Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Extend getMetadata in Metadata API #3611

Merged
merged 14 commits into from
Aug 23, 2024

Conversation

kajarosz
Copy link
Contributor

@kajarosz kajarosz commented Aug 14, 2024

This change extends getMetadata method in Metadata API in order to meet Metadata Sidebar Redesign needs as it will require less complex typing.

Currently MetadataSidebar fetches editors which are objects containing:

  • template object - it holds data on which template was used to create metadata instance for current file and current user and most importantly it holds fields array. This array consists of field objects which hold details on field displayName, field type etc. but do not hold field value for current file and current user - this is job for instance object.
  • instance object - as explained above is simple object with instance details like id and key-value pairs which reflect template fields keys.
    For now in order to get field details AND value for particular metadata instance, there's a lot of mapping needed which makes components implementation less straight forward. Additionally, more types are needed to handle that.

On the top of that, most of the above explanation is not valid in custom metadata case as it does not use templates. This makes whole logic even more complex.

We want to improve this in new Metadata Sidebar to simplify logic inside components and reduce number of types. In this change we are unifying data provided for metadata instances from template and custom metadata, so that components do not have to introduce any additional logic, checks etc. In redesigned Metadata Sidebar we'll introduce the same component for viewing both metadata instances from template and custom metadata instead of dedicated component for each type of instance.

@CLAassistant
Copy link

CLAassistant commented Aug 14, 2024

CLA assistant check
All committers have signed the CLA.

@kajarosz kajarosz changed the title Extend getmetadata feat: Extend getMetadata in Metadata API Aug 14, 2024
@kajarosz kajarosz marked this pull request as ready for review August 14, 2024 14:48
@kajarosz kajarosz requested review from a team as code owners August 14, 2024 14:48
@greg-in-a-box greg-in-a-box changed the title feat: Extend getMetadata in Metadata API feat(api): Extend getMetadata in Metadata API Aug 14, 2024
src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
src/common/types/metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
Comment on lines 373 to 379
description: field.description,
displayName: field.displayName,
hidden: field.hidden,
id: field.id,
key: field.key,
options: field.options,
type: field.type,
value: instance[field.key],
Copy link
Contributor

@wpiesiak wpiesiak Aug 21, 2024

Choose a reason for hiding this comment

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

what about:

Suggested change
description: field.description,
displayName: field.displayName,
hidden: field.hidden,
id: field.id,
key: field.key,
options: field.options,
type: field.type,
value: instance[field.key],
...field,
value: instance[field.key],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MetadataTemplateField has isHidden field which is not expected by MetadataTemplateInstanceField, but it's the only difference which does not collide that much. I implemented your suggestion.

Comment on lines 398 to 402
displayName: template.displayName,
hidden: template.hidden,
id: template.id,
metadataFields,
scope: template.scope,
templateKey: template.templateKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
displayName: template.displayName,
hidden: template.hidden,
id: template.id,
metadataFields,
scope: template.scope,
templateKey: template.templateKey,
...template,
fields: metadataFields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't implement this as suggested because template: MetadataTemplate has isHidden field that we do not want to have in MetadataTemplateInstance. Moreover, template: MetadataTemplate already has fields defined which has incompatible type - it's type is Array<MetadataTemplateField> while MetadataTemplateInstance is expecting MetadataTemplateInstanceField[]. The difference in these two types is that the first one has isHidden and does not have value in comparison to second one.

All in all, I'd rather stay with my implementation.

bfoxx1906
bfoxx1906 previously approved these changes Aug 21, 2024
Copy link

@bfoxx1906 bfoxx1906 left a comment

Choose a reason for hiding this comment

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

lgtm

src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Outdated Show resolved Hide resolved
src/api/Metadata.js Show resolved Hide resolved
src/common/types/metadata.js Outdated Show resolved Hide resolved
@mergify mergify bot merged commit 765f592 into box:master Aug 23, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants