Skip to content

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

Open
fpotier wants to merge 6 commits intomasterfrom
feat/dynamic-defaults
Open

feat(publish): default metadata from /formpopulate#2292
fpotier wants to merge 6 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
  • Allow user to save during edit even if the metadata is not valid, this could already easily be bypassed by closing the metadata panel
  • reverts feat(publish): allow to configure default metadata #2180 as it can now be handled by ajv
  • first commit includes changes required with the new sdk

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:

Summary by Sourcery

Initialize publish and edit metadata forms from the backend form population endpoint while upgrading to the new SDK types and query API.

New Features:

  • Populate publish forms with default metadata returned from the form populate backend endpoint.

Bug Fixes:

  • Allow saving publish and edit forms even when metadata validation fails, avoiding unintended blocking by the metadata panel.

Enhancements:

  • Delegate JSON schema validation and defaults handling to AJV with shared configuration between publish and edit components.
  • Strip dynamic default definitions from loaded metadata schemas before rendering JSON forms.
  • Switch published data and dataset/sample-related calls to the new v4 SDK services, DTO types, and unstringified filter/query parameters for list endpoints.

Tests:

  • Update unit tests and mocks to use the new published data service, sample DTOs, and form population method.

@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.

@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
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