Skip to content

feat(publish): default metadata from /formpopulate#2292

Merged
fpotier merged 2 commits intomasterfrom
feat/dynamic-defaults
Apr 16, 2026
Merged

feat(publish): default metadata from /formpopulate#2292
fpotier merged 2 commits intomasterfrom
feat/dynamic-defaults

Conversation

@fpotier
Copy link
Copy Markdown
Member

@fpotier fpotier commented Mar 27, 2026

Description

Needs SciCatProject/backend#2569 and the new SDK

Changes:

Please provide a list of the changes implemented by this PR

  • Uses the /formpopulate endpoint to initialize the publish form with default metadata

Tests included

  • Included for each change/fix?
  • Passing? (Merge will not be approved unless this is checked)

Documentation

  • swagger documentation updated [required]
  • official documentation updated [nice-to-have]

official documentation info

If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included

Backend version

  • Does it require a specific version of the backend
  • which version of the backend is required: 5.x

@fpotier fpotier requested a review from a team as a code owner March 27, 2026 14:18
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The AJV setup (instance creation, addFormats/addKeywords) is duplicated in both publish and publisheddata-edit components; consider extracting this into a shared helper/service so configuration stays consistent and easier to change.
  • PublishComponent.deleteDynamicDefaults is a static helper but is used from other components and mutates the schema in place; it may be clearer to move this into a shared utility (e.g. a schema helper) and either return a new schema or document that it mutates its argument.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The AJV setup (instance creation, addFormats/addKeywords) is duplicated in both publish and publisheddata-edit components; consider extracting this into a shared helper/service so configuration stays consistent and easier to change.
- PublishComponent.deleteDynamicDefaults is a static helper but is used from other components and mutates the schema in place; it may be clearer to move this into a shared utility (e.g. a schema helper) and either return a new schema or document that it mutates its argument.

## Individual Comments

### Comment 1
<location path="src/app/publisheddata/publisheddata-edit/publisheddata-edit.component.ts" line_range="158-159" />
<code_context>
-            this.schema.required.indexOf("publicationYear"),
-            1,
-          );
+          this.schema = cloneDeep(publishedDataConfig.metadataSchema);
+          PublishComponent.deleteDynamicDefaults(this.schema);
           this.uiSchema = publishedDataConfig.uiSchema;
-          this.metadata = cloneDeep(publishedDataConfig.defaultValues) ?? {};
</code_context>
<issue_to_address>
**suggestion:** Avoid coupling `PublisheddataEditComponent` to `PublishComponent` for schema cleanup logic.

Calling `PublishComponent.deleteDynamicDefaults` from here introduces an unnecessary dependency between two components and may lead to circular references later. Consider extracting `deleteDynamicDefaults` into a shared utility (e.g., a standalone function or service) that both components can use instead.
</issue_to_address>

### Comment 2
<location path="src/app/datasets/publish/publish.component.ts" line_range="123" />
<code_context>
     this._hasUnsavedChanges = true;
   }

+  static deleteDynamicDefaults(data: any): void {
+    if (Array.isArray(data)) {
+      data.forEach((entry) => PublishComponent.deleteDynamicDefaults(entry));
</code_context>
<issue_to_address>
**suggestion:** Tighten typing and clarify intent of `deleteDynamicDefaults` to reduce future misuse.

The helper takes `any` and recursively mutates its argument. Since it’s used for JSON Schema cleaning, consider narrowing the parameter type (e.g. `Record<string, unknown> | unknown[] | null`) and making the in-place mutation explicit via the name/signature, or instead returning a cleaned clone. This reduces accidental use on non-schema data and clarifies caller expectations.

```suggestion
  /**
   * Recursively removes `dynamicDefaults` keys from a JSON Schema-like structure in-place.
   * Accepts plain objects, arrays, or null/undefined; other values are ignored.
   */
  static deleteDynamicDefaults(
    data: Record<string, unknown> | unknown[] | null | undefined,
  ): void {
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/app/publisheddata/publisheddata-edit/publisheddata-edit.component.ts Outdated
Comment thread src/app/datasets/publish/publish.component.ts Outdated
Comment thread src/app/datasets/publish/publish.component.ts Outdated
Comment thread src/app/datasets/publish/publish.component.ts Outdated
Comment thread src/app/publisheddata/publisheddata-edit/publisheddata-edit.component.ts Outdated
Comment thread src/app/publisheddata/publisheddata-edit/publisheddata-edit.component.html Outdated
@fpotier fpotier requested a review from minottic March 30, 2026 11:54
@minottic
Copy link
Copy Markdown
Member

LGTM, I think it would make sense to split this into 2 PRs. One fixing the sdk, the second with the ajv changes

@Junjiequan Junjiequan requested a review from nitrosx March 30, 2026 14:43
@fpotier fpotier force-pushed the feat/dynamic-defaults branch 2 times, most recently from 80c28dd to fc7aaf3 Compare April 15, 2026 12:04
@fpotier fpotier force-pushed the feat/dynamic-defaults branch from fc7aaf3 to cd94a37 Compare April 15, 2026 12:07
@fpotier fpotier merged commit 2d6a184 into master Apr 16, 2026
8 checks passed
@fpotier fpotier deleted the feat/dynamic-defaults branch April 16, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants