Skip to content

Commit

Permalink
feat(releases): sorting release overview table (#7159)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jordanl17 authored and juice49 committed Sep 3, 2024
1 parent 28b9d8b commit 5735897
Show file tree
Hide file tree
Showing 27 changed files with 914 additions and 871 deletions.
Original file line number Diff line number Diff line change
@@ -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<TableContextValue | null>(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
}
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ export * from './context/WorkspaceContext'
export * from './context/WorkspacesContext'
export * from './context/ZIndexContext'
export * from './core/releases/BundlesMetadataContext'
export * from './core/releases/ReleasesTableContext'
14 changes: 11 additions & 3 deletions packages/sanity/src/core/bundles/components/BundleBadge.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -10,7 +10,15 @@ import {type BundleDocument} from '../../store/bundles/types'
* @internal
*/
export function BundleBadge(
props: Partial<BundleDocument> & {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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const BundleMenuButton = ({bundle, documentCount}: Props) => {
padding={bundleHasDocuments}
footer={{
confirmButton: {
text: 'Delete',
tone: 'default',
onClick: handleOnDeleteBundle,
loading: discardStatus === 'discarding',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5735897

Please sign in to comment.