-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(structure): add history and review tabs to changes inspector pan…
…el (#7435) * feat(structure): add history and review tabs to changes inspector panel * fix(structure): move changes inspector navigation to paneRouter * fix(structure): update isReviewChangesOpen check in ChangeConnectorRoot * fix(structure): rename uses of version to revision * chore(core): rename review changes action to history
- Loading branch information
1 parent
694ecab
commit 8ac0374
Showing
12 changed files
with
274 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/sanity/src/structure/panes/document/inspectors/changes/ChangesTabs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import {CloseIcon} from '@sanity/icons' | ||
import {Box, Flex, TabList, TabPanel} from '@sanity/ui' | ||
import {type DocumentInspectorProps, useTranslation} from 'sanity' | ||
import {styled} from 'styled-components' | ||
|
||
import {Button, Tab} from '../../../../../ui-components' | ||
import {usePaneRouter} from '../../../../components/paneRouter/usePaneRouter' | ||
import {structureLocaleNamespace} from '../../../../i18n' | ||
import {HISTORY_INSPECTOR_NAME} from '../../constants' | ||
import {ChangesInspector} from './ChangesInspector' | ||
import {HistorySelector} from './HistorySelector' | ||
|
||
const FadeInFlex = styled(Flex)` | ||
opacity: 0; | ||
transition: opacity 200ms; | ||
&[data-ready] { | ||
opacity: 1; | ||
} | ||
` | ||
const TABS = ['history', 'review'] as const | ||
const isValidTab = (tab: string | undefined): tab is (typeof TABS)[number] => | ||
// @ts-expect-error TS doesn't understand the type guard | ||
tab && TABS.includes(tab) | ||
|
||
export function ChangesTabs(props: DocumentInspectorProps) { | ||
const {params, setParams} = usePaneRouter() | ||
const {t} = useTranslation(structureLocaleNamespace) | ||
const isReady = params?.inspect === HISTORY_INSPECTOR_NAME | ||
|
||
const paneRouterTab = isValidTab(params?.changesInspectorTab) | ||
? params.changesInspectorTab | ||
: TABS[0] | ||
const setPaneRouterTab = (tab: (typeof TABS)[number]) => | ||
setParams({ | ||
...params, | ||
changesInspectorTab: tab, | ||
}) | ||
|
||
return ( | ||
<FadeInFlex direction="column" padding={0} height="fill" data-ready={isReady ? '' : undefined}> | ||
<Flex align="center" padding={3} gap={2}> | ||
<TabList space={1} flex={1}> | ||
<Tab | ||
aria-controls="history-panel" | ||
id="history-tab" | ||
label={t('changes.tab.history')} | ||
onClick={() => setPaneRouterTab('history')} | ||
selected={paneRouterTab === 'history'} | ||
/> | ||
<Tab | ||
aria-controls="review-changes-panel" | ||
id="changes-tab" | ||
label={t('changes.tab.review-changes')} | ||
onClick={() => setPaneRouterTab('review')} | ||
selected={paneRouterTab === 'review'} | ||
/> | ||
</TabList> | ||
<Box flex="none"> | ||
<Button | ||
aria-label={t('changes.action.close-label')} | ||
icon={CloseIcon} | ||
mode="bleed" | ||
onClick={props.onClose} | ||
tooltipProps={{content: t('document-inspector.close-button.tooltip')}} | ||
/> | ||
</Box> | ||
</Flex> | ||
|
||
<TabPanel | ||
aria-labelledby="history-tab" | ||
height="fill" | ||
hidden={paneRouterTab !== 'history'} | ||
id="history-panel" | ||
> | ||
<HistorySelector showList={paneRouterTab === 'history'} /> | ||
</TabPanel> | ||
|
||
<TabPanel | ||
aria-labelledby="review-tab" | ||
hidden={paneRouterTab !== 'review'} | ||
id="review-panel" | ||
height="fill" | ||
> | ||
<ChangesInspector showChanges={paneRouterTab === 'review'} /> | ||
</TabPanel> | ||
</FadeInFlex> | ||
) | ||
} |
Oops, something went wrong.