Skip to content

Commit

Permalink
fix(core): update types to match with react-19
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Jan 8, 2025
1 parent 4f85a54 commit 8b8208d
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/sanity/src/core/config/studio/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface NavbarActionBase {
}

interface ActionWithCustomRender extends NavbarActionBase {
render: () => ReactElement
render: () => React.ReactElement
}

interface Action extends NavbarActionBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function ReleaseAvatar({
fontSize?: number
padding?: number
tone: BadgeTone
}): JSX.Element {
}): React.JSX.Element {
return (
<Box flex="none" padding={padding} style={{borderRadius: 3}}>
<Text size={fontSize}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface CreateReleaseDialogProps {
origin?: OriginInfo['origin']
}

export function CreateReleaseDialog(props: CreateReleaseDialogProps): JSX.Element {
export function CreateReleaseDialog(props: CreateReleaseDialogProps): React.JSX.Element {
const {onCancel, onSubmit, origin} = props
const toast = useToast()
const {createRelease} = useReleaseOperations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function DiscardVersionDialog(props: {
onClose: () => void
documentId: string
documentType: string
}): JSX.Element {
}): React.JSX.Element {
const {onClose, documentId, documentType} = props
const {t} = useTranslation(releasesLocaleNamespace)
const {discardChanges} = useDocumentOperation(getPublishedId(documentId), documentType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const RELEASE_TYPES: ReleaseType[] = ['asap', 'scheduled', 'undecided']
export function ReleaseForm(props: {
onChange: (params: EditableReleaseDocument) => void
value: EditableReleaseDocument
}): JSX.Element {
}): React.JSX.Element {
const {onChange, value} = props
const {releaseType} = value.metadata || {}
const publishAt = value.metadata.intendedPublishAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function TitleDescriptionForm({
}: {
release: EditableReleaseDocument
onChange: (changedValue: EditableReleaseDocument) => void
}): JSX.Element {
}): React.JSX.Element {
const descriptionRef = useRef<HTMLTextAreaElement | null>(null)

const [scrollHeight, setScrollHeight] = useState(46)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function UnpublishVersionDialog(props: {
onClose: () => void
documentVersionId: string
documentType: string
}): JSX.Element {
}): React.JSX.Element {
const {onClose, documentVersionId, documentType} = props
const {t} = useTranslation(releasesLocaleNamespace)
const schema = useSchema()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const VersionChip = memo(function VersionChip(props: {
<>
<Tooltip content={tooltipContent} fallbackPlacements={[]} portal placement="bottom">
<Chip
ref={(ref) => (chipRef.current = ref)}
ref={chipRef}
disabled={disabled}
mode="bleed"
onClick={onClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function CopyToNewReleaseDialog(props: {
tone: BadgeTone
title: string
onCreateVersion: (releaseId: string) => void
}): JSX.Element {
}): React.JSX.Element {
const {onClose, documentId, documentType, tone, title, onCreateVersion} = props
const {t} = useTranslation()
const toast = useToast()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const orderedReleaseTypes: ReleaseType[] = ['asap', 'scheduled', 'undecided']

const ASAP_RANGE_OFFSET = 2

export function GlobalPerspectiveMenu(): JSX.Element {
export function GlobalPerspectiveMenu(): React.JSX.Element {
const {loading, data: releases} = useReleases()
const {selectedReleaseId} = usePerspective()
const [createBundleDialogOpen, setCreateBundleDialogOpen] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function ReleaseTypeMenuSection({
releases: ReleaseDocument[]
range: LayerRange
currentGlobalBundleMenuItemRef: React.RefObject<ScrollElement>
}): JSX.Element | null {
}): React.JSX.Element | null {
const {t} = useTranslation()
const {selectedReleaseId} = usePerspective()

Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/releases/navbar/ReleasesNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const AnimatedMotionDiv = ({children, ...props}: PropsWithChildren<any>) => (
</motion.div>
)

export function ReleasesNav(): JSX.Element {
export function ReleasesNav(): React.JSX.Element {
const activeToolName = useRouterState(
useCallback(
(routerState) => (typeof routerState.tool === 'string' ? routerState.tool : undefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
Fragment,
type HTMLProps,
type MutableRefObject,
type ReactNode,
type RefAttributes,
type RefObject,
useMemo,
useRef,
} from 'react'
Expand All @@ -41,7 +41,7 @@ export interface TableProps<TableData, AdditionalRowTableData> {
columnDefs: Column<RowDatum<TableData, AdditionalRowTableData>>[]
searchFilter?: (data: TableData[], searchTerm: string) => TableData[]
data: TableData[]
emptyState: (() => JSX.Element) | string
emptyState: (() => React.JSX.Element) | string
loading?: boolean
/**
* Should be the dot separated path to the unique identifier of the row. e.g. document._id
Expand All @@ -51,9 +51,9 @@ export interface TableProps<TableData, AdditionalRowTableData> {
datum,
}: {
datum: RowDatum<TableData, AdditionalRowTableData> | unknown
}) => ReactNode
}) => React.ReactNode
rowProps?: (datum: TableData) => Partial<TableRowProps>
scrollContainerRef: MutableRefObject<HTMLDivElement | null>
scrollContainerRef: RefObject<HTMLDivElement | null>
hideTableInlinePadding?: boolean
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {type CSSProperties} from 'react'

export interface InjectedTableProps {
as?: React.ElementType | keyof JSX.IntrinsicElements
as?: React.ElementType | keyof React.JSX.IntrinsicElements
id: string
style: {width?: number}
}

export interface Column<TableData = unknown> {
header: (props: HeaderProps) => JSX.Element
header: (props: HeaderProps) => React.JSX.Element
cell: (props: {
datum: TableData
cellProps: InjectedTableProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function AddDocumentSearch({
open: boolean
onClose: () => void
releaseId: string
}): JSX.Element {
}): React.JSX.Element {
const {createVersion} = useReleaseOperations()
const toast = useToast()
const telemetry = useTelemetry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const ReleaseDetail = () => {
}
}, [activeView, releaseInDetail?.publishAt, navigateToSummary])

const scrollContainerRef = useRef(null)
const scrollContainerRef = useRef<HTMLDivElement | null>(null)

const detailContent = useMemo(() => {
if (documentsLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useCallback, useState} from 'react'
import {TitleDescriptionForm} from '../../components/dialog/TitleDescriptionForm'
import {type EditableReleaseDocument, type ReleaseDocument, useReleaseOperations} from '../../index'

export function ReleaseDetailsEditor({release}: {release: ReleaseDocument}): JSX.Element {
export function ReleaseDetailsEditor({release}: {release: ReleaseDocument}): React.JSX.Element {
const {updateRelease} = useReleaseOperations()
const [timer, setTimer] = useState<NodeJS.Timeout | undefined>(undefined)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function ReleaseReview({
documents: DocumentInRelease[]
release: ReleaseDocument
documentsHistory: Record<string, DocumentHistory>
scrollContainerRef: RefObject<HTMLDivElement>
scrollContainerRef: RefObject<HTMLDivElement | null>
}) {
const [searchTerm, setSearchTerm] = useState('')
const [expandedItems, setIsExpandedItems] = useState<Record<string, boolean>>({})
Expand Down
16 changes: 10 additions & 6 deletions packages/sanity/src/core/releases/tool/detail/ReleaseSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type BundleDocumentRow = DocumentWithHistory
export interface ReleaseSummaryProps {
documents: DocumentInRelease[]
documentsHistory: Record<string, DocumentHistory>
scrollContainerRef: RefObject<HTMLDivElement>
scrollContainerRef: RefObject<HTMLDivElement | null>
release: ReleaseDocument
}

Expand All @@ -42,13 +42,17 @@ export function ReleaseSummary(props: ReleaseSummaryProps) {
[documents, documentsHistory],
)

const renderRowActions: React.FC<{datum: BundleDocumentRow | unknown}> = useCallback(
({datum}) => {
const renderRowActions = useCallback(
(rowProps: {datum: BundleDocumentRow | unknown}) => {
if (release.state !== 'active') return null

const document = datum as BundleDocumentRow

return <DocumentActions document={document} releaseTitle={release.metadata.title} />
return (
<DocumentActions
// TODO: Validate this with a proper asserter
document={rowProps.datum as BundleDocumentRow}
releaseTitle={release.metadata.title}
/>
)
},
[release.metadata.title, release.state],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {useReleaseOperations} from '../../store/useReleaseOperations'
import {getReleaseTone} from '../../util/getReleaseTone'
import {getPublishDateFromRelease, isReleaseScheduledOrScheduling} from '../../util/util'

export function ReleaseTypePicker(props: {release: ReleaseDocument}): JSX.Element {
export function ReleaseTypePicker(props: {release: ReleaseDocument}): React.JSX.Element {
const {release} = props

const popoverRef = useRef<HTMLDivElement | null>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function AddToReleaseBanner({
documentId: string
currentRelease: ReleaseDocument
value?: Record<string, unknown>
}): JSX.Element {
}): React.JSX.Element {
const tone = getReleaseTone(currentRelease ?? LATEST)
const {t} = useTranslation(structureLocaleNamespace)
const {t: tCore} = useTranslation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {structureLocaleNamespace, usePaneRouter} from 'sanity/structure'

import {Banner} from './Banner'

export function ArchivedReleaseDocumentBanner(): JSX.Element {
export function ArchivedReleaseDocumentBanner(): React.JSX.Element {
const {t} = useTranslation(structureLocaleNamespace)
const {archivedReleases} = useReleases()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const TitleContainer = styled(Text)`
min-width: 0;
`
export function DocumentHeaderTitle({collapsed = false}: {collapsed?: boolean}): React.JSX.Element {
const {connectionState, schemaType, title, editState} = useDocumentPane()
const documentValue = editState?.draft || editState?.published
const {connectionState, schemaType, title, value: documentValue} = useDocumentPane()
const subscribed = Boolean(documentValue)

const {error, value} = useValuePreview({
Expand Down
Loading

0 comments on commit 8b8208d

Please sign in to comment.