@nocode-factory/sanity-kit 2.67.0 → 2.70.0-rc.1
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/CHANGELOG.md +41 -0
- package/dist/index.d.ts +48 -16
- package/dist/index.js +574 -290
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useCollection.ts +5 -2
- package/src/hooks/usePages.ts +5 -2
- package/src/hooks/useQueryData.ts +10 -5
- package/src/hooks/useScheduledReleases.ts +27 -0
- package/src/lib/collectionRows.ts +26 -26
- package/src/lib/colors.ts +3 -6
- package/src/lib/pages.ts +16 -3
- package/src/lib/status.ts +118 -22
- package/src/tools/assets/AssetDetail.tsx +4 -4
- package/src/tools/assets/AssetTable.tsx +3 -3
- package/src/tools/collections/CollectionTable.tsx +53 -30
- package/src/tools/pages/FieldValue.tsx +2 -2
- package/src/tools/pages/PagesTable.tsx +2 -2
- package/src/tools/pages/PagesTool.tsx +25 -2
- package/src/tools/pages/PathCell.tsx +1 -1
- package/src/tools/pages/TagCell.tsx +2 -2
- package/src/tools/pages/board/BoardView.tsx +2 -6
- package/src/tools/pages/board/PageNode.tsx +1 -1
- package/src/tools/pages/board/PagePanel.tsx +2 -2
- package/src/tools/presentation/PagesNavigator.tsx +1 -1
- package/src/ui/ActorName.tsx +1 -1
- package/src/ui/QuietInput.tsx +1 -1
- package/src/ui/StatusBadge.tsx +93 -7
- package/src/ui/StatusFilter.tsx +68 -0
- package/src/ui/formatDate.ts +2 -2
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {deriveCollectionColumns, type CollectionColumn} from '../lib/collectionC
|
|
|
5
5
|
import {buildCollectionQuery} from '../lib/collectionQuery'
|
|
6
6
|
import {buildCollectionRows, type CollectionDoc, type CollectionRow} from '../lib/collectionRows'
|
|
7
7
|
import type {SchemaTypeLike} from '../lib/schemaColumns'
|
|
8
|
+
import {useScheduledReleases} from './useScheduledReleases'
|
|
8
9
|
|
|
9
10
|
export interface CollectionState {
|
|
10
11
|
/** Toutes les colonnes possibles du type (pour le sélecteur). */
|
|
@@ -58,9 +59,11 @@ export function useCollection(
|
|
|
58
59
|
listenTypes: [type],
|
|
59
60
|
})
|
|
60
61
|
|
|
62
|
+
// Publications programmées : statut « Scheduled » et sa date.
|
|
63
|
+
const schedules = useScheduledReleases()
|
|
61
64
|
const rows = useMemo(
|
|
62
|
-
() => buildCollectionRows(data ?? [], visibleColumns),
|
|
63
|
-
[data, visibleColumns],
|
|
65
|
+
() => buildCollectionRows(data ?? [], visibleColumns, schedules),
|
|
66
|
+
[data, visibleColumns, schedules],
|
|
64
67
|
)
|
|
65
68
|
|
|
66
69
|
return {allColumns, visibleColumns, rows, loading, error, refresh}
|
package/src/hooks/usePages.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {buildPagesQuery} from '../lib/query'
|
|
|
5
5
|
import {buildPageRows, type PageDoc, type PageRow} from '../lib/pages'
|
|
6
6
|
import {useQueryData} from './useQueryData'
|
|
7
7
|
import {useRedirectMap} from './useRedirectMap'
|
|
8
|
+
import {useScheduledReleases} from './useScheduledReleases'
|
|
8
9
|
import type {ResolvedDocumentColumn} from '../config/types'
|
|
9
10
|
|
|
10
11
|
export interface PagesState {
|
|
@@ -39,9 +40,11 @@ export function usePages(documentColumns: readonly ResolvedDocumentColumn[] = []
|
|
|
39
40
|
|
|
40
41
|
// Redirections du Studio : l'adresse affichée est l'URL finale.
|
|
41
42
|
const redirects = useRedirectMap(config.redirectType)
|
|
43
|
+
// Publications programmées : statut « Scheduled » et sa date.
|
|
44
|
+
const schedules = useScheduledReleases()
|
|
42
45
|
const rows = useMemo(
|
|
43
|
-
() => (data ? buildPageRows(data, config, columns, redirects) : []),
|
|
44
|
-
[data, config, columns, redirects],
|
|
46
|
+
() => (data ? buildPageRows(data, config, columns, redirects, schedules) : []),
|
|
47
|
+
[data, config, columns, redirects, schedules],
|
|
45
48
|
)
|
|
46
49
|
|
|
47
50
|
return {rows, loading, error, refresh}
|
|
@@ -11,6 +11,11 @@ export interface QueryState<T> {
|
|
|
11
11
|
export interface UseQueryDataOptions {
|
|
12
12
|
/** Types écoutés pour rafraîchir automatiquement. Vide = pas d'écoute. */
|
|
13
13
|
listenTypes?: readonly string[]
|
|
14
|
+
/**
|
|
15
|
+
* Requête d'écoute à la place de `*[_type in $types]`, pour des documents
|
|
16
|
+
* qui ne se repèrent pas par leur type (releases : `_.releases.**`).
|
|
17
|
+
*/
|
|
18
|
+
listenQuery?: string
|
|
14
19
|
/** `false` pour différer la requête (onglet pas encore ouvert). */
|
|
15
20
|
enabled?: boolean
|
|
16
21
|
}
|
|
@@ -28,7 +33,7 @@ export function useQueryData<T>(
|
|
|
28
33
|
options: UseQueryDataOptions = {},
|
|
29
34
|
): QueryState<T> {
|
|
30
35
|
const client = useKitClient()
|
|
31
|
-
const {listenTypes, enabled = true} = options
|
|
36
|
+
const {listenTypes, listenQuery, enabled = true} = options
|
|
32
37
|
|
|
33
38
|
const [data, setData] = useState<T | null>(null)
|
|
34
39
|
const [loading, setLoading] = useState(enabled)
|
|
@@ -74,14 +79,14 @@ export function useQueryData<T>(
|
|
|
74
79
|
const typesKey = (listenTypes ?? []).join(',')
|
|
75
80
|
|
|
76
81
|
useEffect(() => {
|
|
77
|
-
if (!enabled || !typesKey) return undefined
|
|
82
|
+
if (!enabled || (!typesKey && !listenQuery)) return undefined
|
|
78
83
|
|
|
79
|
-
const types = typesKey.split(',')
|
|
84
|
+
const types = typesKey ? typesKey.split(',') : []
|
|
80
85
|
// Fenêtre courte : une publication émet plusieurs événements d'affilée,
|
|
81
86
|
// on ne veut pas relancer la requête à chacun.
|
|
82
87
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
83
88
|
const subscription = client
|
|
84
|
-
.listen('*[_type in $types]', {types}, {visibility: 'query', events: ['mutation']})
|
|
89
|
+
.listen(listenQuery ?? '*[_type in $types]', listenQuery ? {} : {types}, {visibility: 'query', events: ['mutation']})
|
|
85
90
|
.subscribe({
|
|
86
91
|
next: () => {
|
|
87
92
|
if (timer) clearTimeout(timer)
|
|
@@ -97,7 +102,7 @@ export function useQueryData<T>(
|
|
|
97
102
|
if (timer) clearTimeout(timer)
|
|
98
103
|
subscription.unsubscribe()
|
|
99
104
|
}
|
|
100
|
-
}, [client, typesKey, enabled])
|
|
105
|
+
}, [client, typesKey, listenQuery, enabled])
|
|
101
106
|
|
|
102
107
|
return {data, loading, error, refresh}
|
|
103
108
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
import {useQueryData} from './useQueryData'
|
|
3
|
+
import type {ScheduleMap} from '../lib/status'
|
|
4
|
+
|
|
5
|
+
/** Releases programmées (Scheduled drafts et Releases : même mécanisme). */
|
|
6
|
+
export const SCHEDULED_RELEASES_QUERY =
|
|
7
|
+
'*[_id in path("_.releases.**") && state == "scheduled"]{name, "at": coalesce(publishAt, metadata.intendedPublishAt)}'
|
|
8
|
+
|
|
9
|
+
const EMPTY: ScheduleMap = new Map()
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Publications programmées, tenues à jour : nom de la release -> date.
|
|
13
|
+
* Sert à afficher le statut « Scheduled » dans les listes du kit.
|
|
14
|
+
*/
|
|
15
|
+
export function useScheduledReleases(): ScheduleMap {
|
|
16
|
+
const {data} = useQueryData<{name?: string; at?: string}[]>(
|
|
17
|
+
SCHEDULED_RELEASES_QUERY,
|
|
18
|
+
{},
|
|
19
|
+
{listenQuery: '*[_id in path("_.releases.**")]'},
|
|
20
|
+
)
|
|
21
|
+
return useMemo(() => {
|
|
22
|
+
if (!data?.length) return EMPTY
|
|
23
|
+
return new Map(
|
|
24
|
+
data.filter((r): r is {name: string; at: string} => Boolean(r.name && r.at)).map((r) => [r.name, r.at]),
|
|
25
|
+
)
|
|
26
|
+
}, [data])
|
|
27
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {DATA_PREFIX} from './query'
|
|
2
2
|
import type {CollectionColumn} from './collectionColumns'
|
|
3
|
+
import {mergeVersions, type PageStatus, type ScheduleMap} from './status'
|
|
3
4
|
|
|
4
5
|
export type CellValue = string | number | boolean | null
|
|
5
6
|
|
|
@@ -14,8 +15,14 @@ export interface CollectionRow {
|
|
|
14
15
|
/** Id de base (sans `drafts.`), pour ouvrir le document. */
|
|
15
16
|
id: string
|
|
16
17
|
updatedAt: string | null
|
|
17
|
-
/**
|
|
18
|
-
|
|
18
|
+
/** Statut de publication (Draft, Modified, Scheduled, Published). */
|
|
19
|
+
status: PageStatus
|
|
20
|
+
/** Date de publication programmée (statut `scheduled`). */
|
|
21
|
+
scheduledAt?: string | null
|
|
22
|
+
/** Une version publiée existe (l'item est en ligne). */
|
|
23
|
+
live?: boolean
|
|
24
|
+
/** Un brouillon existe (modifications non publiées). */
|
|
25
|
+
hasDraft?: boolean
|
|
19
26
|
cells: Record<string, CollectionCell>
|
|
20
27
|
}
|
|
21
28
|
|
|
@@ -26,8 +33,6 @@ export interface CollectionDoc {
|
|
|
26
33
|
[key: string]: unknown
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
const baseId = (id: string): string => (id.startsWith('drafts.') ? id.slice('drafts.'.length) : id)
|
|
30
|
-
const isDraft = (id: string): boolean => id.startsWith('drafts.')
|
|
31
36
|
|
|
32
37
|
const dateFormatter = new Intl.DateTimeFormat('en-US', {day: '2-digit', month: '2-digit', year: 'numeric'})
|
|
33
38
|
|
|
@@ -57,36 +62,31 @@ function cellOf(raw: unknown, kind: CollectionColumn['kind']): CollectionCell {
|
|
|
57
62
|
|
|
58
63
|
/**
|
|
59
64
|
* Documents → lignes, une par item. Le client (perspective `raw`) renvoie le
|
|
60
|
-
* brouillon
|
|
61
|
-
*
|
|
65
|
+
* brouillon, la version publiée et les versions de release : on les fusionne
|
|
66
|
+
* par id de base (`mergeVersions`, même règle que les pages), en gardant le
|
|
67
|
+
* brouillon s'il existe (valeurs les plus fraîches). Une version de release non
|
|
68
|
+
* programmée ne crée jamais de ligne à part.
|
|
62
69
|
*/
|
|
63
70
|
export function buildCollectionRows(
|
|
64
71
|
docs: readonly CollectionDoc[],
|
|
65
72
|
columns: readonly CollectionColumn[],
|
|
73
|
+
schedules?: ScheduleMap,
|
|
66
74
|
): CollectionRow[] {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const entry = byId.get(baseId(doc._id)) ?? {}
|
|
71
|
-
if (isDraft(doc._id)) entry.draft = doc
|
|
72
|
-
else entry.published = doc
|
|
73
|
-
byId.set(baseId(doc._id), entry)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const rows: CollectionRow[] = []
|
|
77
|
-
for (const [id, {draft, published}] of byId) {
|
|
78
|
-
const source = draft ?? published
|
|
79
|
-
if (!source) continue
|
|
75
|
+
const valid = docs.filter((doc) => Boolean(doc?._id)).map((doc) => ({...doc, _type: '', _updatedAt: doc._updatedAt ?? undefined}))
|
|
76
|
+
return mergeVersions(valid, schedules).map((merged) => {
|
|
77
|
+
const source = merged.doc as unknown as CollectionDoc
|
|
80
78
|
const cells: Record<string, CollectionCell> = {}
|
|
81
79
|
for (const column of columns) {
|
|
82
80
|
cells[column.key] = cellOf(source[`${DATA_PREFIX}${column.key}`], column.kind)
|
|
83
81
|
}
|
|
84
|
-
|
|
85
|
-
id,
|
|
86
|
-
updatedAt:
|
|
87
|
-
|
|
82
|
+
return {
|
|
83
|
+
id: merged.id,
|
|
84
|
+
updatedAt: merged.updatedAt ?? null,
|
|
85
|
+
status: merged.status,
|
|
86
|
+
scheduledAt: merged.scheduledAt ?? null,
|
|
87
|
+
live: merged.live,
|
|
88
|
+
hasDraft: merged.hasDraft,
|
|
88
89
|
cells,
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return rows
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
92
|
}
|
package/src/lib/colors.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type {NcfBoardTag, NcfInternalField} from '../config/types'
|
|
2
2
|
import type {NodeLayout} from './graph'
|
|
3
3
|
import type {PageRow} from './pages'
|
|
4
|
+
import {STATUS_COLORS} from './status'
|
|
4
5
|
|
|
5
6
|
/** Critère qui donne sa couleur à une page. */
|
|
6
7
|
export type ColorBy = 'tag' | 'status' | `field:${string}`
|
|
7
8
|
|
|
8
|
-
/** Couleurs des statuts
|
|
9
|
-
export
|
|
10
|
-
published: '#43d675',
|
|
11
|
-
modified: '#f5a623',
|
|
12
|
-
draft: '#8a8a8a',
|
|
13
|
-
}
|
|
9
|
+
/** Couleurs des statuts : source unique dans `lib/status`. */
|
|
10
|
+
export {STATUS_COLORS}
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
13
|
* Applique une opacité à une couleur hexadécimale.
|
package/src/lib/pages.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {orderByIds} from './pageOrder'
|
|
|
3
3
|
import type {ResolvedDocumentColumn, ResolvedKitConfig} from '../config/types'
|
|
4
4
|
import {pageTypeFor, toPath, toUrl} from './paths'
|
|
5
5
|
import {DATA_PREFIX} from './query'
|
|
6
|
-
import {mergeVersions, type PageStatus, type VersionedDoc} from './status'
|
|
6
|
+
import {mergeVersions, STATUS_ORDER as STATUS_SEQUENCE, type PageStatus, type ScheduleMap, type VersionedDoc} from './status'
|
|
7
7
|
|
|
8
8
|
/** Document tel que le renvoie `buildPagesQuery`. */
|
|
9
9
|
export interface PageDoc extends VersionedDoc {
|
|
@@ -26,6 +26,12 @@ export interface PageRow {
|
|
|
26
26
|
url: string | null
|
|
27
27
|
locale: string | null
|
|
28
28
|
status: PageStatus
|
|
29
|
+
/** Date de publication programmée (statut `scheduled`). */
|
|
30
|
+
scheduledAt?: string | null
|
|
31
|
+
/** Une version publiée existe (l'item est en ligne). */
|
|
32
|
+
live?: boolean
|
|
33
|
+
/** Un brouillon existe (modifications non publiées). */
|
|
34
|
+
hasDraft?: boolean
|
|
29
35
|
updatedAt: string | null
|
|
30
36
|
blockCount: number
|
|
31
37
|
/** Marquée non indexable dans le CMS. */
|
|
@@ -59,8 +65,9 @@ export function buildPageRows(
|
|
|
59
65
|
config: ResolvedKitConfig,
|
|
60
66
|
documentColumns: readonly ResolvedDocumentColumn[] = [],
|
|
61
67
|
redirects: RedirectMap | null = null,
|
|
68
|
+
schedules?: ScheduleMap,
|
|
62
69
|
): PageRow[] {
|
|
63
|
-
return mergeVersions(docs).map((merged) => {
|
|
70
|
+
return mergeVersions(docs, schedules).map((merged) => {
|
|
64
71
|
const doc = merged.doc
|
|
65
72
|
const pageType = pageTypeFor(doc._type, config.pageTypes)
|
|
66
73
|
// URL FINALE (page codée, dossier de la langue, redirection du Studio suivie).
|
|
@@ -74,6 +81,9 @@ export function buildPageRows(
|
|
|
74
81
|
url: toUrl(config.previewUrl, path),
|
|
75
82
|
locale: doc.ncfLocale ?? null,
|
|
76
83
|
status: merged.status,
|
|
84
|
+
scheduledAt: merged.scheduledAt ?? null,
|
|
85
|
+
live: merged.live,
|
|
86
|
+
hasDraft: merged.hasDraft,
|
|
77
87
|
updatedAt: merged.updatedAt ?? null,
|
|
78
88
|
blockCount: doc.ncfBlockCount ?? 0,
|
|
79
89
|
noindex: Boolean(doc.ncfNoindex),
|
|
@@ -110,7 +120,10 @@ export type SortKey =
|
|
|
110
120
|
export type SortDirection = 'asc' | 'desc'
|
|
111
121
|
|
|
112
122
|
/** Ordre d'affichage des statuts : du plus « à traiter » au plus stable. */
|
|
113
|
-
const STATUS_ORDER
|
|
123
|
+
const STATUS_ORDER = Object.fromEntries(STATUS_SEQUENCE.map((status, index) => [status, index])) as Record<
|
|
124
|
+
PageStatus,
|
|
125
|
+
number
|
|
126
|
+
>
|
|
114
127
|
|
|
115
128
|
export interface SortOptions {
|
|
116
129
|
/** Ordre de déclaration des types, pour le tri « structure ». */
|
package/src/lib/status.ts
CHANGED
|
@@ -3,7 +3,17 @@
|
|
|
3
3
|
* release) pour en déduire un statut unique affichable.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export type PageStatus = 'published' | '
|
|
6
|
+
export type PageStatus = 'published' | 'modified' | 'scheduled' | 'draft'
|
|
7
|
+
|
|
8
|
+
/** Ordre d'affichage et de tri : du plus urgent au plus calme. */
|
|
9
|
+
export const STATUS_ORDER: readonly PageStatus[] = ['scheduled', 'modified', 'draft', 'published']
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Publications programmées en cours : nom de la release -> date de publication
|
|
13
|
+
* (ISO). Seules les releases à l'état `scheduled` y figurent (« Scheduled
|
|
14
|
+
* drafts » comme Releases : c'est le même mécanisme dans Sanity).
|
|
15
|
+
*/
|
|
16
|
+
export type ScheduleMap = ReadonlyMap<string, string>
|
|
7
17
|
|
|
8
18
|
export interface VersionedDoc {
|
|
9
19
|
_id: string
|
|
@@ -49,6 +59,12 @@ export interface MergedDoc<T extends VersionedDoc> {
|
|
|
49
59
|
versions: Record<string, T>
|
|
50
60
|
/** Date de la modification la plus récente, toutes variantes confondues. */
|
|
51
61
|
updatedAt?: string
|
|
62
|
+
/** Date de publication programmée la plus proche (statut `scheduled`). */
|
|
63
|
+
scheduledAt?: string
|
|
64
|
+
/** Une version publiée existe : l'item est sur le site. */
|
|
65
|
+
live: boolean
|
|
66
|
+
/** Un brouillon existe (modifications non publiées). */
|
|
67
|
+
hasDraft: boolean
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
const mostRecent = (a?: string, b?: string): string | undefined => {
|
|
@@ -60,14 +76,20 @@ const mostRecent = (a?: string, b?: string): string | undefined => {
|
|
|
60
76
|
/**
|
|
61
77
|
* Regroupe les documents par identifiant de base.
|
|
62
78
|
*
|
|
63
|
-
* -
|
|
64
|
-
* - brouillon seul -> 'draft' (jamais publié, absent du site)
|
|
79
|
+
* - publication programmée -> 'scheduled' (prime sur tout : c'est ce qui va changer)
|
|
65
80
|
* - publié + brouillon -> 'modified' (modifications non publiées)
|
|
81
|
+
* - brouillon seul -> 'draft' (jamais publié ou retiré du site)
|
|
82
|
+
* - publié seul -> 'published'
|
|
66
83
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
84
|
+
* Une version de release ne compte que si sa release est programmée
|
|
85
|
+
* (`schedules`) : une release en préparation n'est ni en ligne ni attendue.
|
|
86
|
+
* Un item qui n'existe QUE dans une release programmée (brouillon programmé,
|
|
87
|
+
* jamais publié) est bien listé, en `scheduled`.
|
|
69
88
|
*/
|
|
70
|
-
export function mergeVersions<T extends VersionedDoc>(
|
|
89
|
+
export function mergeVersions<T extends VersionedDoc>(
|
|
90
|
+
docs: readonly T[],
|
|
91
|
+
schedules: ScheduleMap = new Map(),
|
|
92
|
+
): MergedDoc<T>[] {
|
|
71
93
|
const groups = new Map<string, {published?: T; draft?: T; versions: Record<string, T>}>()
|
|
72
94
|
|
|
73
95
|
for (const doc of docs) {
|
|
@@ -89,15 +111,25 @@ export function mergeVersions<T extends VersionedDoc>(docs: readonly T[]): Merge
|
|
|
89
111
|
const merged: MergedDoc<T>[] = []
|
|
90
112
|
|
|
91
113
|
for (const [id, group] of groups) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
114
|
+
const scheduled = Object.keys(group.versions)
|
|
115
|
+
.map((release) => ({release, at: schedules.get(release)}))
|
|
116
|
+
.filter((entry): entry is {release: string; at: string} => Boolean(entry.at))
|
|
117
|
+
.sort((a, b) => (a.at < b.at ? -1 : a.at > b.at ? 1 : 0))[0]
|
|
118
|
+
|
|
119
|
+
const reference =
|
|
120
|
+
group.draft ?? group.published ?? (scheduled ? group.versions[scheduled.release] : undefined)
|
|
121
|
+
// Une version de release non programmée, seule, n'est pas un item du site.
|
|
122
|
+
if (!reference) continue
|
|
123
|
+
|
|
124
|
+
const status: PageStatus = scheduled
|
|
125
|
+
? 'scheduled'
|
|
126
|
+
: group.published
|
|
127
|
+
? group.draft
|
|
128
|
+
? 'modified'
|
|
129
|
+
: 'published'
|
|
130
|
+
: 'draft'
|
|
131
|
+
|
|
132
|
+
const updatedAt = mostRecent(group.published?._updatedAt, group.draft?._updatedAt) ?? reference._updatedAt
|
|
101
133
|
|
|
102
134
|
merged.push({
|
|
103
135
|
id,
|
|
@@ -106,17 +138,81 @@ export function mergeVersions<T extends VersionedDoc>(docs: readonly T[]): Merge
|
|
|
106
138
|
...(group.published ? {published: group.published} : {}),
|
|
107
139
|
...(group.draft ? {draft: group.draft} : {}),
|
|
108
140
|
versions: group.versions,
|
|
109
|
-
...(
|
|
110
|
-
|
|
111
|
-
|
|
141
|
+
...(updatedAt ? {updatedAt} : {}),
|
|
142
|
+
...(scheduled ? {scheduledAt: scheduled.at} : {}),
|
|
143
|
+
live: Boolean(group.published),
|
|
144
|
+
hasDraft: Boolean(group.draft),
|
|
112
145
|
})
|
|
113
146
|
}
|
|
114
147
|
|
|
115
148
|
return merged
|
|
116
149
|
}
|
|
117
150
|
|
|
118
|
-
export const STATUS_LABELS: Record<
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
151
|
+
export const STATUS_LABELS: Record<
|
|
152
|
+
PageStatus,
|
|
153
|
+
{label: string; tone: 'positive' | 'caution' | 'primary' | 'default'; help: string}
|
|
154
|
+
> = {
|
|
155
|
+
published: {label: 'Published', tone: 'positive', help: 'Live, up to date.'},
|
|
156
|
+
modified: {label: 'Modified', tone: 'caution', help: 'Live, with changes not published yet.'},
|
|
157
|
+
scheduled: {label: 'Scheduled', tone: 'primary', help: 'Publication scheduled: it goes live automatically on the date shown.'},
|
|
158
|
+
draft: {label: 'Draft', tone: 'default', help: 'Not on the site: never published, or removed from the site (content kept in the draft).'},
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Couleur de chaque statut, SOURCE UNIQUE pour le kit (pastilles, filtres,
|
|
163
|
+
* minimap et couleurs du board) : gris, orange, bleu, vert.
|
|
164
|
+
*/
|
|
165
|
+
export const STATUS_COLORS: Record<PageStatus, string> = {
|
|
166
|
+
draft: '#8b93a1',
|
|
167
|
+
modified: '#f08a24',
|
|
168
|
+
scheduled: '#2f7bf5',
|
|
169
|
+
published: '#2fb466',
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Données utiles à l'infobulle d'un statut (toutes facultatives). */
|
|
173
|
+
export interface StatusDetails {
|
|
174
|
+
status: PageStatus
|
|
175
|
+
scheduledAt?: string | null
|
|
176
|
+
live?: boolean
|
|
177
|
+
hasDraft?: boolean
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const scheduleFormat = new Intl.DateTimeFormat(undefined, {
|
|
181
|
+
day: 'numeric',
|
|
182
|
+
month: 'short',
|
|
183
|
+
year: 'numeric',
|
|
184
|
+
hour: '2-digit',
|
|
185
|
+
minute: '2-digit',
|
|
186
|
+
})
|
|
187
|
+
const shortFormat = new Intl.DateTimeFormat(undefined, {day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit'})
|
|
188
|
+
|
|
189
|
+
/** Date de programmation lisible (« 1 Mar 2027, 10:00 », fuseau du navigateur). */
|
|
190
|
+
export function formatSchedule(iso: string | null | undefined, short = false): string {
|
|
191
|
+
if (!iso) return ''
|
|
192
|
+
const date = new Date(iso)
|
|
193
|
+
if (Number.isNaN(date.getTime())) return ''
|
|
194
|
+
return (short ? shortFormat : scheduleFormat).format(date)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Lignes de l'infobulle : ce qu'est le statut, puis ce qu'il faut savoir en plus. */
|
|
198
|
+
export function statusHelp(details: StatusDetails): string[] {
|
|
199
|
+
const {status, scheduledAt, live, hasDraft} = details
|
|
200
|
+
if (status === 'scheduled') {
|
|
201
|
+
const lines = [
|
|
202
|
+
live
|
|
203
|
+
? 'Currently live: this update goes live automatically on the date shown.'
|
|
204
|
+
: 'Not on the site yet: it goes live automatically on the date shown.',
|
|
205
|
+
]
|
|
206
|
+
if (hasDraft) lines.push('Also has other changes not scheduled (draft).')
|
|
207
|
+
lines.push('Change the date in Scheduled drafts / Releases.')
|
|
208
|
+
return scheduledAt ? [`Scheduled for ${formatSchedule(scheduledAt)}.`, ...lines] : lines
|
|
209
|
+
}
|
|
210
|
+
return [STATUS_LABELS[status].help]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Nombre d'items par statut (filtres). */
|
|
214
|
+
export function countStatuses(rows: readonly {status: PageStatus}[]): Record<PageStatus, number> {
|
|
215
|
+
const counts: Record<PageStatus, number> = {published: 0, modified: 0, scheduled: 0, draft: 0}
|
|
216
|
+
for (const row of rows) counts[row.status] += 1
|
|
217
|
+
return counts
|
|
122
218
|
}
|
|
@@ -109,7 +109,7 @@ export function AssetDetail(props: AssetDetailProps) {
|
|
|
109
109
|
) : (
|
|
110
110
|
<Flex align="center" justify="center" padding={5}>
|
|
111
111
|
<Text size={1} muted>
|
|
112
|
-
{asset.extension?.toUpperCase() || 'Fichier'}
|
|
112
|
+
{asset.extension?.toUpperCase() || 'Fichier'} (pas d'aperçu)
|
|
113
113
|
</Text>
|
|
114
114
|
</Flex>
|
|
115
115
|
)}
|
|
@@ -168,11 +168,11 @@ export function AssetDetail(props: AssetDetailProps) {
|
|
|
168
168
|
</Stack>
|
|
169
169
|
|
|
170
170
|
<Grid gridTemplateColumns={[1, 2]} gap={3}>
|
|
171
|
-
<Metric label="Fichier" value={asset.originalFilename ?? '
|
|
171
|
+
<Metric label="Fichier" value={asset.originalFilename ?? 'None'} />
|
|
172
172
|
<Metric label="Type" value={asset.extension?.toUpperCase() || asset._type.replace('sanity.', '')} />
|
|
173
173
|
<Metric label="Taille" value={formatBytes(asset.size)} />
|
|
174
|
-
<Metric label="Dimensions" value={asset.dimensions?.width ? `${asset.dimensions.width}×${asset.dimensions.height}` : '
|
|
175
|
-
<Metric label="Usage" value={asset.uses === undefined ? '
|
|
174
|
+
<Metric label="Dimensions" value={asset.dimensions?.width ? `${asset.dimensions.width}×${asset.dimensions.height}` : 'Unknown'} />
|
|
175
|
+
<Metric label="Usage" value={asset.uses === undefined ? 'Unknown' : `${asset.uses}`} />
|
|
176
176
|
<Metric label="Ajouté" value={formatDate(asset._createdAt)} />
|
|
177
177
|
</Grid>
|
|
178
178
|
|
|
@@ -88,12 +88,12 @@ export function AssetTable(props: AssetTableProps) {
|
|
|
88
88
|
</td>
|
|
89
89
|
<td style={{padding: '6px 10px', textAlign: 'right', whiteSpace: 'nowrap'}}>
|
|
90
90
|
<Text size={1} muted style={TABULAR}>
|
|
91
|
-
{asset.dimensions?.width ? `${asset.dimensions.width}×${asset.dimensions.height}` : '
|
|
91
|
+
{asset.dimensions?.width ? `${asset.dimensions.width}×${asset.dimensions.height}` : ''}
|
|
92
92
|
</Text>
|
|
93
93
|
</td>
|
|
94
94
|
<td style={{padding: '6px 10px', whiteSpace: 'nowrap'}}>
|
|
95
95
|
<Text size={1} muted textOverflow="ellipsis">
|
|
96
|
-
{folder ? folderName(folder) : '
|
|
96
|
+
{folder ? folderName(folder) : ''}
|
|
97
97
|
</Text>
|
|
98
98
|
</td>
|
|
99
99
|
<td style={{padding: '6px 10px', textAlign: 'right', whiteSpace: 'nowrap'}}>
|
|
@@ -103,7 +103,7 @@ export function AssetTable(props: AssetTableProps) {
|
|
|
103
103
|
</Badge>
|
|
104
104
|
) : (
|
|
105
105
|
<Text size={1} style={TABULAR}>
|
|
106
|
-
{asset.uses ?? '
|
|
106
|
+
{asset.uses ?? ''}
|
|
107
107
|
</Text>
|
|
108
108
|
)}
|
|
109
109
|
</td>
|