@nocode-factory/sanity-kit 2.52.0 → 2.54.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 +36 -4
- package/dist/{finalUrl-CaFXmYvm.js → finalUrl-IXF3zbT9.js} +7 -2
- package/dist/finalUrl-IXF3zbT9.js.map +1 -0
- package/dist/{fixCrossLanguageReferences-w3whO9xM.d.ts → fixCrossLanguageReferences-C1VsmGsJ.d.ts} +21 -2
- package/dist/{fixCrossLanguageReferences-BeXywAAU.js → fixCrossLanguageReferences-CDczoic9.js} +2 -2
- package/dist/{fixCrossLanguageReferences-BeXywAAU.js.map → fixCrossLanguageReferences-CDczoic9.js.map} +1 -1
- package/dist/index.d.ts +186 -8
- package/dist/index.js +1136 -121
- package/dist/index.js.map +1 -1
- package/dist/jsonld.js +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +2 -2
- package/package.json +1 -1
- package/src/config/resolve.ts +5 -0
- package/src/config/types.ts +21 -0
- package/src/hooks/useAssetDelete.ts +60 -0
- package/src/hooks/useBoardLayout.ts +25 -1
- package/src/hooks/useCollection.ts +51 -0
- package/src/index.ts +23 -1
- package/src/lib/assetRefs.ts +53 -0
- package/src/lib/collectionColumns.ts +114 -0
- package/src/lib/collectionQuery.ts +23 -0
- package/src/lib/collectionRows.ts +92 -0
- package/src/lib/collectionTable.ts +72 -0
- package/src/lib/collectionTypes.ts +49 -0
- package/src/lib/csv.ts +24 -0
- package/src/lib/download.ts +24 -0
- package/src/lib/i18nTemplates.ts +40 -0
- package/src/lib/pageOrder.ts +36 -0
- package/src/lib/pages.ts +11 -1
- package/src/lib/schemaColumns.ts +18 -5
- package/src/schema/boardLayout.ts +7 -0
- package/src/structure/collections.tsx +103 -0
- package/src/tools/assets/AssetCard.tsx +8 -10
- package/src/tools/assets/AssetDetail.tsx +97 -2
- package/src/tools/assets/AssetsTool.tsx +28 -11
- package/src/tools/collections/CollectionColumnPicker.tsx +122 -0
- package/src/tools/collections/CollectionTable.tsx +259 -0
- package/src/tools/collections/CollectionToolbar.tsx +68 -0
- package/src/tools/pages/PagesTool.tsx +15 -9
- package/src/tools/presentation/PagesNavigator.tsx +51 -6
- package/src/version.ts +1 -1
- package/dist/finalUrl-CaFXmYvm.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useCallback, useMemo, useRef, useState} from 'react'
|
|
2
|
-
import {Box, Button, Card, Flex,
|
|
2
|
+
import {Box, Button, Card, Flex, Select, Spinner, Stack, Text} from '@sanity/ui'
|
|
3
3
|
import {QueryError} from '../../ui/QueryError'
|
|
4
4
|
import {useAssets} from '../../hooks/useAssets'
|
|
5
5
|
import {useAssetMeta} from '../../hooks/useAssetMeta'
|
|
@@ -234,17 +234,19 @@ export function AssetsTool() {
|
|
|
234
234
|
</Text>
|
|
235
235
|
</Card>
|
|
236
236
|
) : view === 'grid' ? (
|
|
237
|
-
|
|
237
|
+
// Masonry (colonnes CSS) : chaque vignette garde son vrai ratio.
|
|
238
|
+
<Box style={{columnWidth: 200, columnGap: 12}}>
|
|
238
239
|
{visible.map((asset) => (
|
|
239
|
-
<
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
240
|
+
<Box key={asset._id} style={{breakInside: 'avoid', marginBottom: 12}}>
|
|
241
|
+
<AssetCard
|
|
242
|
+
asset={asset}
|
|
243
|
+
selected={selectedIds.has(asset._id)}
|
|
244
|
+
onToggleSelect={() => toggleSelect(asset._id)}
|
|
245
|
+
onOpen={() => setOpenedId(asset._id)}
|
|
246
|
+
/>
|
|
247
|
+
</Box>
|
|
246
248
|
))}
|
|
247
|
-
</
|
|
249
|
+
</Box>
|
|
248
250
|
) : (
|
|
249
251
|
<AssetTable
|
|
250
252
|
assets={visible}
|
|
@@ -265,7 +267,22 @@ export function AssetsTool() {
|
|
|
265
267
|
</Stack>
|
|
266
268
|
|
|
267
269
|
{opened ? (
|
|
268
|
-
<AssetDetail
|
|
270
|
+
<AssetDetail
|
|
271
|
+
asset={opened}
|
|
272
|
+
folders={meta.folders}
|
|
273
|
+
folder={folderOf(opened._id)}
|
|
274
|
+
onMove={(folder) => meta.moveAsset(opened._id, folder)}
|
|
275
|
+
onClose={() => setOpenedId(null)}
|
|
276
|
+
onDeleted={() => {
|
|
277
|
+
setSelectedIds((prev) => {
|
|
278
|
+
const next = new Set(prev)
|
|
279
|
+
next.delete(opened._id)
|
|
280
|
+
return next
|
|
281
|
+
})
|
|
282
|
+
setOpenedId(null)
|
|
283
|
+
refresh()
|
|
284
|
+
}}
|
|
285
|
+
/>
|
|
269
286
|
) : null}
|
|
270
287
|
</Flex>
|
|
271
288
|
)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {useMemo, useState} from 'react'
|
|
2
|
+
import {Box, Button, Flex, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {CheckmarkIcon} from '@sanity/icons/Checkmark'
|
|
4
|
+
import {ControlsIcon} from '@sanity/icons/Controls'
|
|
5
|
+
import {InlinePopover} from '../../ui/Popover'
|
|
6
|
+
import {BORDER} from '../../ui/tokens'
|
|
7
|
+
import type {CollectionColumn} from '../../lib/collectionColumns'
|
|
8
|
+
|
|
9
|
+
export interface CollectionColumnPickerProps {
|
|
10
|
+
columns: readonly CollectionColumn[]
|
|
11
|
+
/** Clés visibles, dans l'ordre d'affichage. */
|
|
12
|
+
visible: readonly string[]
|
|
13
|
+
onToggle: (key: string) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Choix des colonnes affichées, sans quitter la table (façon tableur). */
|
|
17
|
+
export function CollectionColumnPicker(props: CollectionColumnPickerProps) {
|
|
18
|
+
const {columns, visible, onToggle} = props
|
|
19
|
+
const visibleSet = useMemo(() => new Set(visible), [visible])
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<InlinePopover
|
|
23
|
+
width={264}
|
|
24
|
+
trigger={({toggle}) => (
|
|
25
|
+
<Button
|
|
26
|
+
mode="bleed"
|
|
27
|
+
fontSize={1}
|
|
28
|
+
padding={2}
|
|
29
|
+
icon={ControlsIcon}
|
|
30
|
+
text={`Columns · ${visible.length}`}
|
|
31
|
+
onClick={toggle}
|
|
32
|
+
/>
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
{() => <ColumnList columns={columns} visibleSet={visibleSet} onToggle={onToggle} />}
|
|
36
|
+
</InlinePopover>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function Row(props: {label: string; checked: boolean; onClick: () => void}) {
|
|
41
|
+
return (
|
|
42
|
+
<Flex
|
|
43
|
+
align="center"
|
|
44
|
+
gap={2}
|
|
45
|
+
padding={2}
|
|
46
|
+
onClick={props.onClick}
|
|
47
|
+
style={{cursor: 'pointer', borderRadius: 3}}
|
|
48
|
+
onMouseEnter={(event) => {
|
|
49
|
+
event.currentTarget.style.background = 'var(--card-muted-bg-color, rgba(127,127,127,0.12))'
|
|
50
|
+
}}
|
|
51
|
+
onMouseLeave={(event) => {
|
|
52
|
+
event.currentTarget.style.background = 'transparent'
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<Box style={{width: 14, flex: 'none'}}>
|
|
56
|
+
{props.checked && <CheckmarkIcon style={{fontSize: 14, opacity: 0.7}} />}
|
|
57
|
+
</Box>
|
|
58
|
+
<Text size={1} muted={!props.checked} textOverflow="ellipsis">
|
|
59
|
+
{props.label}
|
|
60
|
+
</Text>
|
|
61
|
+
</Flex>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Au-delà d'une poignée de champs, un filtre apparaît pour en chercher un. */
|
|
66
|
+
function ColumnList(props: {
|
|
67
|
+
columns: readonly CollectionColumn[]
|
|
68
|
+
visibleSet: ReadonlySet<string>
|
|
69
|
+
onToggle: (key: string) => void
|
|
70
|
+
}) {
|
|
71
|
+
const {columns, visibleSet, onToggle} = props
|
|
72
|
+
const [filter, setFilter] = useState('')
|
|
73
|
+
|
|
74
|
+
const matches = useMemo(() => {
|
|
75
|
+
const needle = filter.trim().toLowerCase()
|
|
76
|
+
if (!needle) return columns
|
|
77
|
+
return columns.filter((column) => column.label.toLowerCase().includes(needle))
|
|
78
|
+
}, [columns, filter])
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Stack gap={0}>
|
|
82
|
+
{columns.length > 8 && (
|
|
83
|
+
<Box paddingX={1} paddingBottom={1}>
|
|
84
|
+
<input
|
|
85
|
+
type="text"
|
|
86
|
+
value={filter}
|
|
87
|
+
placeholder="Filter…"
|
|
88
|
+
onChange={(event) => setFilter(event.currentTarget.value)}
|
|
89
|
+
style={{
|
|
90
|
+
width: '100%',
|
|
91
|
+
font: 'inherit',
|
|
92
|
+
fontSize: 12,
|
|
93
|
+
padding: '6px',
|
|
94
|
+
borderRadius: 3,
|
|
95
|
+
border: `1px solid ${BORDER}`,
|
|
96
|
+
background: 'var(--card-bg-color)',
|
|
97
|
+
color: 'var(--card-fg-color)',
|
|
98
|
+
outline: 'none',
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
</Box>
|
|
102
|
+
)}
|
|
103
|
+
|
|
104
|
+
{matches.map((column) => (
|
|
105
|
+
<Row
|
|
106
|
+
key={column.key}
|
|
107
|
+
label={column.label}
|
|
108
|
+
checked={visibleSet.has(column.key)}
|
|
109
|
+
onClick={() => onToggle(column.key)}
|
|
110
|
+
/>
|
|
111
|
+
))}
|
|
112
|
+
|
|
113
|
+
{matches.length === 0 && (
|
|
114
|
+
<Box padding={2}>
|
|
115
|
+
<Text size={0} muted>
|
|
116
|
+
No matching fields.
|
|
117
|
+
</Text>
|
|
118
|
+
</Box>
|
|
119
|
+
)}
|
|
120
|
+
</Stack>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import {useCallback, useMemo, useState} from 'react'
|
|
2
|
+
import {Badge, Box, Flex, Spinner, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {ChevronDownIcon} from '@sanity/icons/ChevronDown'
|
|
4
|
+
import {ChevronUpIcon} from '@sanity/icons/ChevronUp'
|
|
5
|
+
import {useRouter} from 'sanity/router'
|
|
6
|
+
import {useSchema} from 'sanity'
|
|
7
|
+
import {useCollection} from '../../hooks/useCollection'
|
|
8
|
+
import {filterRows, sortRows, type CollectionSort} from '../../lib/collectionTable'
|
|
9
|
+
import {toCsv} from '../../lib/csv'
|
|
10
|
+
import {downloadText} from '../../lib/download'
|
|
11
|
+
import {deriveCollectionColumns, type CollectionColumn} from '../../lib/collectionColumns'
|
|
12
|
+
import type {SchemaTypeLike} from '../../lib/schemaColumns'
|
|
13
|
+
import type {CollectionRow} from '../../lib/collectionRows'
|
|
14
|
+
import {BORDER, BORDER_SOFT, CELL, TABULAR} from '../../ui/tokens'
|
|
15
|
+
import {QueryError} from '../../ui/QueryError'
|
|
16
|
+
import {CollectionToolbar} from './CollectionToolbar'
|
|
17
|
+
|
|
18
|
+
/** Colonnes montrées par défaut : le titre d'abord, puis les premières. */
|
|
19
|
+
const DEFAULT_MAX = 6
|
|
20
|
+
|
|
21
|
+
function defaultVisible(columns: readonly CollectionColumn[]): string[] {
|
|
22
|
+
const title = columns.find((c) => c.key === 'title') ?? columns.find((c) => c.kind === 'text')
|
|
23
|
+
const ordered = title ? [title, ...columns.filter((c) => c !== title)] : [...columns]
|
|
24
|
+
return ordered.slice(0, DEFAULT_MAX).map((c) => c.key)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CollectionTableProps {
|
|
28
|
+
type: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function CollectionTable({type}: CollectionTableProps) {
|
|
32
|
+
const router = useRouter()
|
|
33
|
+
|
|
34
|
+
// `null` = pas encore de choix explicite → colonnes par défaut.
|
|
35
|
+
const [selected, setSelected] = useState<string[] | null>(null)
|
|
36
|
+
const [sort, setSort] = useState<CollectionSort>({key: null, direction: 'asc'})
|
|
37
|
+
const [search, setSearch] = useState('')
|
|
38
|
+
const [columnFilters, setColumnFilters] = useState<Record<string, string>>({})
|
|
39
|
+
|
|
40
|
+
// Toutes les colonnes viennent du schéma (sans requête) : elles fixent le
|
|
41
|
+
// défaut et alimentent le sélecteur. Seules les visibles sont ensuite
|
|
42
|
+
// projetées par le hook de données.
|
|
43
|
+
const schema = useSchema()
|
|
44
|
+
const allColumns = useMemo(
|
|
45
|
+
() => deriveCollectionColumns(schema.get(type) as SchemaTypeLike | undefined),
|
|
46
|
+
[schema, type],
|
|
47
|
+
)
|
|
48
|
+
const visibleKeys = useMemo(() => selected ?? defaultVisible(allColumns), [selected, allColumns])
|
|
49
|
+
|
|
50
|
+
const {visibleColumns, rows, loading, error, refresh} = useCollection(type, visibleKeys)
|
|
51
|
+
|
|
52
|
+
const visible = useMemo(() => {
|
|
53
|
+
const filtered = filterRows(rows, {search, columns: columnFilters}, visibleColumns)
|
|
54
|
+
return sortRows(filtered, sort, visibleColumns)
|
|
55
|
+
}, [rows, search, columnFilters, visibleColumns, sort])
|
|
56
|
+
|
|
57
|
+
const onToggleColumn = useCallback(
|
|
58
|
+
(key: string) => {
|
|
59
|
+
setSelected((current) => {
|
|
60
|
+
const base = current ?? defaultVisible(allColumns)
|
|
61
|
+
return base.includes(key) ? base.filter((k) => k !== key) : [...base, key]
|
|
62
|
+
})
|
|
63
|
+
// Un filtre sur une colonne qu'on masque n'a plus de sens.
|
|
64
|
+
setColumnFilters((current) => {
|
|
65
|
+
if (!current[key]) return current
|
|
66
|
+
const {[key]: _removed, ...rest} = current
|
|
67
|
+
return rest
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
[allColumns],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const onSort = useCallback((key: string) => {
|
|
74
|
+
setSort((current) =>
|
|
75
|
+
current.key === key
|
|
76
|
+
? {key, direction: current.direction === 'asc' ? 'desc' : 'asc'}
|
|
77
|
+
: {key, direction: 'asc'},
|
|
78
|
+
)
|
|
79
|
+
}, [])
|
|
80
|
+
|
|
81
|
+
const onExport = useCallback(() => {
|
|
82
|
+
downloadText(`${type}.csv`, toCsv(visible, visibleColumns))
|
|
83
|
+
}, [type, visible, visibleColumns])
|
|
84
|
+
|
|
85
|
+
const onColumnFilter = useCallback((key: string, value: string) => {
|
|
86
|
+
setColumnFilters((current) => ({...current, [key]: value}))
|
|
87
|
+
}, [])
|
|
88
|
+
|
|
89
|
+
if (error) return <QueryError error={error} onRetry={refresh} />
|
|
90
|
+
|
|
91
|
+
const summary =
|
|
92
|
+
visible.length === rows.length
|
|
93
|
+
? `${rows.length} item${rows.length > 1 ? 's' : ''}`
|
|
94
|
+
: `${visible.length} of ${rows.length}`
|
|
95
|
+
|
|
96
|
+
const grid: React.CSSProperties = {
|
|
97
|
+
display: 'grid',
|
|
98
|
+
gridTemplateColumns: visibleColumns
|
|
99
|
+
.map((_, index) => (index === 0 ? 'minmax(200px, 1.6fr)' : 'minmax(150px, 1fr)'))
|
|
100
|
+
.join(' '),
|
|
101
|
+
gap: '0.875rem',
|
|
102
|
+
alignItems: 'center',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Stack gap={4}>
|
|
107
|
+
<CollectionToolbar
|
|
108
|
+
search={search}
|
|
109
|
+
onSearch={setSearch}
|
|
110
|
+
columns={allColumns}
|
|
111
|
+
visible={visibleKeys}
|
|
112
|
+
onToggleColumn={onToggleColumn}
|
|
113
|
+
onExport={onExport}
|
|
114
|
+
onRefresh={refresh}
|
|
115
|
+
busy={loading}
|
|
116
|
+
summary={summary}
|
|
117
|
+
/>
|
|
118
|
+
|
|
119
|
+
{loading && rows.length === 0 ? (
|
|
120
|
+
<Flex align="center" justify="center" padding={6} gap={3}>
|
|
121
|
+
<Spinner muted />
|
|
122
|
+
<Text size={1} muted>
|
|
123
|
+
Loading…
|
|
124
|
+
</Text>
|
|
125
|
+
</Flex>
|
|
126
|
+
) : visibleColumns.length === 0 ? (
|
|
127
|
+
<Box padding={5}>
|
|
128
|
+
<Text size={1} muted align="center">
|
|
129
|
+
No displayable field in this type. Pick columns above.
|
|
130
|
+
</Text>
|
|
131
|
+
</Box>
|
|
132
|
+
) : (
|
|
133
|
+
<Box style={{overflowX: 'auto', border: `1px solid ${BORDER_SOFT}`, borderRadius: 6}}>
|
|
134
|
+
<Box style={{minWidth: 'min-content'}}>
|
|
135
|
+
{/* En-tête : libellé triable + filtre « contient » par colonne. */}
|
|
136
|
+
<Box
|
|
137
|
+
paddingX={3}
|
|
138
|
+
paddingY={2}
|
|
139
|
+
style={{
|
|
140
|
+
...grid,
|
|
141
|
+
alignItems: 'end',
|
|
142
|
+
borderBottom: `1px solid ${BORDER}`,
|
|
143
|
+
position: 'sticky',
|
|
144
|
+
top: 0,
|
|
145
|
+
background: 'var(--card-bg-color, inherit)',
|
|
146
|
+
zIndex: 2,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{visibleColumns.map((column) => {
|
|
150
|
+
const active = sort.key === column.key
|
|
151
|
+
const Arrow = sort.direction === 'asc' ? ChevronUpIcon : ChevronDownIcon
|
|
152
|
+
return (
|
|
153
|
+
<Stack key={column.key} gap={2} style={CELL}>
|
|
154
|
+
<Flex
|
|
155
|
+
align="center"
|
|
156
|
+
gap={1}
|
|
157
|
+
onClick={() => onSort(column.key)}
|
|
158
|
+
style={{cursor: 'pointer', userSelect: 'none'}}
|
|
159
|
+
title={`Sort by ${column.label.toLowerCase()}`}
|
|
160
|
+
>
|
|
161
|
+
<Text size={0} weight="medium" muted={!active} textOverflow="ellipsis">
|
|
162
|
+
{column.label}
|
|
163
|
+
</Text>
|
|
164
|
+
{active && <Arrow style={{fontSize: 13, opacity: 0.7, flex: 'none'}} />}
|
|
165
|
+
</Flex>
|
|
166
|
+
<input
|
|
167
|
+
type="text"
|
|
168
|
+
value={columnFilters[column.key] ?? ''}
|
|
169
|
+
placeholder="Filter…"
|
|
170
|
+
onChange={(event) => onColumnFilter(column.key, event.currentTarget.value)}
|
|
171
|
+
style={{
|
|
172
|
+
width: '100%',
|
|
173
|
+
font: 'inherit',
|
|
174
|
+
fontSize: 11,
|
|
175
|
+
padding: '3px 6px',
|
|
176
|
+
borderRadius: 3,
|
|
177
|
+
border: `1px solid ${BORDER_SOFT}`,
|
|
178
|
+
background: 'var(--card-bg-color)',
|
|
179
|
+
color: 'var(--card-fg-color)',
|
|
180
|
+
outline: 'none',
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
</Stack>
|
|
184
|
+
)
|
|
185
|
+
})}
|
|
186
|
+
</Box>
|
|
187
|
+
|
|
188
|
+
{visible.map((row) => (
|
|
189
|
+
<CollectionRowView
|
|
190
|
+
key={row.id}
|
|
191
|
+
row={row}
|
|
192
|
+
columns={visibleColumns}
|
|
193
|
+
grid={grid}
|
|
194
|
+
onOpen={() => router.navigateIntent('edit', {id: row.id, type})}
|
|
195
|
+
/>
|
|
196
|
+
))}
|
|
197
|
+
|
|
198
|
+
{visible.length === 0 && (
|
|
199
|
+
<Box padding={5}>
|
|
200
|
+
<Text size={1} muted align="center">
|
|
201
|
+
{rows.length === 0 ? 'No item yet.' : 'No match.'}
|
|
202
|
+
</Text>
|
|
203
|
+
</Box>
|
|
204
|
+
)}
|
|
205
|
+
</Box>
|
|
206
|
+
</Box>
|
|
207
|
+
)}
|
|
208
|
+
</Stack>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function CollectionRowView(props: {
|
|
213
|
+
row: CollectionRow
|
|
214
|
+
columns: readonly CollectionColumn[]
|
|
215
|
+
grid: React.CSSProperties
|
|
216
|
+
onOpen: () => void
|
|
217
|
+
}) {
|
|
218
|
+
const {row, columns, grid, onOpen} = props
|
|
219
|
+
const [hovered, setHovered] = useState(false)
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<Box
|
|
223
|
+
paddingX={3}
|
|
224
|
+
paddingY={2}
|
|
225
|
+
onClick={onOpen}
|
|
226
|
+
onMouseEnter={() => setHovered(true)}
|
|
227
|
+
onMouseLeave={() => setHovered(false)}
|
|
228
|
+
style={{
|
|
229
|
+
...grid,
|
|
230
|
+
cursor: 'pointer',
|
|
231
|
+
borderBottom: `1px solid ${BORDER_SOFT}`,
|
|
232
|
+
background: hovered ? 'var(--card-muted-bg-color, rgba(127,127,127,0.08))' : 'transparent',
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
{columns.map((column, index) => {
|
|
236
|
+
const cell = row.cells[column.key]
|
|
237
|
+
const empty = !cell || cell.raw === null || cell.text === ''
|
|
238
|
+
return (
|
|
239
|
+
<Flex key={column.key} align="center" gap={2} style={CELL}>
|
|
240
|
+
<Text
|
|
241
|
+
size={1}
|
|
242
|
+
muted={empty}
|
|
243
|
+
weight={index === 0 ? 'medium' : 'regular'}
|
|
244
|
+
textOverflow="ellipsis"
|
|
245
|
+
style={{flex: 1, minWidth: 0, ...(column.kind === 'number' || column.kind === 'date' ? TABULAR : null)}}
|
|
246
|
+
>
|
|
247
|
+
{empty ? '—' : cell.text}
|
|
248
|
+
</Text>
|
|
249
|
+
{index === 0 && row.draftOnly && (
|
|
250
|
+
<Badge tone="caution" fontSize={0} style={{flex: 'none'}}>
|
|
251
|
+
Draft
|
|
252
|
+
</Badge>
|
|
253
|
+
)}
|
|
254
|
+
</Flex>
|
|
255
|
+
)
|
|
256
|
+
})}
|
|
257
|
+
</Box>
|
|
258
|
+
)
|
|
259
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {Box, Button, Flex, Text, TextInput} from '@sanity/ui'
|
|
2
|
+
import {SearchIcon} from '@sanity/icons/Search'
|
|
3
|
+
import {DownloadIcon} from '@sanity/icons/Download'
|
|
4
|
+
import {RefreshIcon} from '@sanity/icons/Refresh'
|
|
5
|
+
import {CollectionColumnPicker} from './CollectionColumnPicker'
|
|
6
|
+
import type {CollectionColumn} from '../../lib/collectionColumns'
|
|
7
|
+
|
|
8
|
+
export interface CollectionToolbarProps {
|
|
9
|
+
search: string
|
|
10
|
+
onSearch: (value: string) => void
|
|
11
|
+
columns: readonly CollectionColumn[]
|
|
12
|
+
visible: readonly string[]
|
|
13
|
+
onToggleColumn: (key: string) => void
|
|
14
|
+
onExport: () => void
|
|
15
|
+
onRefresh: () => void
|
|
16
|
+
busy: boolean
|
|
17
|
+
/** Résumé « N items » ou « N of M ». */
|
|
18
|
+
summary: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Barre au-dessus de la table : recherche, colonnes, export CSV. */
|
|
22
|
+
export function CollectionToolbar(props: CollectionToolbarProps) {
|
|
23
|
+
const {search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, busy, summary} = props
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Flex align="center" gap={2} wrap="wrap">
|
|
27
|
+
<Box style={{flex: 1, minWidth: 180}}>
|
|
28
|
+
<TextInput
|
|
29
|
+
icon={SearchIcon}
|
|
30
|
+
fontSize={1}
|
|
31
|
+
padding={2}
|
|
32
|
+
radius={2}
|
|
33
|
+
placeholder="Search"
|
|
34
|
+
value={search}
|
|
35
|
+
onChange={(event) => onSearch(event.currentTarget.value)}
|
|
36
|
+
clearButton={Boolean(search)}
|
|
37
|
+
onClear={() => onSearch('')}
|
|
38
|
+
/>
|
|
39
|
+
</Box>
|
|
40
|
+
|
|
41
|
+
<Text size={1} muted style={{flex: 'none'}}>
|
|
42
|
+
{summary}
|
|
43
|
+
</Text>
|
|
44
|
+
|
|
45
|
+
<Flex gap={1} style={{flex: 'none'}}>
|
|
46
|
+
<CollectionColumnPicker columns={columns} visible={visible} onToggle={onToggleColumn} />
|
|
47
|
+
<Button
|
|
48
|
+
mode="bleed"
|
|
49
|
+
fontSize={1}
|
|
50
|
+
padding={2}
|
|
51
|
+
icon={DownloadIcon}
|
|
52
|
+
text="Export CSV"
|
|
53
|
+
onClick={onExport}
|
|
54
|
+
/>
|
|
55
|
+
<Button
|
|
56
|
+
mode="bleed"
|
|
57
|
+
fontSize={1}
|
|
58
|
+
padding={2}
|
|
59
|
+
icon={RefreshIcon}
|
|
60
|
+
title="Refresh"
|
|
61
|
+
aria-label="Refresh"
|
|
62
|
+
onClick={onRefresh}
|
|
63
|
+
disabled={busy}
|
|
64
|
+
/>
|
|
65
|
+
</Flex>
|
|
66
|
+
</Flex>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
@@ -31,7 +31,7 @@ export function PagesTool() {
|
|
|
31
31
|
const config = useKitConfig()
|
|
32
32
|
const router = useRouter()
|
|
33
33
|
|
|
34
|
-
const {byId, saveColumns, patchNode, patchField} = useBoardLayout()
|
|
34
|
+
const {byId, saveColumns, patchNode, patchField, pageOrder} = useBoardLayout()
|
|
35
35
|
const columnOptions = useColumnOptions()
|
|
36
36
|
const preview = usePreviewTarget()
|
|
37
37
|
const columns = useInternalColumns()
|
|
@@ -45,9 +45,11 @@ export function PagesTool() {
|
|
|
45
45
|
const [onlyTodo, setOnlyTodo] = useState(false)
|
|
46
46
|
const [groupBy, setGroupBy] = useState<GroupBy>('none')
|
|
47
47
|
const [rawColorBy, setColorBy] = useState<ColorBy>('tag')
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
|
|
48
|
+
// `null` = tri automatique : l'ordre manuel (réordonné dans Presentation)
|
|
49
|
+
// s'il existe, sinon l'ordre du Studio. Un clic sur une colonne fige un tri
|
|
50
|
+
// explicite. Aucune colonne n'est marquée triée tant que l'éditeur n'a pas
|
|
51
|
+
// choisi.
|
|
52
|
+
const [sortKey, setSortKey] = useState<SortKey | null>(null)
|
|
51
53
|
const [sortDirection, setSortDirection] = useState<SortDirection>('asc')
|
|
52
54
|
const [page, setPage] = useState(0)
|
|
53
55
|
const [hidden, setHidden] = useState<ReadonlySet<string>>(new Set())
|
|
@@ -79,15 +81,19 @@ export function PagesTool() {
|
|
|
79
81
|
[config.i18n, rows],
|
|
80
82
|
)
|
|
81
83
|
|
|
84
|
+
// Tri effectif : l'ordre manuel partagé avec Presentation par défaut, sinon
|
|
85
|
+
// l'ordre du Studio ; un clic sur une colonne prend le dessus.
|
|
86
|
+
const effectiveSortKey: SortKey = sortKey ?? (pageOrder.length > 0 ? 'manual' : 'structure')
|
|
87
|
+
|
|
82
88
|
const visible = useMemo(
|
|
83
89
|
() =>
|
|
84
90
|
sortRows(
|
|
85
91
|
filterRows(rows, {search, locales: locale ? [locale] : undefined}).filter((row) => !onlyTodo || todos.has(row.id)),
|
|
86
|
-
|
|
92
|
+
effectiveSortKey,
|
|
87
93
|
sortDirection,
|
|
88
|
-
{typeOrder: config.pageTypeNames},
|
|
94
|
+
{typeOrder: config.pageTypeNames, pageOrder},
|
|
89
95
|
),
|
|
90
|
-
[rows, search, locale, onlyTodo, todos,
|
|
96
|
+
[rows, search, locale, onlyTodo, todos, effectiveSortKey, sortDirection, config.pageTypeNames, pageOrder],
|
|
91
97
|
)
|
|
92
98
|
|
|
93
99
|
// Un filtre qui réduit la liste ne doit pas laisser l'utilisateur sur une
|
|
@@ -134,7 +140,7 @@ export function PagesTool() {
|
|
|
134
140
|
})
|
|
135
141
|
|
|
136
142
|
const onSort = (key: SortKey) => {
|
|
137
|
-
if (key ===
|
|
143
|
+
if (key === effectiveSortKey) setSortDirection((d) => (d === 'asc' ? 'desc' : 'asc'))
|
|
138
144
|
else {
|
|
139
145
|
setSortKey(key)
|
|
140
146
|
setSortDirection('asc')
|
|
@@ -330,7 +336,7 @@ export function PagesTool() {
|
|
|
330
336
|
) : (
|
|
331
337
|
<PagesTable
|
|
332
338
|
groups={groups}
|
|
333
|
-
sortKey={
|
|
339
|
+
sortKey={effectiveSortKey}
|
|
334
340
|
sortDirection={sortDirection}
|
|
335
341
|
onSort={onSort}
|
|
336
342
|
columns={columns}
|