From d5016793dbd78068db981a2934baa7afe44fcb54 Mon Sep 17 00:00:00 2001 From: Jordan Lawrence Date: Thu, 18 Jul 2024 14:42:01 +0100 Subject: [PATCH] feat(releases): sorting release overview table (#7159) * feat(releases): sorting releases table with new Table component * fix(releases): fixing sanity require for DocumentPerspectiveMenu.test * refactor(releases): clarifying generic names; minor tidies to naming * refactor(releases): default table data type of unknown; rename of some variables; improved types for TableProvider * refactor(releases): default table data type of unknown; rename of some variables; improved types for TableProvider --- .../core/releases/ReleasesTableContext.ts | 34 +++ packages/sanity/src/_singletons/index.ts | 1 + .../core/bundles/components/BundleBadge.tsx | 14 +- .../BundleMenuButton/BundleMenuButton.tsx | 1 + .../__tests__/BundleMenuButton.test.tsx | 4 +- .../ReleasesTable/ReleaseHeader.tsx | 73 ------- .../components/ReleasesTable/ReleaseRow.tsx | 94 --------- .../ReleasesTable/ReleasesTable.tsx | 65 ------ .../__tests__/ReleasesTable.test.tsx | 155 -------------- .../core/releases/components/Table/Table.tsx | 197 ++++++++++++++++++ .../releases/components/Table/TableHeader.tsx | 77 +++++++ .../components/Table/TableProvider.tsx | 24 +++ .../core/releases/components/Table/types.ts | 27 +++ .../contexts/BundlesMetadataProvider.tsx | 7 +- .../src/core/releases/tool/ReleasesTool.tsx | 2 +- .../releases/tool/detail/ReleaseDetail.tsx | 31 ++- ...ReleaseOverview.tsx => ReleaseSummary.tsx} | 90 ++++++-- .../__tests__/ReleaseReview.test.tsx | 21 +- .../detail/documentTable/DocumentActions.tsx | 23 +- .../detail/documentTable/DocumentHeader.tsx | 124 ----------- .../tool/detail/documentTable/DocumentRow.tsx | 156 -------------- .../detail/documentTable/DocumentTable.tsx | 76 ------- .../documentTable/DocumentTableColumnDefs.tsx | 130 ++++++++++++ .../tool/detail/documentTable/index.ts | 1 - .../tool/{ => overview}/ReleasesOverview.tsx | 120 ++++++----- .../overview/ReleasesOverviewColumnDefs.tsx | 125 +++++++++++ .../__tests__/ReleasesOverview.test.tsx | 113 ++++++++-- 27 files changed, 914 insertions(+), 871 deletions(-) create mode 100644 packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts delete mode 100644 packages/sanity/src/core/releases/components/ReleasesTable/ReleaseHeader.tsx delete mode 100644 packages/sanity/src/core/releases/components/ReleasesTable/ReleaseRow.tsx delete mode 100644 packages/sanity/src/core/releases/components/ReleasesTable/ReleasesTable.tsx delete mode 100644 packages/sanity/src/core/releases/components/ReleasesTable/__tests__/ReleasesTable.test.tsx create mode 100644 packages/sanity/src/core/releases/components/Table/Table.tsx create mode 100644 packages/sanity/src/core/releases/components/Table/TableHeader.tsx create mode 100644 packages/sanity/src/core/releases/components/Table/TableProvider.tsx create mode 100644 packages/sanity/src/core/releases/components/Table/types.ts rename packages/sanity/src/core/releases/tool/detail/{ReleaseOverview.tsx => ReleaseSummary.tsx} (56%) rename packages/sanity/src/core/releases/tool/{ => detail}/__tests__/ReleaseReview.test.tsx (87%) delete mode 100644 packages/sanity/src/core/releases/tool/detail/documentTable/DocumentHeader.tsx delete mode 100644 packages/sanity/src/core/releases/tool/detail/documentTable/DocumentRow.tsx delete mode 100644 packages/sanity/src/core/releases/tool/detail/documentTable/DocumentTable.tsx create mode 100644 packages/sanity/src/core/releases/tool/detail/documentTable/DocumentTableColumnDefs.tsx delete mode 100644 packages/sanity/src/core/releases/tool/detail/documentTable/index.ts rename packages/sanity/src/core/releases/tool/{ => overview}/ReleasesOverview.tsx (58%) create mode 100644 packages/sanity/src/core/releases/tool/overview/ReleasesOverviewColumnDefs.tsx rename packages/sanity/src/core/releases/tool/{ => overview}/__tests__/ReleasesOverview.test.tsx (53%) diff --git a/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts b/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts new file mode 100644 index 000000000000..919100555af1 --- /dev/null +++ b/packages/sanity/src/_singletons/core/releases/ReleasesTableContext.ts @@ -0,0 +1,34 @@ +import {createContext, useContext} from 'react' + +/** + * @internal + */ +export interface TableContextValue { + searchTerm: string | null + setSearchTerm: (searchTerm: string) => void + sort: {column: string; direction: 'asc' | 'desc'} | null + setSearchColumn: (column: string) => void +} + +const DEFAULT_TABLE_CONTEXT: TableContextValue = { + searchTerm: null, + setSearchTerm: () => null, + sort: null, + setSearchColumn: () => null, +} + +/** + * @internal + */ +export const TableContext = createContext(null) + +/** + * @internal + */ +export const useTableContext = (): TableContextValue => { + const context = useContext(TableContext) + if (!context) { + throw new Error('useTableContext must be used within a TableProvider') + } + return context || DEFAULT_TABLE_CONTEXT +} diff --git a/packages/sanity/src/_singletons/index.ts b/packages/sanity/src/_singletons/index.ts index 95443cbe1f0d..550d89eb50e2 100644 --- a/packages/sanity/src/_singletons/index.ts +++ b/packages/sanity/src/_singletons/index.ts @@ -28,6 +28,7 @@ export * from './core/i18n/LocaleContext' export * from './core/presence/FormFieldPresenceContext' export * from './core/presence/overlay/PresenceTrackerContexts' export * from './core/releases/BundlesMetadataContext' +export * from './core/releases/ReleasesTableContext' export * from './core/schedulePublishing/DocumentActionPropsContext' export * from './core/schedulePublishing/tool/ScheduledPublishingEnabledContext' export * from './core/schedulePublishing/tool/SchedulePublishingUpsellContext' diff --git a/packages/sanity/src/core/bundles/components/BundleBadge.tsx b/packages/sanity/src/core/bundles/components/BundleBadge.tsx index d2926cc58dd1..bcb6a3f763c2 100644 --- a/packages/sanity/src/core/bundles/components/BundleBadge.tsx +++ b/packages/sanity/src/core/bundles/components/BundleBadge.tsx @@ -1,5 +1,5 @@ -import {hues} from '@sanity/color' -import {ChevronDownIcon, Icon} from '@sanity/icons' +import {type ColorHueKey, hues} from '@sanity/color' +import {ChevronDownIcon, Icon, type IconSymbol} from '@sanity/icons' // eslint-disable-next-line camelcase import {Box, Flex, rgba, Text, useTheme_v2} from '@sanity/ui' import {type CSSProperties} from 'react' @@ -10,7 +10,15 @@ import {type BundleDocument} from '../../store/bundles/types' * @internal */ export function BundleBadge( - props: Partial & {openButton?: boolean; padding?: number; title?: string}, + props: Partial< + BundleDocument & { + icon: IconSymbol + hue: ColorHueKey + openButton: boolean + padding: number + title: string + } + >, ): JSX.Element { const {hue = 'gray', icon, openButton, padding = 3, title} = props const {color} = useTheme_v2() diff --git a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx index 4f6bd007e3ad..6306151daf43 100644 --- a/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx +++ b/packages/sanity/src/core/releases/components/BundleMenuButton/BundleMenuButton.tsx @@ -98,6 +98,7 @@ export const BundleMenuButton = ({bundle, documentCount}: Props) => { padding={bundleHasDocuments} footer={{ confirmButton: { + text: 'Delete', tone: 'default', onClick: handleOnDeleteBundle, loading: discardStatus === 'discarding', diff --git a/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx b/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx index 79241eab7a2f..55a58497a121 100644 --- a/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx +++ b/packages/sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.test.tsx @@ -116,7 +116,7 @@ describe('BundleMenuButton', () => { screen.getByText('This will also delete 2 document versions', {exact: false}) await act(() => { - fireEvent.click(screen.getByText('Confirm')) + fireEvent.click(screen.getByText('Delete')) }) expect(useBundleOperations().deleteBundle).toHaveBeenCalledWith(activeBundle) @@ -149,7 +149,7 @@ describe('BundleMenuButton', () => { expect(screen.queryByTestId('confirm-delete-body')).toBeNull() await act(() => { - fireEvent.click(screen.getByText('Confirm')) + fireEvent.click(screen.getByText('Delete')) }) expect(useBundleOperations().deleteBundle).toHaveBeenCalledWith(activeEmptyBundle) diff --git a/packages/sanity/src/core/releases/components/ReleasesTable/ReleaseHeader.tsx b/packages/sanity/src/core/releases/components/ReleasesTable/ReleaseHeader.tsx deleted file mode 100644 index f2189840dee0..000000000000 --- a/packages/sanity/src/core/releases/components/ReleasesTable/ReleaseHeader.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import {SearchIcon} from '@sanity/icons' -import {Box, Button, Card, Flex, Stack, Text, TextInput} from '@sanity/ui' - -/** - * @internal - */ -export interface ReleaseHeaderProps { - searchDisabled?: boolean - searchTerm?: string - setSearchTerm: (value?: string) => void -} - -export function ReleaseHeader({searchDisabled, searchTerm, setSearchTerm}: ReleaseHeaderProps) { - return ( - - - {/* Title */} - - setSearchTerm(event.currentTarget.value)} - onClear={() => setSearchTerm('')} - clearButton={!!searchTerm} - /> - - {/* Number of documents */} - - - - Documents - - - - {/* Created */} - -