feat(publish): default metadata from /formpopulate#2292
Open
feat(publish): default metadata from /formpopulate#2292
Conversation
Contributor
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
src/app/publisheddata/publisheddata-edit/publisheddata-edit.component.ts
Outdated
Show resolved
Hide resolved
minottic
reviewed
Mar 27, 2026
src/app/publisheddata/publisheddata-edit/publisheddata-edit.component.ts
Outdated
Show resolved
Hide resolved
src/app/publisheddata/publisheddata-edit/publisheddata-edit.component.html
Show resolved
Hide resolved
Member
|
LGTM, I think it would make sense to split this into 2 PRs. One fixing the sdk, the second with the ajv changes |
nitrosx
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Needs SciCatProject/backend#2569 and the new SDK
Changes:
Please provide a list of the changes implemented by this PR
/formpopulateendpoint to initialize the publish form with default metadataTests included
Documentation
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
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:
Bug Fixes:
Enhancements:
Tests: