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(metadata-views): Support adding removing values #2284

Merged
merged 3 commits into from
Aug 11, 2020

Conversation

manishPh
Copy link
Contributor

@manishPh manishPh commented Aug 10, 2020

This PR enables metadata views to add/remove metadata values in addition to replace (PUT) them.


default:
return value;
if (type === FIELD_TYPE_INTEGER && !isNil(value)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using isNil() to separate null/undefined with values like 0

@@ -258,17 +259,18 @@ class MetadataBasedItemList extends React.Component<Props, State> {
return cellData;
}
const { type, value, options = [] } = field;
const shouldShowEditIcon = isCellEditable && isString(type);
Copy link
Contributor Author

@manishPh manishPh Aug 10, 2020

Choose a reason for hiding this comment

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

Making sure data type of metadata field is valid, so that we can show edit icon and corresponding <MetadataField /> for that type.

<IconWithTooltip
type={EDIT_ICON_TYPE}
tooltipText={<FormattedMessage {...messages.editLabel} />}
onClick={() => this.handleEditIconClick(columnIndex, rowIndex, value)}
/>
)}
{isCellBeingEdited && valueBeingEdited && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Show edit icon even for the case where value is not present to start with; i.e. for JSON patch add operation

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a snapshot test for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sahiga there is but its difficult to test react-virtualized <AutoSizer /> component with enzyme because of issues like this. The other alternative I found out was to export one more component from the same file which is wrapped in <VirtualScroll /> as mentioned here so that we can test the functionality but I guess its too complicated for a snapshot test. I have instead relied on unit testing other functionality from the component.

ancestor_folder_id: 0,
};

This function will return ['field_1', 'field_2', 'field_3']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

['field_1', 'field_2', 'field_3'] will become the columns in the grid view.

});
const queryFields = this.getMetadataQueryFields();

const fields = queryFields.map((queryField: string) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Iterate over the fields mentioned in the query instead of fields returned in the response. The metadata_queries API will return only the existing fields.

src/features/metadata-based-view/MetadataBasedItemList.js Outdated Show resolved Hide resolved
src/features/metadata-based-view/MetadataQueryAPIHelper.js Outdated Show resolved Hide resolved
@@ -169,6 +169,8 @@ describe('features/metadata-based-view/MetadataBasedItemList', () => {
${FIELD_TYPE_FLOAT} | ${'123.456'} | ${123.456}
${FIELD_TYPE_MULTISELECT} | ${['Yes', 'No']} | ${['Yes', 'No']}
${FIELD_TYPE_STRING} | ${'str'} | ${'str'}
${FIELD_TYPE_STRING} | ${undefined} | ${undefined}
${null} | ${'some value'} | ${'some value'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also test the cases in which the type is FIELD_TYPE_INTEGER or FIELD_TYPE_FLOAT, but the value is null or undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The additional two cases cover the function behavior where it returns value when either value or type doesn't exist. Checking for more types for the same result may not add additional testing.

<IconWithTooltip
type={EDIT_ICON_TYPE}
tooltipText={<FormattedMessage {...messages.editLabel} />}
onClick={() => this.handleEditIconClick(columnIndex, rowIndex, value)}
/>
)}
{isCellBeingEdited && valueBeingEdited && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a snapshot test for this change?

src/features/metadata-based-view/MetadataQueryAPIHelper.js Outdated Show resolved Hide resolved
@mergify mergify bot merged commit dc856fa into box:master Aug 11, 2020
@manishPh manishPh deleted the jsonOpsMDView branch August 11, 2020 01:04
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.

3 participants