@bison-lab/payload-core 4.12.0 → 4.12.2
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 +8 -2
- package/dist/admin.d.mts +6 -0
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +138 -37
- package/dist/admin.mjs.map +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -12,8 +12,9 @@ pnpm add @bison-lab/payload-core @payloadcms/plugin-seo @payloadcms/plugin-redir
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Peers: `payload`, `@payloadcms/plugin-seo`, and `@payloadcms/plugin-redirects` are required. `@bison-lab/tokens`
|
|
15
|
-
and `@bison-lab/fonts` are required because Theme is required. `@payloadcms/ui
|
|
16
|
-
and `react` are needed for admin fields
|
|
15
|
+
and `@bison-lab/fonts` are required because Theme is required. `@payloadcms/ui`,
|
|
16
|
+
`next` and `react` are needed for admin fields (`./admin` refreshes the
|
|
17
|
+
Media list with `next/navigation`, which Payload's admin already loads); `@bison-lab/ui` and
|
|
17
18
|
`@payloadcms/live-preview-react` are peers of the legacy `./react` entry.
|
|
18
19
|
Pin the plugin to the same version as `payload`; Payload releases them in
|
|
19
20
|
lockstep.
|
|
@@ -351,6 +352,11 @@ Turning a card off distinguishes published from draft:
|
|
|
351
352
|
transaction. Published versions are never written. Cancel leaves it on.
|
|
352
353
|
- **Unused** — off, no dialog.
|
|
353
354
|
|
|
355
|
+
Save leaves the form clean: the field reads each row from Payload's own
|
|
356
|
+
row fields and writes one column at a time, never the array path and never
|
|
357
|
+
on load, so after a Save the button disables again, leaving the page asks
|
|
358
|
+
nothing, and a switch flipped straight after a Save holds (BIS-135).
|
|
359
|
+
|
|
354
360
|
The server is the authority: the Save hook re-reads usage, refuses while
|
|
355
361
|
anything published holds the slug, and strips drafts otherwise, whether
|
|
356
362
|
the Save came from the admin or the API. The admin asks
|
package/dist/admin.d.mts
CHANGED
|
@@ -198,6 +198,12 @@ declare const FeaturesMatrixField: ArrayFieldClientComponent;
|
|
|
198
198
|
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
199
199
|
* while a published document holds it, and asks before a Save that strips
|
|
200
200
|
* it from drafts.
|
|
201
|
+
*
|
|
202
|
+
* Form contract (BIS-135): rows are read from Payload's per-row fields and
|
|
203
|
+
* written one column at a time. The field never writes the array path and
|
|
204
|
+
* never marks the form modified on its own; a catalogue entry the stored
|
|
205
|
+
* rows lack is added to local form state without that mark. So a Save
|
|
206
|
+
* leaves the form clean and the server's post-Save state is what shows.
|
|
201
207
|
*/
|
|
202
208
|
declare const BlockLibraryField: ArrayFieldClientComponent;
|
|
203
209
|
//#endregion
|
package/dist/admin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.d.mts","names":[],"sources":["../src/admin/color-field.tsx","../src/admin/color-scale-field.tsx","../src/admin/library-field.tsx","../src/admin/font-field.tsx","../src/admin/pairing-field.tsx","../src/admin/appearance-field.tsx","../src/admin/grey-scale-field.tsx","../src/admin/contrast-report.tsx","../src/admin/section-heading.tsx","../src/admin/publish-child.tsx","../src/admin/save-button.tsx","../src/admin/preview-mode.tsx","../src/admin/identity-fallback.tsx","../src/admin/look-field.tsx","../src/admin/roles-matrix-field.tsx","../src/admin/roles-row-label.tsx","../src/admin/role-slug-field.tsx","../src/admin/slug-field.tsx","../src/admin/page-title-cell.tsx","../src/admin/page-slug-cell.tsx","../src/admin/required-page-cell.tsx","../src/admin/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-field.tsx","../src/admin/block-library-field.tsx","../src/admin/document-title-actions.tsx","../src/admin/list-align-styles.tsx","../src/admin/document-create-new.tsx","../src/admin-nav/types.ts","../src/admin/admin-nav.tsx","../src/admin/admin-nav-row-label.tsx","../src/admin/admin-nav-item-row-label.tsx","../src/admin/admin-nav-entity-field.tsx","../src/taxonomy/facet-field.ts","../src/questions/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AA,EAAe,wBAAA;;;;;;;;cC8Cf,UAAA,EAAY,0BAAA;;;;;;;;cCpBZ,gBAAA,EAAkB,wBAAA;;;;;;;;;AvBxB/B;;cwB2Ca,mBAAA,EAAqB,yBAAA;;;;;;;;;AxB3ClC
|
|
1
|
+
{"version":3,"file":"admin.d.mts","names":[],"sources":["../src/admin/color-field.tsx","../src/admin/color-scale-field.tsx","../src/admin/library-field.tsx","../src/admin/font-field.tsx","../src/admin/pairing-field.tsx","../src/admin/appearance-field.tsx","../src/admin/grey-scale-field.tsx","../src/admin/contrast-report.tsx","../src/admin/section-heading.tsx","../src/admin/publish-child.tsx","../src/admin/save-button.tsx","../src/admin/preview-mode.tsx","../src/admin/identity-fallback.tsx","../src/admin/look-field.tsx","../src/admin/roles-matrix-field.tsx","../src/admin/roles-row-label.tsx","../src/admin/role-slug-field.tsx","../src/admin/slug-field.tsx","../src/admin/page-title-cell.tsx","../src/admin/page-slug-cell.tsx","../src/admin/required-page-cell.tsx","../src/admin/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-field.tsx","../src/admin/block-library-field.tsx","../src/admin/document-title-actions.tsx","../src/admin/list-align-styles.tsx","../src/admin/document-create-new.tsx","../src/admin-nav/types.ts","../src/admin/admin-nav.tsx","../src/admin/admin-nav-row-label.tsx","../src/admin/admin-nav-item-row-label.tsx","../src/admin/admin-nav-entity-field.tsx","../src/taxonomy/facet-field.ts","../src/questions/types.ts","../src/admin/questions-list.tsx","../src/admin/media-alt-autofill.tsx","../src/admin/media-list-view.tsx"],"mappings":";;;;;;;;;;;cAWa,UAAA,EAAY,wBAAA;;;;;;;;cCuBZ,eAAA,EAAiB,yBAAA;;;;;;;;;cCMjB,YAAA,EAAc,yBAAA;;;;;;;;;cCtBd,SAAA,EAAW,0BAAA;;;;;;;cCNX,YAAA,EAAc,sBAAA;;;;;;;cCCd,eAAA,EAAiB,yBAAA;;;ALF9B;;;;AAAA,cM4Da,cAAA,E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KEYS, n as pageEditorLooks, r as pageEditorTokens, s as stateFromColorDoc } from "./looks-BbL309kO.mjs";
|
|
3
|
-
import { ArrayField, Button, CheckboxInput, DefaultCell, FieldDescription, FieldError, FieldLabel, Link, Logout, NavGroup, NavToggler, SelectField, fieldBaseClass, useAuth, useBulkUpload, useConfig, useEntityVisibility, useField, useForm, useFormFields, useListDrawerContext, useListQuery, useModal, useNav, useRowLabel, useStepNav } from "@payloadcms/ui";
|
|
3
|
+
import { ArrayField, Button, CheckboxInput, DefaultCell, FieldDescription, FieldError, FieldLabel, Link, Logout, NavGroup, NavToggler, SelectField, fieldBaseClass, useAllFormFields, useAuth, useBulkUpload, useConfig, useEntityVisibility, useField, useForm, useFormFields, useListDrawerContext, useListQuery, useModal, useNav, useRowLabel, useStepNav } from "@payloadcms/ui";
|
|
4
4
|
import { GREY_SCALES, SHADE_STEPS, contrastForeground, contrastRatio, createColorScale, deriveDarkPalette, deriveLightPalette, hexToHSL, hslToString, includedShadeSteps, isThemeHex, presetHints, regenerateColorScale, setColorScaleInclude, updateColorScale } from "@bison-lab/tokens";
|
|
5
5
|
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -10,6 +10,7 @@ import { createPortal } from "react-dom";
|
|
|
10
10
|
import { findFont, fontFaceCss, isFontId } from "@bison-lab/fonts";
|
|
11
11
|
import "payload";
|
|
12
12
|
import { RenderLexical } from "@payloadcms/richtext-lexical/client";
|
|
13
|
+
import { useRouter } from "next/navigation";
|
|
13
14
|
import { formatAdminURL, formatFilesize } from "payload/shared";
|
|
14
15
|
//#region src/admin/color-field.tsx
|
|
15
16
|
const HEX_ERROR = "Enter a six-digit hex colour like #1e3a5f";
|
|
@@ -3928,7 +3929,7 @@ function isUsage(value) {
|
|
|
3928
3929
|
* publish without its hero). A disabled block keeps its ticks; they matter
|
|
3929
3930
|
* again when it is re-enabled.
|
|
3930
3931
|
*/
|
|
3931
|
-
function SectionControlTicks({ row,
|
|
3932
|
+
function SectionControlTicks({ row, write }) {
|
|
3932
3933
|
if (row.kind === "navbar") return null;
|
|
3933
3934
|
const controls = sectionControlsOf(row.sectionControls, defaultSectionControls(row.kind));
|
|
3934
3935
|
const locked = (key) => key === "hidden" && row.kind === "hero";
|
|
@@ -3943,12 +3944,9 @@ function SectionControlTicks({ row, onChange }) {
|
|
|
3943
3944
|
...locked(key) ? { "data-locked": "" } : {},
|
|
3944
3945
|
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
3945
3946
|
checked: locked(key) ? false : controls[key],
|
|
3946
|
-
disabled: locked(key),
|
|
3947
|
+
disabled: locked(key) || !write,
|
|
3947
3948
|
"aria-label": SECTION_CONTROL_LABELS[key],
|
|
3948
|
-
onCheckedChange: (checked) =>
|
|
3949
|
-
...controls,
|
|
3950
|
-
[key]: checked === true
|
|
3951
|
-
})
|
|
3949
|
+
onCheckedChange: (checked) => write?.(`sectionControls.${key}`, checked === true)
|
|
3952
3950
|
}), /* @__PURE__ */ jsx("span", {
|
|
3953
3951
|
"aria-hidden": true,
|
|
3954
3952
|
children: SECTION_CONTROL_LABELS[key]
|
|
@@ -3956,15 +3954,11 @@ function SectionControlTicks({ row, onChange }) {
|
|
|
3956
3954
|
}, key))]
|
|
3957
3955
|
});
|
|
3958
3956
|
}
|
|
3959
|
-
function LibraryCard({
|
|
3960
|
-
const { setValue: setEnabled } = useField({ path: `${path}.${index}.enabled` });
|
|
3957
|
+
function LibraryCard({ row, write, src, toggle, usageURL }) {
|
|
3961
3958
|
const [refusal, setRefusal] = useState(null);
|
|
3962
3959
|
const [drafts, setDrafts] = useState(null);
|
|
3963
3960
|
const [checking, setChecking] = useState(false);
|
|
3964
|
-
const apply = (enabled) =>
|
|
3965
|
-
setEnabled(enabled);
|
|
3966
|
-
setRow(index, { enabled });
|
|
3967
|
-
};
|
|
3961
|
+
const apply = (enabled) => write?.("enabled", enabled);
|
|
3968
3962
|
/**
|
|
3969
3963
|
* Off asks the server where the slug is used. Published refuses; drafts
|
|
3970
3964
|
* only ask first, because the Save that turns it off deletes those rows.
|
|
@@ -3990,7 +3984,7 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
3990
3984
|
children: [
|
|
3991
3985
|
/* @__PURE__ */ jsxs("header", { children: [/* @__PURE__ */ jsx("span", { children: row.label }), toggle ? /* @__PURE__ */ jsx(Switch, {
|
|
3992
3986
|
checked: row.enabled !== false,
|
|
3993
|
-
disabled: checking,
|
|
3987
|
+
disabled: checking || !write,
|
|
3994
3988
|
"aria-label": `Enable ${row.label}`,
|
|
3995
3989
|
onCheckedChange: (enabled) => {
|
|
3996
3990
|
if (enabled) {
|
|
@@ -4001,7 +3995,7 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
4001
3995
|
}) : null] }),
|
|
4002
3996
|
/* @__PURE__ */ jsx(SectionControlTicks, {
|
|
4003
3997
|
row,
|
|
4004
|
-
|
|
3998
|
+
write
|
|
4005
3999
|
}),
|
|
4006
4000
|
refusal ? /* @__PURE__ */ jsx("p", {
|
|
4007
4001
|
className: "bl-block-library__refusal",
|
|
@@ -4035,6 +4029,30 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
4035
4029
|
]
|
|
4036
4030
|
});
|
|
4037
4031
|
}
|
|
4032
|
+
function rowState(row) {
|
|
4033
|
+
const state = {};
|
|
4034
|
+
const put = (key, value) => {
|
|
4035
|
+
state[key] = {
|
|
4036
|
+
value,
|
|
4037
|
+
initialValue: value,
|
|
4038
|
+
valid: true
|
|
4039
|
+
};
|
|
4040
|
+
};
|
|
4041
|
+
put("id", row.id);
|
|
4042
|
+
put("slug", row.slug);
|
|
4043
|
+
put("label", row.label);
|
|
4044
|
+
put("category", row.category);
|
|
4045
|
+
put("enabled", row.enabled);
|
|
4046
|
+
put("kind", row.kind);
|
|
4047
|
+
for (const key of SECTION_CONTROL_KEYS) put(`sectionControls.${key}`, row.sectionControls[key]);
|
|
4048
|
+
return state;
|
|
4049
|
+
}
|
|
4050
|
+
/** The form index of the row holding `slug`, read off the fields as they are now. */
|
|
4051
|
+
function indexOfSlug(fields, path, slug) {
|
|
4052
|
+
const count = rowCount(fields, path);
|
|
4053
|
+
for (let i = 0; i < count; i += 1) if (fields[`${path}.${i}.slug`]?.value === slug) return i;
|
|
4054
|
+
return -1;
|
|
4055
|
+
}
|
|
4038
4056
|
function asRows(value) {
|
|
4039
4057
|
return Array.isArray(value) ? value : [];
|
|
4040
4058
|
}
|
|
@@ -4049,40 +4067,124 @@ function previewsOf(field) {
|
|
|
4049
4067
|
function seededRows(field) {
|
|
4050
4068
|
return asRows(customOf(field).rows);
|
|
4051
4069
|
}
|
|
4070
|
+
function isKind(value) {
|
|
4071
|
+
return value === "hero" || value === "section" || value === "navbar";
|
|
4072
|
+
}
|
|
4073
|
+
/**
|
|
4074
|
+
* How many rows the form holds. Payload keeps an array field's *count* at
|
|
4075
|
+
* its path (`blocks.value`), never the rows; each row's columns sit at
|
|
4076
|
+
* `blocks.<i>.<name>`. The count is read off `rows` when present, so a row
|
|
4077
|
+
* added client-side counts too.
|
|
4078
|
+
*/
|
|
4079
|
+
function rowCount(fields, path) {
|
|
4080
|
+
const field = fields[path];
|
|
4081
|
+
if (Array.isArray(field?.rows)) return field.rows.length;
|
|
4082
|
+
return typeof field?.value === "number" ? field.value : 0;
|
|
4083
|
+
}
|
|
4084
|
+
/**
|
|
4085
|
+
* The rows as the form holds them, read column by column. A column a
|
|
4086
|
+
* stored row lacks (the ticks, before the migration that added them)
|
|
4087
|
+
* takes the catalogue's seeded value for that slug. Reading never writes:
|
|
4088
|
+
* the stored values stand until an editor changes one.
|
|
4089
|
+
*/
|
|
4090
|
+
function rowsFromFields(fields, path, seeded) {
|
|
4091
|
+
const count = rowCount(fields, path);
|
|
4092
|
+
const rows = [];
|
|
4093
|
+
for (let i = 0; i < count; i += 1) {
|
|
4094
|
+
const read = (name) => fields[`${path}.${i}.${name}`]?.value;
|
|
4095
|
+
const slug = read("slug");
|
|
4096
|
+
if (typeof slug !== "string" || !slug) continue;
|
|
4097
|
+
const seed = seeded.find((entry) => entry.slug === slug);
|
|
4098
|
+
const kind = read("kind");
|
|
4099
|
+
const resolvedKind = isKind(kind) ? kind : seed?.kind ?? "section";
|
|
4100
|
+
const ticks = {};
|
|
4101
|
+
for (const key of SECTION_CONTROL_KEYS) ticks[key] = read(`sectionControls.${key}`);
|
|
4102
|
+
const label = read("label");
|
|
4103
|
+
const category = read("category");
|
|
4104
|
+
const enabled = read("enabled");
|
|
4105
|
+
const id = read("id");
|
|
4106
|
+
rows.push({
|
|
4107
|
+
id: typeof id === "string" ? id : slug,
|
|
4108
|
+
slug,
|
|
4109
|
+
label: typeof label === "string" ? label : seed?.label ?? slug,
|
|
4110
|
+
category: typeof category === "string" ? category : seed?.category ?? "content",
|
|
4111
|
+
enabled: typeof enabled === "boolean" ? enabled : true,
|
|
4112
|
+
kind: resolvedKind,
|
|
4113
|
+
sectionControls: sectionControlsOf(ticks, seed?.sectionControls ?? defaultSectionControls(resolvedKind))
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
return rows;
|
|
4117
|
+
}
|
|
4052
4118
|
/**
|
|
4053
4119
|
* Category rail and a gallery of live islands. Each island is the sample
|
|
4054
4120
|
* at `previewPath(slug)` under the published theme (the route is SPI-53).
|
|
4055
4121
|
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
4056
4122
|
* while a published document holds it, and asks before a Save that strips
|
|
4057
4123
|
* it from drafts.
|
|
4124
|
+
*
|
|
4125
|
+
* Form contract (BIS-135): rows are read from Payload's per-row fields and
|
|
4126
|
+
* written one column at a time. The field never writes the array path and
|
|
4127
|
+
* never marks the form modified on its own; a catalogue entry the stored
|
|
4128
|
+
* rows lack is added to local form state without that mark. So a Save
|
|
4129
|
+
* leaves the form clean and the server's post-Save state is what shows.
|
|
4058
4130
|
*/
|
|
4059
4131
|
const BlockLibraryField = (props) => {
|
|
4060
|
-
const
|
|
4132
|
+
const [fields, dispatch] = useAllFormFields();
|
|
4133
|
+
const { setModified } = useForm();
|
|
4061
4134
|
const { config } = useConfig();
|
|
4062
4135
|
const usageURL = `${config.serverURL ?? ""}${config.routes?.api ?? "/api"}/globals/${BLOCK_LIBRARY_SLUG}/usage`;
|
|
4063
|
-
const loaded = asRows(value);
|
|
4064
4136
|
const seeded = seededRows(props.field);
|
|
4065
|
-
const
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4137
|
+
const loaded = useMemo(() => rowsFromFields(fields, props.path, seeded), [
|
|
4138
|
+
fields,
|
|
4139
|
+
props.path,
|
|
4140
|
+
seeded
|
|
4141
|
+
]);
|
|
4142
|
+
const fieldsRef = useRef(fields);
|
|
4143
|
+
fieldsRef.current = fields;
|
|
4144
|
+
const missing = useMemo(() => seeded.filter((entry) => !loaded.some((row) => row.slug === entry.slug)), [loaded, seeded]);
|
|
4145
|
+
const added = useRef(null);
|
|
4072
4146
|
useEffect(() => {
|
|
4073
|
-
if (
|
|
4147
|
+
if (missing.length === 0) return;
|
|
4148
|
+
const current = fields;
|
|
4149
|
+
const asked = added.current?.fields === current ? added.current.slugs : /* @__PURE__ */ new Set();
|
|
4150
|
+
for (const entry of missing) {
|
|
4151
|
+
if (asked.has(entry.slug)) continue;
|
|
4152
|
+
asked.add(entry.slug);
|
|
4153
|
+
dispatch({
|
|
4154
|
+
type: "ADD_ROW",
|
|
4155
|
+
path: props.path,
|
|
4156
|
+
subFieldState: rowState(entry)
|
|
4157
|
+
});
|
|
4158
|
+
}
|
|
4159
|
+
added.current = {
|
|
4160
|
+
fields: current,
|
|
4161
|
+
slugs: asked
|
|
4162
|
+
};
|
|
4074
4163
|
}, [
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4164
|
+
dispatch,
|
|
4165
|
+
fields,
|
|
4166
|
+
missing,
|
|
4167
|
+
props.path
|
|
4078
4168
|
]);
|
|
4169
|
+
const writeRow = useCallback((slug) => (column, value) => {
|
|
4170
|
+
const index = indexOfSlug(fieldsRef.current, props.path, slug);
|
|
4171
|
+
if (index < 0) return;
|
|
4172
|
+
dispatch({
|
|
4173
|
+
type: "UPDATE",
|
|
4174
|
+
path: `${props.path}.${index}.${column}`,
|
|
4175
|
+
value
|
|
4176
|
+
});
|
|
4177
|
+
setModified(true);
|
|
4178
|
+
}, [
|
|
4179
|
+
dispatch,
|
|
4180
|
+
props.path,
|
|
4181
|
+
setModified
|
|
4182
|
+
]);
|
|
4183
|
+
const rows = [...loaded, ...missing];
|
|
4079
4184
|
const previews = previewsOf(props.field);
|
|
4080
4185
|
const [category, setCategory] = useState("hero");
|
|
4081
4186
|
const navbarCount = rows.filter((row) => row.kind === "navbar").length;
|
|
4082
|
-
const visible = rows.
|
|
4083
|
-
row,
|
|
4084
|
-
index
|
|
4085
|
-
})).filter(({ row }) => row.category === category);
|
|
4187
|
+
const visible = rows.filter((row) => row.category === category);
|
|
4086
4188
|
return /* @__PURE__ */ jsx(KitProvider, { children: /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsxs("div", {
|
|
4087
4189
|
className: "bl-block-library",
|
|
4088
4190
|
children: [
|
|
@@ -4102,11 +4204,9 @@ const BlockLibraryField = (props) => {
|
|
|
4102
4204
|
children: entry.label
|
|
4103
4205
|
}, entry.id))
|
|
4104
4206
|
}),
|
|
4105
|
-
/* @__PURE__ */ jsx("div", { children: visible.map((
|
|
4106
|
-
path: props.path,
|
|
4107
|
-
index,
|
|
4207
|
+
/* @__PURE__ */ jsx("div", { children: visible.map((row) => /* @__PURE__ */ jsx(LibraryCard, {
|
|
4108
4208
|
row,
|
|
4109
|
-
|
|
4209
|
+
write: loaded.some((entry) => entry.slug === row.slug) ? writeRow(row.slug) : null,
|
|
4110
4210
|
src: previews[row.slug] ?? "",
|
|
4111
4211
|
toggle: row.kind !== "navbar" || navbarCount > 1,
|
|
4112
4212
|
usageURL
|
|
@@ -5689,6 +5789,7 @@ function MediaListPage({ collectionSlug, enableRowSelections, hasCreatePermissio
|
|
|
5689
5789
|
const { drawerSlug, setCollectionSlug, setOnSuccess } = useBulkUpload();
|
|
5690
5790
|
const { config: { routes: { admin: adminRoute, api }, serverURL }, getEntityConfig } = useConfig();
|
|
5691
5791
|
const { data, query, handleSearchChange, handlePageChange, handlePerPageChange, handleSortChange, handleWhereChange, refineListData } = useListQuery();
|
|
5792
|
+
const router = useRouter();
|
|
5692
5793
|
const collectionConfig = getEntityConfig({ collectionSlug });
|
|
5693
5794
|
const inUseEnabled = mediaInUseEnabled(collectionConfig);
|
|
5694
5795
|
const canDelete = hasDeletePermission !== false;
|
|
@@ -5905,7 +6006,7 @@ function MediaListPage({ collectionSlug, enableRowSelections, hasCreatePermissio
|
|
|
5905
6006
|
method: "DELETE",
|
|
5906
6007
|
credentials: "include"
|
|
5907
6008
|
})).ok) failed.push(String(id));
|
|
5908
|
-
|
|
6009
|
+
router.refresh();
|
|
5909
6010
|
if (failed.length > 0) {
|
|
5910
6011
|
setSelected(new Set(failed));
|
|
5911
6012
|
setSelectedLabels((current) => new Map([...current].filter(([id]) => failed.includes(id))));
|