-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a "configuration issues" button + dialog to the global nav …
…bar in development
- Loading branch information
Showing
7 changed files
with
302 additions
and
190 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
92 changes: 92 additions & 0 deletions
92
packages/sanity/src/studio/components/navbar/configIssues/ConfigIssuesButton.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,92 @@ | ||
import React, {useCallback, useState} from 'react' | ||
import {Box, Button, Dialog, Heading, Inline, Stack, Text, Tooltip} from '@sanity/ui' | ||
|
||
import {InfoOutlineIcon, WarningOutlineIcon} from '@sanity/icons' | ||
import {useId} from '@reach/auto-id' | ||
import {useSchema} from '../../../../hooks' | ||
import {SchemaProblemGroups} from '../../../screens/schemaErrors/SchemaProblemGroups' | ||
import {useColorScheme} from '../../../colorScheme' | ||
|
||
export function ConfigIssuesButton() { | ||
const schema = useSchema() | ||
const groupsWithWarnings = | ||
schema._validation?.filter((group) => | ||
group.problems.some((problem) => problem.severity === 'warning') | ||
) || [] | ||
|
||
// get root scheme | ||
const {scheme} = useColorScheme() | ||
|
||
const dialogId = useId() || 'config-issues-dialog' | ||
|
||
const [isDialogOpen, setDialogOpen] = useState(false) | ||
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null) | ||
const handleOpen = useCallback(() => setDialogOpen(true), []) | ||
|
||
const handleClose = useCallback(() => { | ||
setDialogOpen(false) | ||
|
||
if (buttonElement) { | ||
buttonElement.focus() | ||
} | ||
}, [buttonElement]) | ||
|
||
if (groupsWithWarnings.length === 0) { | ||
return null | ||
} | ||
|
||
return ( | ||
<> | ||
<Tooltip | ||
content={ | ||
<Box padding={2}> | ||
<Text size={1}>Found configuration issues</Text> | ||
</Box> | ||
} | ||
placement="bottom" | ||
portal | ||
scheme={scheme} | ||
> | ||
<Box> | ||
<Button | ||
icon={WarningOutlineIcon} | ||
mode="bleed" | ||
tone="caution" | ||
onClick={handleOpen} | ||
ref={setButtonElement} | ||
selected={isDialogOpen} | ||
/> | ||
</Box> | ||
</Tooltip> | ||
|
||
{isDialogOpen && ( | ||
<Dialog | ||
header="Configuration issues" | ||
width={2} | ||
onClickOutside={handleClose} | ||
onClose={handleClose} | ||
// force root scheme here to "break out" of the navbar's dark scheme | ||
scheme={scheme} | ||
id={dialogId} | ||
> | ||
<Stack space={4} padding={4}> | ||
<Inline space={2} paddingY={3}> | ||
<Text muted size={1}> | ||
<InfoOutlineIcon /> | ||
</Text> | ||
<Text muted size={1}> | ||
Note: Configuration checks are only performed during development and will not be | ||
visible in production builds | ||
</Text> | ||
</Inline> | ||
|
||
<Heading as="h2" size={1}> | ||
Found {groupsWithWarnings.length} schema warnings | ||
</Heading> | ||
<SchemaProblemGroups problemGroups={groupsWithWarnings} /> | ||
</Stack> | ||
</Dialog> | ||
)} | ||
</> | ||
) | ||
} |
137 changes: 0 additions & 137 deletions
137
packages/sanity/src/studio/screens/schemaErrors/SchemaErrors.tsx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.