@mattisvensson/strapi-plugin-webatlas 0.11.5 → 0.11.7

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.
@@ -1,244 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
5
- const index = require("./index-Bm8lkiNL.js");
6
- const admin = require("@strapi/strapi/admin");
7
- const designSystem = require("@strapi/design-system");
8
- require("@strapi/icons/symbols");
9
- const FullLoader = require("./FullLoader-Da2n70bJ.js");
10
- const reactIntl = require("react-intl");
11
- const reactRouterDom = require("react-router-dom");
12
- const icons = require("@strapi/icons");
13
- function PageWrapper({ children }) {
14
- const { formatMessage } = reactIntl.useIntl();
15
- return /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
16
- /* @__PURE__ */ jsxRuntime.jsx(
17
- admin.Layouts.Header,
18
- {
19
- title: formatMessage({
20
- id: index.getTranslation("paths.page.title"),
21
- defaultMessage: "Paths"
22
- }),
23
- subtitle: formatMessage({
24
- id: index.getTranslation("paths.page.subtitle"),
25
- defaultMessage: "Overview of all existing paths"
26
- })
27
- }
28
- ),
29
- /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }) })
30
- ] });
31
- }
32
- function compareBy(field, direction) {
33
- if (!field) {
34
- return () => 0;
35
- }
36
- if (field === "type") {
37
- return (a, b) => {
38
- return direction === "asc" ? a.type.localeCompare(b.type) : b.type.localeCompare(a.type);
39
- };
40
- }
41
- return (a, b) => {
42
- const aValue = a[field];
43
- const bValue = b[field];
44
- if (aValue == null && bValue == null) {
45
- return 0;
46
- }
47
- if (aValue == null) {
48
- return direction === "asc" ? 1 : -1;
49
- }
50
- if (bValue == null) {
51
- return direction === "asc" ? -1 : 1;
52
- }
53
- if (typeof aValue === "string" && typeof bValue === "string") {
54
- return direction === "asc" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
55
- }
56
- return 0;
57
- };
58
- }
59
- function SearchInput({
60
- searchQuery,
61
- handleSearchChange
62
- }) {
63
- const { formatMessage } = reactIntl.useIntl();
64
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Root, { style: { marginBottom: "16px" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { width: "100%", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Root, { children: /* @__PURE__ */ jsxRuntime.jsx(
65
- designSystem.Field.Input,
66
- {
67
- name: "search",
68
- placeholder: formatMessage({
69
- id: index.getTranslation("paths.page.searchPlaceholder"),
70
- defaultMessage: "Search paths"
71
- }),
72
- value: searchQuery,
73
- onChange: handleSearchChange,
74
- endAction: searchQuery ? /* @__PURE__ */ jsxRuntime.jsx(
75
- "button",
76
- {
77
- type: "button",
78
- onClick: () => handleSearchChange({
79
- target: { value: "" }
80
- }),
81
- style: {
82
- color: "inherit",
83
- background: "none",
84
- border: "none",
85
- cursor: "pointer"
86
- },
87
- "aria-label": "Clear search",
88
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {})
89
- }
90
- ) : null
91
- }
92
- ) }) }) }) });
93
- }
94
- function TableHeader({
95
- sortKey,
96
- handleSort
97
- }) {
98
- const { formatMessage } = reactIntl.useIntl();
99
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
100
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Th, { onClick: () => handleSort("title"), cursor: "pointer", children: [
101
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: formatMessage({
102
- id: index.getTranslation("title"),
103
- defaultMessage: "Title"
104
- }) }),
105
- sortKey === "title" && /* @__PURE__ */ jsxRuntime.jsx(icons.ChevronDown, {})
106
- ] }),
107
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Th, { onClick: () => handleSort("canonicalPath"), cursor: "pointer", children: [
108
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: formatMessage({
109
- id: index.getTranslation("canonicalPath"),
110
- defaultMessage: "Canonical Path"
111
- }) }),
112
- sortKey === "canonicalPath" && /* @__PURE__ */ jsxRuntime.jsx(icons.ChevronDown, {})
113
- ] }),
114
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Th, { onClick: () => handleSort("path"), cursor: "pointer", children: [
115
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: formatMessage({
116
- id: index.getTranslation("path"),
117
- defaultMessage: "Path"
118
- }) }),
119
- sortKey === "path" && /* @__PURE__ */ jsxRuntime.jsx(icons.ChevronDown, {})
120
- ] }),
121
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Th, { onClick: () => handleSort("type"), cursor: "pointer", children: [
122
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: formatMessage({
123
- id: index.getTranslation("paths.page.column.type"),
124
- defaultMessage: "Type"
125
- }) }),
126
- sortKey === "type" && /* @__PURE__ */ jsxRuntime.jsx(icons.ChevronDown, {})
127
- ] }),
128
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: formatMessage({
129
- id: index.getTranslation("actions"),
130
- defaultMessage: "Actions"
131
- }) }) })
132
- ] }) });
133
- }
134
- function TableRow({ route }) {
135
- const { formatMessage } = reactIntl.useIntl();
136
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
137
- [route.title, route.canonicalPath, route.path].map((field, index2) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { title: field, textColor: "neutral800", children: field || "-" }) }, index2)),
138
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { title: route.type, textColor: "neutral800", children: formatMessage({
139
- id: index.getTranslation(`path.type.${route.type}`),
140
- defaultMessage: "-"
141
- }) }) }),
142
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, justifyContent: "end", children: route.type === "internal" && /* @__PURE__ */ jsxRuntime.jsx(
143
- designSystem.LinkButton,
144
- {
145
- variant: "secondary",
146
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {}),
147
- href: `/admin/content-manager/collection-types/${route.relatedContentType}/${route.relatedDocumentId}`,
148
- children: formatMessage({
149
- id: index.getTranslation("edit"),
150
- defaultMessage: "Edit"
151
- })
152
- }
153
- ) }) })
154
- ] });
155
- }
156
- function PathTable({
157
- routes,
158
- sortKey,
159
- handleSort
160
- }) {
161
- const { formatMessage } = reactIntl.useIntl();
162
- const TABLE_COL_COUNT = 5;
163
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: TABLE_COL_COUNT, rowCount: routes.length, children: [
164
- /* @__PURE__ */ jsxRuntime.jsx(TableHeader, { sortKey, handleSort }),
165
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: routes.length > 0 ? routes.map((route) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { route }, route.id)) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tr, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { colSpan: TABLE_COL_COUNT, children: /* @__PURE__ */ jsxRuntime.jsx(
166
- designSystem.EmptyStateLayout,
167
- {
168
- shadow: "none",
169
- content: formatMessage({
170
- id: index.getTranslation("paths.page.emptyPaths"),
171
- defaultMessage: "No paths found"
172
- })
173
- }
174
- ) }) }) })
175
- ] });
176
- }
177
- const Paths = () => {
178
- const { getAllRoutes } = index.useApi();
179
- const { formatMessage } = reactIntl.useIntl();
180
- const { toggleNotification } = admin.useNotification();
181
- const [allRoutes, setAllRoutes] = React.useState([]);
182
- const [routes, setRoutes] = React.useState([]);
183
- const [loading, setLoading] = React.useState(true);
184
- const [searchParams, setSearchParams] = reactRouterDom.useSearchParams();
185
- const initialQuery = searchParams.get("search") || "";
186
- const [searchQuery, setSearchQuery] = React.useState(initialQuery);
187
- const [sortKey, setSortKey] = React.useState("canonicalPath");
188
- const [sortDirection, setSortDirection] = React.useState("asc");
189
- React.useEffect(() => {
190
- const query = searchQuery.toLowerCase();
191
- setRoutes(
192
- allRoutes.filter(
193
- (route) => JSON.stringify(route.id).toLowerCase().includes(query) || route.title.toLowerCase().includes(query) || route.path.toLowerCase().includes(query) || route.relatedDocumentId.toLowerCase().includes(query) || route.relatedContentType.toLowerCase().includes(query)
194
- )
195
- );
196
- }, [searchQuery, allRoutes]);
197
- const debouncedSetSearchParams = React.useMemo(
198
- () => index.debounce((value) => {
199
- value ? setSearchParams({ search: value }) : setSearchParams({});
200
- }, 300),
201
- [setSearchParams]
202
- );
203
- const handleSearchChange = (e) => {
204
- const value = e.target.value;
205
- setSearchQuery(value);
206
- debouncedSetSearchParams(value);
207
- };
208
- React.useEffect(() => {
209
- async function fetchRoutes() {
210
- try {
211
- const data = await getAllRoutes();
212
- setAllRoutes(data);
213
- setRoutes(data);
214
- } catch (err) {
215
- strapi.log.error("Failed to fetch paths:", err);
216
- toggleNotification({
217
- type: "danger",
218
- message: formatMessage({
219
- id: index.getTranslation("notification.paths.fetchFailed"),
220
- defaultMessage: "Failed to fetch paths"
221
- })
222
- });
223
- } finally {
224
- setLoading(false);
225
- }
226
- }
227
- fetchRoutes();
228
- }, []);
229
- const handleSort = (key) => {
230
- setSortDirection((prev) => prev === "asc" ? "desc" : "asc");
231
- setSortKey(key);
232
- };
233
- const sortedRoutes = React.useMemo(() => {
234
- return sortKey ? [...routes].sort(compareBy(sortKey, sortDirection)) : routes;
235
- }, [routes, sortKey, sortDirection]);
236
- if (loading) {
237
- return /* @__PURE__ */ jsxRuntime.jsx(PageWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(FullLoader.FullLoader, {}) });
238
- }
239
- return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.pluginPermissions["page.routes"], children: /* @__PURE__ */ jsxRuntime.jsxs(PageWrapper, { children: [
240
- /* @__PURE__ */ jsxRuntime.jsx(SearchInput, { handleSearchChange, searchQuery }),
241
- /* @__PURE__ */ jsxRuntime.jsx(PathTable, { routes: sortedRoutes, sortKey, handleSort })
242
- ] }) });
243
- };
244
- exports.default = Paths;
@@ -1,243 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useReducer, useState, useRef, useEffect } from "react";
3
- import { Box, Accordion, Field, SingleSelect, SingleSelectOption, Typography, Link } from "@strapi/design-system";
4
- import { useNotification, Page } from "@strapi/strapi/admin";
5
- import { g as getTranslation, c as usePluginConfig, e as useAllContentTypes, p as pluginPermissions, f as PLUGIN_NAME, h as PLUGIN_VERSION } from "./index-Dx-EVn-t.mjs";
6
- import { useIntl } from "react-intl";
7
- import "@strapi/icons/symbols";
8
- import { F as FullLoader } from "./FullLoader-Btjb2W2p.mjs";
9
- import { P as PageWrapper, C as ContentBox, S as SettingTitle } from "./SettingTitle-UPbQCuTC.mjs";
10
- import { ExternalLink } from "@strapi/icons";
11
- function ContentTypeAccordion({
12
- contentType,
13
- contentTypeSettings,
14
- dispatch
15
- }) {
16
- const { formatMessage } = useIntl();
17
- if (!contentType) return null;
18
- return /* @__PURE__ */ jsx(Box, { borderColor: !contentTypeSettings.default ? "danger500" : void 0, children: /* @__PURE__ */ jsxs(Accordion.Item, { value: contentType.uid, children: [
19
- /* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { children: contentType?.info.displayName }) }),
20
- /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Box, { padding: 3, children: /* @__PURE__ */ jsxs(
21
- Field.Root,
22
- {
23
- name: "selectedContentTypes",
24
- hint: formatMessage({
25
- id: getTranslation("settings.page.generate.hint"),
26
- defaultMessage: 'The selected field from the content type will be used to generate the path. Use a field that is unique and descriptive, such as a "title" or "name".'
27
- }),
28
- error: !contentTypeSettings.default && formatMessage({
29
- id: getTranslation("settings.page.generate.error"),
30
- defaultMessage: "Please select a default field"
31
- }),
32
- required: true,
33
- children: [
34
- /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
35
- id: getTranslation("settings.page.generate"),
36
- defaultMessage: "Generate paths from"
37
- }) }),
38
- /* @__PURE__ */ jsx(
39
- SingleSelect,
40
- {
41
- name: `defaultField-${contentType.uid}`,
42
- onClear: () => dispatch({
43
- type: "SET_DEFAULT_FIELD",
44
- payload: { ctUid: contentType.uid, field: "" }
45
- }),
46
- value: contentTypeSettings?.default || "",
47
- onChange: (value) => dispatch({
48
- type: "SET_DEFAULT_FIELD",
49
- payload: { ctUid: contentType.uid, field: String(value) }
50
- }),
51
- children: Object.entries(contentType.attributes).map(([key], index) => {
52
- if (key === "id" || key === "documentId" || key === "createdAt" || key === "updatedAt" || key === "createdBy" || key === "updatedBy" || key === "webatlas" || // The following fields are not longer used in the new implementation, but we keep them hidden just in case
53
- key === "webatlas_path" || key === "webatlas_override" || key === "webatlas_parent")
54
- return null;
55
- return /* @__PURE__ */ jsx(SingleSelectOption, { value: key, children: key }, index);
56
- })
57
- }
58
- ),
59
- /* @__PURE__ */ jsx(Field.Hint, {})
60
- ]
61
- }
62
- ) }) })
63
- ] }, contentType.uid) }, contentType.uid);
64
- }
65
- function reducer(newConfig, action) {
66
- let updatedContentTypes;
67
- switch (action.type) {
68
- case "SET_DEFAULT_FIELD":
69
- if (!newConfig) return null;
70
- updatedContentTypes = newConfig?.selectedContentTypes.map(
71
- (ct) => ct.uid === action.payload.ctUid ? { ...ct, default: action.payload.field } : ct
72
- );
73
- return { ...newConfig, selectedContentTypes: updatedContentTypes || [] };
74
- case "SET_CONFIG":
75
- return action.payload;
76
- default:
77
- throw new Error();
78
- }
79
- }
80
- const Settings = () => {
81
- const { config: fetchedConfig, setConfig, loading, fetchError } = usePluginConfig();
82
- const [config, dispatch] = useReducer(reducer, fetchedConfig);
83
- const { contentTypes: allContentTypesData } = useAllContentTypes();
84
- const allContentTypes = allContentTypesData?.filter(
85
- (ct) => ct.pluginOptions?.webatlas?.enabled === true
86
- );
87
- const { toggleNotification } = useNotification();
88
- const { formatMessage } = useIntl();
89
- const [isSaving, setIsSaving] = useState(false);
90
- const initialConfig = useRef(fetchedConfig);
91
- useEffect(() => {
92
- initialConfig.current = fetchedConfig;
93
- if (fetchedConfig) dispatch({ type: "SET_CONFIG", payload: fetchedConfig });
94
- }, [fetchedConfig]);
95
- useEffect(() => {
96
- if (fetchError) {
97
- toggleNotification({
98
- type: "danger",
99
- message: formatMessage({
100
- id: getTranslation("notification.error"),
101
- defaultMessage: "An error occurred"
102
- }) + ": " + fetchError
103
- });
104
- }
105
- }, [fetchError, toggleNotification, formatMessage]);
106
- async function save() {
107
- if (!config || config.selectedContentTypes.find((cta) => !cta.default) !== void 0)
108
- return;
109
- setIsSaving(true);
110
- try {
111
- await setConfig({ selectedContentTypes: config.selectedContentTypes });
112
- initialConfig.current = config;
113
- toggleNotification({
114
- type: "success",
115
- message: formatMessage({
116
- id: getTranslation("notification.settings.saved"),
117
- defaultMessage: "Settings saved successfully"
118
- })
119
- });
120
- setIsSaving(false);
121
- } catch (err) {
122
- setIsSaving(false);
123
- toggleNotification({
124
- type: "danger",
125
- message: formatMessage({
126
- id: getTranslation("notification.error"),
127
- defaultMessage: "An error occurred"
128
- }) + ": " + err
129
- });
130
- strapi.log.error(err);
131
- }
132
- }
133
- if (loading) {
134
- return /* @__PURE__ */ jsx(
135
- PageWrapper,
136
- {
137
- isSaving,
138
- subtitle: formatMessage({
139
- id: getTranslation("loading"),
140
- defaultMessage: "Loading..."
141
- }),
142
- disabledCondition: true,
143
- children: /* @__PURE__ */ jsx(FullLoader, { height: 200 })
144
- }
145
- );
146
- }
147
- return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions["settings.general"], children: /* @__PURE__ */ jsxs(
148
- PageWrapper,
149
- {
150
- save,
151
- isSaving,
152
- subtitle: formatMessage({
153
- id: getTranslation("settings.page.general.subtitle"),
154
- defaultMessage: "Configure general settings"
155
- }),
156
- disabledCondition: JSON.stringify(config) === JSON.stringify(initialConfig.current),
157
- children: [
158
- /* @__PURE__ */ jsx(
159
- ContentBox,
160
- {
161
- title: formatMessage({
162
- id: getTranslation("settings.page.general.contentTypes"),
163
- defaultMessage: "Content Types"
164
- }),
165
- children: config?.selectedContentTypes && config.selectedContentTypes.length > 0 ? /* @__PURE__ */ jsxs(Field.Root, { name: "selectedContentTypesAccordion", children: [
166
- /* @__PURE__ */ jsx(Field.Label, { children: /* @__PURE__ */ jsx(SettingTitle, { children: formatMessage({
167
- id: getTranslation("settings.page.contentTypeSettings"),
168
- defaultMessage: "Content Type settings"
169
- }) }) }),
170
- /* @__PURE__ */ jsx(Accordion.Root, { children: config.selectedContentTypes?.map((contentTypeSettings) => {
171
- const ct = allContentTypes?.find(
172
- (item) => item.uid === contentTypeSettings.uid
173
- );
174
- return /* @__PURE__ */ jsx(
175
- ContentTypeAccordion,
176
- {
177
- contentType: ct,
178
- contentTypeSettings,
179
- dispatch
180
- },
181
- contentTypeSettings.uid
182
- );
183
- }) })
184
- ] }) : /* @__PURE__ */ jsxs(Typography, { children: [
185
- formatMessage({
186
- id: getTranslation("settings.page.general.noContentTypesEnabled"),
187
- defaultMessage: "No content types are enabled for Webatlas. Please enable at least one content type to use this plugin."
188
- }),
189
- /* @__PURE__ */ jsx(
190
- Link,
191
- {
192
- href: "https://github.com/mattisvensson/strapi-plugin-webatlas?tab=readme-ov-file#-configuration",
193
- isExternal: true,
194
- style: { marginLeft: 4 },
195
- children: formatMessage({
196
- id: getTranslation("settings.page.general.noContentTypesEnabled.moreInfo"),
197
- defaultMessage: "More info"
198
- })
199
- }
200
- )
201
- ] })
202
- }
203
- ),
204
- /* @__PURE__ */ jsx(
205
- ContentBox,
206
- {
207
- title: formatMessage({
208
- id: getTranslation("settings.page.general.details"),
209
- defaultMessage: "Details"
210
- }),
211
- children: /* @__PURE__ */ jsxs(Field.Root, { name: "selectedContentTypesAccordion", children: [
212
- /* @__PURE__ */ jsx(Field.Label, { children: /* @__PURE__ */ jsxs(SettingTitle, { children: [
213
- PLUGIN_NAME,
214
- " ",
215
- formatMessage({
216
- id: getTranslation("version"),
217
- defaultMessage: "Version"
218
- })
219
- ] }) }),
220
- /* @__PURE__ */ jsxs(Typography, { children: [
221
- "v",
222
- PLUGIN_VERSION,
223
- /* @__PURE__ */ jsx(
224
- Link,
225
- {
226
- href: `https://github.com/mattisvensson/strapi-plugin-webatlas/releases/tag/v${PLUGIN_VERSION}`,
227
- target: "_blank",
228
- rel: "noopener noreferrer",
229
- style: { marginLeft: 4 },
230
- children: /* @__PURE__ */ jsx(ExternalLink, {})
231
- }
232
- )
233
- ] })
234
- ] })
235
- }
236
- )
237
- ]
238
- }
239
- ) });
240
- };
241
- export {
242
- Settings as default
243
- };
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
5
- const designSystem = require("@strapi/design-system");
6
- const admin = require("@strapi/strapi/admin");
7
- const index = require("./index-Bm8lkiNL.js");
8
- const reactIntl = require("react-intl");
9
- require("@strapi/icons/symbols");
10
- const FullLoader = require("./FullLoader-Da2n70bJ.js");
11
- const SettingTitle = require("./SettingTitle-DGSkTF7e.js");
12
- function reducer(newConfig, action) {
13
- switch (action.type) {
14
- case "SET_MAX_DEPTH":
15
- if (!newConfig) return null;
16
- return {
17
- ...newConfig,
18
- navigation: { ...newConfig.navigation, maxDepth: action.payload },
19
- selectedContentTypes: newConfig.selectedContentTypes || []
20
- };
21
- case "SET_CONFIG":
22
- return action.payload;
23
- default:
24
- throw new Error();
25
- }
26
- }
27
- const Settings = () => {
28
- const { config: fetchedConfig, setConfig, loading, fetchError } = index.usePluginConfig();
29
- const [config, dispatch] = React.useReducer(reducer, fetchedConfig);
30
- const { toggleNotification } = admin.useNotification();
31
- const { formatMessage } = reactIntl.useIntl();
32
- const [isSaving, setIsSaving] = React.useState(false);
33
- const initialConfig = React.useRef(fetchedConfig);
34
- React.useEffect(() => {
35
- initialConfig.current = fetchedConfig;
36
- if (fetchedConfig) dispatch({ type: "SET_CONFIG", payload: fetchedConfig });
37
- }, [fetchedConfig]);
38
- React.useEffect(() => {
39
- if (fetchError) {
40
- toggleNotification({
41
- type: "danger",
42
- message: formatMessage({
43
- id: index.getTranslation("notification.error"),
44
- defaultMessage: "An error occurred"
45
- }) + ": " + fetchError
46
- });
47
- }
48
- }, [fetchError, toggleNotification, formatMessage]);
49
- async function save() {
50
- if (!config) return;
51
- setIsSaving(true);
52
- try {
53
- await setConfig({ navigation: config.navigation });
54
- initialConfig.current = config;
55
- toggleNotification({
56
- type: "success",
57
- message: formatMessage({
58
- id: index.getTranslation("notification.settings.saved"),
59
- defaultMessage: "Settings saved successfully"
60
- })
61
- });
62
- setIsSaving(false);
63
- } catch (err) {
64
- setIsSaving(false);
65
- toggleNotification({
66
- type: "danger",
67
- message: formatMessage({
68
- id: index.getTranslation("notification.error"),
69
- defaultMessage: "An error occurred"
70
- }) + ": " + err
71
- });
72
- strapi.log.error(err);
73
- }
74
- }
75
- if (loading) {
76
- return /* @__PURE__ */ jsxRuntime.jsx(
77
- SettingTitle.PageWrapper,
78
- {
79
- isSaving,
80
- subtitle: formatMessage({
81
- id: index.getTranslation("loading"),
82
- defaultMessage: "Loading..."
83
- }),
84
- disabledCondition: true,
85
- children: /* @__PURE__ */ jsxRuntime.jsx(FullLoader.FullLoader, { height: 200 })
86
- }
87
- );
88
- }
89
- return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.pluginPermissions["settings.navigation"], children: /* @__PURE__ */ jsxRuntime.jsx(
90
- SettingTitle.PageWrapper,
91
- {
92
- save,
93
- isSaving,
94
- subtitle: formatMessage({
95
- id: index.getTranslation("settings.page.navigation.subtitle"),
96
- defaultMessage: "Configure navigation settings"
97
- }),
98
- disabledCondition: JSON.stringify(config) === JSON.stringify(initialConfig.current),
99
- children: /* @__PURE__ */ jsxRuntime.jsx(
100
- SettingTitle.ContentBox,
101
- {
102
- title: formatMessage({
103
- id: index.getTranslation("settings.page.navigation.navigation"),
104
- defaultMessage: "Navigation"
105
- }),
106
- children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "maxNavDepth", children: [
107
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: /* @__PURE__ */ jsxRuntime.jsx(SettingTitle.SettingTitle, { children: formatMessage({
108
- id: index.getTranslation("settings.page.navigation.maxNavDepth.label"),
109
- defaultMessage: "Max depth of navigation tree"
110
- }) }) }),
111
- /* @__PURE__ */ jsxRuntime.jsx(
112
- designSystem.Field.Input,
113
- {
114
- id: "maxNavDepth",
115
- type: "number",
116
- min: 0,
117
- step: 1,
118
- value: config?.navigation?.maxDepth !== void 0 ? config.navigation.maxDepth + 1 : "",
119
- onChange: (e) => dispatch({
120
- type: "SET_MAX_DEPTH",
121
- payload: Number(e.target.value) - 1
122
- }),
123
- onBlur: (e) => {
124
- if (e.target.value === "") return;
125
- dispatch({
126
- type: "SET_MAX_DEPTH",
127
- payload: Number(e.target.value) - 1
128
- });
129
- }
130
- }
131
- ),
132
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
133
- ] })
134
- }
135
- )
136
- }
137
- ) });
138
- };
139
- exports.default = Settings;