From 605581f07f101ca36421694916ceb8360391cabf Mon Sep 17 00:00:00 2001 From: Jason Pan Date: Mon, 18 Aug 2025 18:20:27 -0400 Subject: [PATCH 1/2] feat(metadata-view): default sortBy --- src/constants.js | 13 ++++++++++++ .../content-explorer/ContentExplorer.tsx | 4 +++- .../tests/MetadataView-visual.stories.tsx | 21 ++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/constants.js b/src/constants.js index 2432e572be..4e1c727d43 100644 --- a/src/constants.js +++ b/src/constants.js @@ -168,6 +168,19 @@ export const FIELD_CLASSIFICATION: 'classification' = 'classification'; export const FIELD_ENTERPRISE: 'enterprise' = 'enterprise'; export const FIELD_HOSTNAME: 'hostname' = 'hostname'; +/* ----------------------- Item-Prefixed Fields for MD Query API --------------------------- */ +const ITEM_PREFIX = 'item.'; +export const FIELD_ITEM_TYPE = `${ITEM_PREFIX}${FIELD_TYPE}`; +export const FIELD_ITEM_NAME = `${ITEM_PREFIX}${FIELD_NAME}`; +export const FIELD_ITEM_DESCRIPTION = `${ITEM_PREFIX}${FIELD_DESCRIPTION}`; +export const FIELD_ITEM_EXTENSION = `${ITEM_PREFIX}${FIELD_EXTENSION}`; +export const FIELD_ITEM_OWNED_BY = `${ITEM_PREFIX}${FIELD_OWNED_BY}`; +export const FIELD_ITEM_CREATED_AT = `${ITEM_PREFIX}${FIELD_CREATED_AT}`; +export const FIELD_ITEM_MODIFIED_AT = `${ITEM_PREFIX}${FIELD_MODIFIED_AT}`; +export const FIELD_ITEM_CONTENT_CREATED_AT = `${ITEM_PREFIX}${FIELD_CONTENT_CREATED_AT}`; +export const FIELD_ITEM_CONTENT_MODIFIED_AT = `${ITEM_PREFIX}${FIELD_CONTENT_MODIFIED_AT}`; +export const FIELD_ITEM_QUICK_SEARCH_CONTENT = `${ITEM_PREFIX}quick_search_content`; + /* ----------------------- Permissions --------------------------- */ export const PERMISSION_CAN_COMMENT = 'can_comment'; export const PERMISSION_CAN_CREATE_ANNOTATIONS = 'can_create_annotations'; diff --git a/src/elements/content-explorer/ContentExplorer.tsx b/src/elements/content-explorer/ContentExplorer.tsx index fecd0588bc..b064f7c6d1 100644 --- a/src/elements/content-explorer/ContentExplorer.tsx +++ b/src/elements/content-explorer/ContentExplorer.tsx @@ -49,6 +49,7 @@ import { DEFAULT_HOSTNAME_STATIC, DEFAULT_SEARCH_DEBOUNCE, SORT_ASC, + FIELD_ITEM_NAME, FIELD_NAME, FIELD_PERMISSIONS_CAN_SHARE, FIELD_SHARED_LINK, @@ -456,7 +457,8 @@ class ContentExplorer extends Component { metadataQueryClone.order_by = [ { - field_key: sortBy, + // Default to the prefixed name field for metadata view v2 only, while not touching the default sortBy for other views. + field_key: sortBy === FIELD_NAME ? FIELD_ITEM_NAME : sortBy, direction: sortDirection, }, ]; diff --git a/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx b/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx index 1758b55f3b..6c373384aa 100644 --- a/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx +++ b/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx @@ -21,7 +21,7 @@ const metadataFieldNamePrefix = `metadata.${metadataScopeAndKey}`; const metadataQuery = { from: metadataScopeAndKey, ancestor_folder_id: '0', - sort_by: [ + order_by: [ { field_key: `${metadataFieldNamePrefix}.${mockSchema.fields[0].key}`, // Default to sorting by the first field in the schema direction: 'asc', @@ -49,7 +49,7 @@ const columns = [ textValue: 'Name', id: 'name', type: 'string', - allowSorting: true, + allowsSorting: true, minWidth: 150, maxWidth: 150, }, @@ -57,7 +57,7 @@ const columns = [ textValue: field.displayName, id: `${metadataFieldNamePrefix}.${field.key}`, type: field.type, - allowSorting: true, + allowsSorting: true, minWidth: 150, maxWidth: 150, })), @@ -94,6 +94,21 @@ export const metadataViewV2: Story = { args: metadataViewV2ElementProps, }; +// @TODO Assert that rows are actually sorted in a different order, once handleSortChange is implemented +export const metadataViewV2SortsFromHeader: Story = { + args: metadataViewV2ElementProps, + play: async ({ canvas }) => { + await waitFor(() => { + expect(canvas.getByRole('row', { name: /Industry/i })).toBeInTheDocument(); + }); + + const firstRow = canvas.getByRole('row', { name: /Industry/i }); + const industryHeader = within(firstRow).getByRole('columnheader', { name: 'Industry' }); + userEvent.click(industryHeader); + }, +}; + +// @TODO Fix shared feature to never allow multi and single select to sort export const metadataViewV2WithCustomActions: Story = { args: { ...metadataViewV2ElementProps, From 6e9c86aacac9d0b08c2b9265673426ceffb61b1b Mon Sep 17 00:00:00 2001 From: Jason Pan Date: Wed, 20 Aug 2025 10:53:08 -0400 Subject: [PATCH 2/2] feat(metadata-view): default sortBy change for mdv2 only --- .../content-explorer/ContentExplorer.tsx | 21 ++++++++++++------- .../tests/MetadataView-visual.stories.tsx | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/elements/content-explorer/ContentExplorer.tsx b/src/elements/content-explorer/ContentExplorer.tsx index b064f7c6d1..c883922719 100644 --- a/src/elements/content-explorer/ContentExplorer.tsx +++ b/src/elements/content-explorer/ContentExplorer.tsx @@ -455,13 +455,6 @@ class ContentExplorer extends Component { metadataQueryClone.limit = DEFAULT_PAGE_SIZE; } - metadataQueryClone.order_by = [ - { - // Default to the prefixed name field for metadata view v2 only, while not touching the default sortBy for other views. - field_key: sortBy === FIELD_NAME ? FIELD_ITEM_NAME : sortBy, - direction: sortDirection, - }, - ]; // Reset search state, the view and show busy indicator this.setState({ searchQuery: '', @@ -470,8 +463,22 @@ class ContentExplorer extends Component { }); if (isFeatureEnabled(features, 'contentExplorer.metadataViewV2')) { + metadataQueryClone.order_by = [ + { + // Default to the prefixed name field for metadata view v2 only, while not touching the default sortBy for other views. + field_key: sortBy === FIELD_NAME ? FIELD_ITEM_NAME : sortBy, + direction: sortDirection, + }, + ]; + this.metadataQueryAPIHelper = new MetadataQueryAPIHelperV2(this.api); } else { + metadataQueryClone.order_by = [ + { + field_key: sortBy, + direction: sortDirection, + }, + ]; this.metadataQueryAPIHelper = new MetadataQueryAPIHelper(this.api); } diff --git a/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx b/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx index 6c373384aa..03c7609675 100644 --- a/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx +++ b/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx @@ -108,7 +108,6 @@ export const metadataViewV2SortsFromHeader: Story = { }, }; -// @TODO Fix shared feature to never allow multi and single select to sort export const metadataViewV2WithCustomActions: Story = { args: { ...metadataViewV2ElementProps,