sanity-plugin-workspace-home 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/WorkspaceHome.tsx +50 -7
- package/src/components/WorkspacePreview.tsx +33 -10
package/package.json
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
import {useActiveWorkspace, useWorkspaces} from 'sanity'
|
|
2
|
-
import {
|
|
2
|
+
import {Box, Text, TextInput, Flex, Container, Stack, Heading, Card} from '@sanity/ui'
|
|
3
|
+
import React, {useRef, useEffect, useState, useMemo, useCallback} from 'react'
|
|
3
4
|
|
|
4
5
|
import WorkspacePreview from './WorkspacePreview'
|
|
5
|
-
import {useEffect} from 'react'
|
|
6
6
|
|
|
7
7
|
export default function WorkspaceHome() {
|
|
8
|
-
const [
|
|
8
|
+
const [, ...workspaces] = useWorkspaces()
|
|
9
9
|
const {setActiveWorkspace} = useActiveWorkspace()
|
|
10
10
|
|
|
11
|
+
// Handle search query
|
|
12
|
+
const [query, setQuery] = useState('')
|
|
13
|
+
const searchInput = useRef(null)
|
|
14
|
+
const handleQuery = useCallback(
|
|
15
|
+
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
16
|
+
setQuery(e.target.value)
|
|
17
|
+
},
|
|
18
|
+
[setQuery]
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
// filter workspaces if name, dataset or title matches query
|
|
22
|
+
const filteredWorkspaces = useMemo(() => {
|
|
23
|
+
return workspaces.filter((workspace) => {
|
|
24
|
+
return (
|
|
25
|
+
workspace.name.toLowerCase().includes(query.toLowerCase()) ||
|
|
26
|
+
workspace.dataset.toLowerCase().includes(query.toLowerCase()) ||
|
|
27
|
+
workspace.title.toLowerCase().includes(query.toLowerCase())
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
}, [workspaces, query])
|
|
31
|
+
|
|
11
32
|
// Listen to keypress of workspace index
|
|
12
33
|
useEffect(() => {
|
|
13
34
|
const handleKeypress = (event: KeyboardEvent) => {
|
|
35
|
+
// Ignore if search query exists or search input is focused
|
|
36
|
+
if (query || searchInput.current === document.activeElement) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
14
40
|
const index = parseInt(event.key, 10) - 1
|
|
15
41
|
if (index >= 0 && index < workspaces.length) {
|
|
16
42
|
setActiveWorkspace(workspaces[index].name)
|
|
@@ -22,7 +48,7 @@ export default function WorkspaceHome() {
|
|
|
22
48
|
return () => {
|
|
23
49
|
window.removeEventListener('keypress', handleKeypress)
|
|
24
50
|
}
|
|
25
|
-
}, [workspaces, setActiveWorkspace])
|
|
51
|
+
}, [query, workspaces, setActiveWorkspace])
|
|
26
52
|
|
|
27
53
|
return (
|
|
28
54
|
<Card tone="transparent" height="fill">
|
|
@@ -30,9 +56,26 @@ export default function WorkspaceHome() {
|
|
|
30
56
|
<Container>
|
|
31
57
|
<Stack space={4}>
|
|
32
58
|
<Heading>Workspaces</Heading>
|
|
33
|
-
{
|
|
34
|
-
<
|
|
35
|
-
|
|
59
|
+
<Card padding={[2, 3, 4, 4]} radius={3} shadow={2}>
|
|
60
|
+
<Stack space={3}>
|
|
61
|
+
<Stack space={2}>
|
|
62
|
+
<Text size={1} weight="semibold">
|
|
63
|
+
Search
|
|
64
|
+
</Text>
|
|
65
|
+
<TextInput ref={searchInput} value={query} onChange={handleQuery} />
|
|
66
|
+
</Stack>
|
|
67
|
+
<Box>
|
|
68
|
+
{filteredWorkspaces.map((workspace, index) => (
|
|
69
|
+
<WorkspacePreview
|
|
70
|
+
key={workspace.name}
|
|
71
|
+
workspace={workspace}
|
|
72
|
+
index={index}
|
|
73
|
+
query={query}
|
|
74
|
+
/>
|
|
75
|
+
))}
|
|
76
|
+
</Box>
|
|
77
|
+
</Stack>
|
|
78
|
+
</Card>
|
|
36
79
|
</Stack>
|
|
37
80
|
</Container>
|
|
38
81
|
</Flex>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Button, Hotkeys, Stack, Box, Flex,
|
|
2
|
-
|
|
1
|
+
import {Grid, Button, Hotkeys, Stack, Box, Flex, Card, Text} from '@sanity/ui'
|
|
2
|
+
import {DatabaseIcon} from '@sanity/icons'
|
|
3
3
|
import React, {createElement, isValidElement, useMemo} from 'react'
|
|
4
4
|
import {isValidElementType} from 'react-is'
|
|
5
5
|
import {useActiveWorkspace, WorkspaceSummary} from 'sanity'
|
|
@@ -24,10 +24,13 @@ export const MediaCard = styled(Card)`
|
|
|
24
24
|
export type WorkspacePreviewProps = {
|
|
25
25
|
workspace: WorkspaceSummary
|
|
26
26
|
index: number
|
|
27
|
+
query: string
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export default function WorkspacePreview(props: WorkspacePreviewProps) {
|
|
30
|
-
const {
|
|
31
|
+
const {workspace, index, query} = props
|
|
32
|
+
const {icon, title, name, subtitle, dataset} = workspace
|
|
33
|
+
|
|
31
34
|
const {setActiveWorkspace} = useActiveWorkspace()
|
|
32
35
|
const iconComponent = useMemo(() => createIcon(icon), [icon])
|
|
33
36
|
|
|
@@ -42,25 +45,45 @@ export default function WorkspacePreview(props: WorkspacePreviewProps) {
|
|
|
42
45
|
// localStorage.setItem('favoriteWorkspace', name)
|
|
43
46
|
// }, [name])
|
|
44
47
|
|
|
48
|
+
const hotKeyIndex = index + 1 === 10 ? 0 : index + 1
|
|
49
|
+
|
|
45
50
|
return (
|
|
46
|
-
<Card
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
<Box flex={1}>
|
|
51
|
+
<Card borderTop={Boolean(index)} tone="default">
|
|
52
|
+
<Grid columns={5} gap={[2, 3, 4, 4]} paddingY={1}>
|
|
53
|
+
<Card columnStart={1} columnEnd={3}>
|
|
50
54
|
<Stack>
|
|
51
55
|
<Button mode="bleed" tone="default" onClick={() => setActiveWorkspace(name)}>
|
|
52
56
|
<Flex align="center" gap={[2, 3, 4, 4]}>
|
|
53
57
|
{iconComponent ? <MediaCard>{createIcon(iconComponent)}</MediaCard> : null}
|
|
54
58
|
<Box flex={1}>
|
|
55
59
|
<Stack space={[1, 2, 3, 3]}>
|
|
56
|
-
<
|
|
60
|
+
<Text size={3} weight="semibold">
|
|
61
|
+
{title || name}
|
|
62
|
+
</Text>
|
|
57
63
|
{subtitle ? <Text muted>{subtitle}</Text> : null}
|
|
58
64
|
</Stack>
|
|
59
65
|
</Box>
|
|
60
66
|
</Flex>
|
|
61
67
|
</Button>
|
|
62
68
|
</Stack>
|
|
63
|
-
</
|
|
69
|
+
</Card>
|
|
70
|
+
<Card columnStart={3} columnEnd={5}>
|
|
71
|
+
<Flex height="fill" align="center" gap={2}>
|
|
72
|
+
<Text size={1} weight="semibold">
|
|
73
|
+
<DatabaseIcon />
|
|
74
|
+
</Text>
|
|
75
|
+
<Text size={1} weight="semibold">
|
|
76
|
+
{dataset}
|
|
77
|
+
</Text>
|
|
78
|
+
</Flex>
|
|
79
|
+
</Card>
|
|
80
|
+
<Card paddingRight={[2, 3, 3, 3]}>
|
|
81
|
+
<Flex height="fill" align="center" justify="flex-end">
|
|
82
|
+
{!query && hotKeyIndex < 10 ? (
|
|
83
|
+
<Hotkeys keys={[String(hotKeyIndex)]} padding={2} />
|
|
84
|
+
) : null}
|
|
85
|
+
</Flex>
|
|
86
|
+
</Card>
|
|
64
87
|
{/* <Button
|
|
65
88
|
mode={isFavourite ? 'default' : 'bleed'}
|
|
66
89
|
tone={isFavourite ? 'primary' : 'default'}
|
|
@@ -71,7 +94,7 @@ export default function WorkspacePreview(props: WorkspacePreviewProps) {
|
|
|
71
94
|
setFavoriteWorkspace()
|
|
72
95
|
}}
|
|
73
96
|
/> */}
|
|
74
|
-
</
|
|
97
|
+
</Grid>
|
|
75
98
|
</Card>
|
|
76
99
|
)
|
|
77
100
|
}
|