Skip to content

Commit

Permalink
fix(core): update corel contexts to match new lint rules (#7332)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin authored and bjoerge committed Aug 20, 2024
1 parent 48468fe commit b1ed584
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 62 deletions.
12 changes: 12 additions & 0 deletions packages/sanity/src/_singletons/context/BundlesMetadataContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {createContext} from 'sanity/_createContext'

import type {BundlesMetadataContextValue} from '../../core/releases/contexts/BundlesMetadataProvider'

/**
* @internal
* @hidden
*/
export const BundlesMetadataContext = createContext<BundlesMetadataContextValue | null>(
'sanity/_singletons/context/bundles-metadata',
null,
)
11 changes: 11 additions & 0 deletions packages/sanity/src/_singletons/context/ReleasesTableContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {createContext} from 'sanity/_createContext'

import type {TableContextValue} from '../../core/releases/components/Table/TableProvider'

/**
* @internal
*/
export const TableContext = createContext<TableContextValue | null>(
'sanity/_singletons/context/releases-table',
null,
)

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './context/ActiveWorkspaceMatcherContext'
export * from './context/AddonDatasetContext'
export * from './context/BundlesMetadataContext'
export * from './context/CalendarContext'
export * from './context/ChangeIndicatorTrackerContexts'
export * from './context/ColorSchemeSetValueContext'
Expand Down Expand Up @@ -43,6 +44,7 @@ export * from './context/PresenceTrackerContexts'
export * from './context/PreviewCardContext'
export * from './context/ReferenceInputOptionsContext'
export * from './context/ReferenceItemRefContext'
export * from './context/ReleasesTableContext'
export * from './context/ResourceCacheContext'
export * from './context/ReviewChangesContext'
export * from './context/RouterContext'
Expand All @@ -66,5 +68,3 @@ export * from './context/VirtualizerScrollInstanceContext'
export * from './context/WorkspaceContext'
export * from './context/WorkspacesContext'
export * from './context/ZIndexContext'
export * from './core/releases/BundlesMetadataContext'
export * from './core/releases/ReleasesTableContext'
3 changes: 1 addition & 2 deletions packages/sanity/src/core/releases/components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {Box, Card, Flex, Stack, Text} from '@sanity/ui'
import {get} from 'lodash'
import {Fragment, useMemo} from 'react'
import {useTableContext} from 'sanity/_singletons'
import {styled} from 'styled-components'

import {TooltipDelayGroupProvider} from '../../../../ui-components'
import {LoadingBlock} from '../../../components'
import {TableHeader} from './TableHeader'
import {TableProvider, type TableSort} from './TableProvider'
import {TableProvider, type TableSort, useTableContext} from './TableProvider'
import {type Column} from './types'

type RowDatum<TableData, AdditionalRowTableData> = AdditionalRowTableData extends undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ArrowDownIcon, ArrowUpIcon, SearchIcon} from '@sanity/icons'
import {Button, type ButtonProps, Card, Flex, Stack, TextInput} from '@sanity/ui'
import {useTableContext} from 'sanity/_singletons'

import {useTableContext} from './TableProvider'
import {type HeaderProps, type TableHeaderProps} from './types'

const SortHeaderButton = ({header, text}: ButtonProps & HeaderProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import {type ComponentType, type PropsWithChildren, useCallback, useState} from 'react'
import {type ComponentType, type PropsWithChildren, useCallback, useContext, useState} from 'react'
import {TableContext} from 'sanity/_singletons'

export interface TableSort {
column: string
direction: 'asc' | 'desc'
}

/**
* @internal
*/
export interface TableContextValue {
searchTerm: string | null
setSearchTerm: (searchTerm: string) => void
sort: TableSort | null
setSortColumn: (column: string) => void
}

/**
* @internal
*/
Expand All @@ -30,3 +40,14 @@ export const TableProvider: ComponentType<PropsWithChildren & {defaultSort?: Tab

return <TableContext.Provider value={contextValue}>{children}</TableContext.Provider>
}

/**
* @internal
*/
export const useTableContext = (): TableContextValue => {
const context = useContext(TableContext)
if (!context) {
throw new Error('useTableContext must be used within a TableProvider')
}
return context
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import {BundlesMetadataContext} from 'sanity/_singletons'
import {type MetadataWrapper} from '../../store/bundles/createBundlesMetadataAggregator'
import {type BundlesMetadata} from '../tool/useBundlesMetadata'

/**
* @internal
*/
export interface BundlesMetadataContextValue {
state: MetadataWrapper
addBundleSlugsToListener: (slugs: string[]) => void
removeBundleSlugsFromListener: (slugs: string[]) => void
}

const DEFAULT_METADATA_STATE: MetadataWrapper = {
data: null,
error: null,
Expand Down Expand Up @@ -91,7 +100,7 @@ export const BundlesMetadataProvider = ({children}: {children: React.ReactNode})
return <BundlesMetadataProviderInner>{children}</BundlesMetadataProviderInner>
}

export const useBundlesMetadataProvider = () => {
export const useBundlesMetadataProvider = (): BundlesMetadataContextValue => {
const contextValue = useContext(BundlesMetadataContext)

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {DocumentsIcon} from '@sanity/icons'
import {type SanityDocument} from '@sanity/types'
import {AvatarStack, Box, Flex, Heading, Stack, Text, useToast} from '@sanity/ui'
import {useCallback, useEffect, useMemo, useState} from 'react'
import {useTableContext} from 'sanity/_singletons'

import {
BundleIconEditorPicker,
Expand All @@ -14,6 +13,7 @@ import {type BundleDocument} from '../../../store/bundles/types'
import {useAddonDataset} from '../../../studio/addonDataset/useAddonDataset'
import {Chip} from '../../components/Chip'
import {Table, type TableProps} from '../../components/Table/Table'
import {useTableContext} from '../../components/Table/TableProvider'
import {type DocumentValidationStatus} from './bundleDocumentsValidation'
import {DocumentActions} from './documentTable/DocumentActions'
import {getDocumentTableColumnDefs} from './documentTable/DocumentTableColumnDefs'
Expand Down

0 comments on commit b1ed584

Please sign in to comment.