@mattisvensson/strapi-plugin-webatlas 0.4.2 → 0.6.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/dist/_chunks/EmptyBox-BM4IscSk.mjs +1 -0
- package/dist/_chunks/EmptyBox-BM4IscSk.mjs.map +1 -0
- package/dist/_chunks/EmptyBox-T8t29l25.js +1 -0
- package/dist/_chunks/EmptyBox-T8t29l25.js.map +1 -0
- package/dist/_chunks/FullLoader-Cmsf8xS6.js +1 -0
- package/dist/_chunks/FullLoader-Cmsf8xS6.js.map +1 -0
- package/dist/_chunks/FullLoader-CrPED_dY.mjs +1 -0
- package/dist/_chunks/FullLoader-CrPED_dY.mjs.map +1 -0
- package/dist/_chunks/{de-RiCps8UH.js → de-CL1TIZPg.js} +5 -1
- package/dist/_chunks/de-CL1TIZPg.js.map +1 -0
- package/dist/_chunks/{de-Dn24NwJf.mjs → de-CzVD4dbZ.mjs} +5 -1
- package/dist/_chunks/de-CzVD4dbZ.mjs.map +1 -0
- package/dist/_chunks/{en-JLW5S3ZC.js → en-Du-Ap60j.js} +5 -1
- package/dist/_chunks/en-Du-Ap60j.js.map +1 -0
- package/dist/_chunks/{en-D9Lxaugc.mjs → en-Nk6QcTdr.mjs} +5 -1
- package/dist/_chunks/en-Nk6QcTdr.mjs.map +1 -0
- package/dist/_chunks/{index-CtJ_9-RB.mjs → index-B5u3q4DO.mjs} +6 -6
- package/dist/_chunks/index-Bxhu-TNT.js +4177 -0
- package/dist/_chunks/index-Bxhu-TNT.js.map +1 -0
- package/dist/_chunks/{index-CSYue_D0.js → index-C1HfYOU_.js} +6 -6
- package/dist/_chunks/index-CDqKPoLF.mjs +12200 -0
- package/dist/_chunks/index-CDqKPoLF.mjs.map +1 -0
- package/dist/_chunks/{index-Clikpy91.js → index-CcwGhk4b.js} +1724 -673
- package/dist/_chunks/index-Cw8m9qME.js +282 -0
- package/dist/_chunks/index-Cw8m9qME.js.map +1 -0
- package/dist/_chunks/index-DKWn1eh9.mjs +282 -0
- package/dist/_chunks/index-DKWn1eh9.mjs.map +1 -0
- package/dist/_chunks/{index-9db80XRS.mjs → index-DLfJwkbe.mjs} +1 -1
- package/dist/_chunks/index-DShP5BtK.mjs +127 -0
- package/dist/_chunks/index-DShP5BtK.mjs.map +1 -0
- package/dist/_chunks/index-DWcVnOi0.js +12200 -0
- package/dist/_chunks/index-DWcVnOi0.js.map +1 -0
- package/dist/_chunks/{index-CVj7qbwh.mjs → index-Dl3NwmwH.mjs} +1 -1
- package/dist/_chunks/index-DohcUdej.mjs +4161 -0
- package/dist/_chunks/index-DohcUdej.mjs.map +1 -0
- package/dist/_chunks/index-Dryo1JuH.js +127 -0
- package/dist/_chunks/index-Dryo1JuH.js.map +1 -0
- package/dist/_chunks/{index-CiY-8z8F.js → index-Dy2LLMda.js} +1 -1
- package/dist/_chunks/{index-B4pe6Yuh.mjs → index-Upva9LaE.mjs} +1725 -674
- package/dist/_chunks/{index-IHvD3566.js → index-xhAxCOze.js} +1 -1
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/index.mjs +2 -1
- package/dist/admin/index.mjs.map +1 -0
- package/dist/admin/src/hooks/useApi.d.ts +1 -1
- package/dist/admin/src/pages/Navigation/Page.d.ts +2 -0
- package/dist/admin/src/pages/Navigation/RouteItem.d.ts +1 -0
- package/dist/admin/src/pages/Navigation/SortableRouteItem.d.ts +1 -1
- package/dist/admin/src/pages/Navigation/index.d.ts +2 -2
- package/dist/server/index.js +13 -1
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +13 -1
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/src/index.d.ts +1 -1
- package/dist/server/src/services/admin.d.ts +1 -1
- package/dist/server/src/services/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,282 @@
|
|
|
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-Bxhu-TNT.js");
|
|
8
|
+
const reactIntl = require("react-intl");
|
|
9
|
+
require("@strapi/icons/symbols");
|
|
10
|
+
const FullLoader = require("./FullLoader-Cmsf8xS6.js");
|
|
11
|
+
function PageWrapper({
|
|
12
|
+
settingsState,
|
|
13
|
+
initialState,
|
|
14
|
+
save,
|
|
15
|
+
isSaving,
|
|
16
|
+
children
|
|
17
|
+
}) {
|
|
18
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
19
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
|
|
20
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
21
|
+
admin.Layouts.Header,
|
|
22
|
+
{
|
|
23
|
+
title: index.PLUGIN_NAME,
|
|
24
|
+
subtitle: formatMessage({
|
|
25
|
+
id: index.getTranslation("settings.page.subtitle"),
|
|
26
|
+
defaultMessage: "Settings"
|
|
27
|
+
}),
|
|
28
|
+
primaryAction: settingsState && initialState && save && /* @__PURE__ */ jsxRuntime.jsx(
|
|
29
|
+
designSystem.Button,
|
|
30
|
+
{
|
|
31
|
+
type: "submit",
|
|
32
|
+
onClick: () => save(),
|
|
33
|
+
loading: isSaving,
|
|
34
|
+
disabled: JSON.stringify(settingsState) === JSON.stringify(initialState) || settingsState.selectedContentTypes.find((cta) => !cta.default) !== void 0 || isSaving,
|
|
35
|
+
children: formatMessage({
|
|
36
|
+
id: index.getTranslation("save"),
|
|
37
|
+
defaultMessage: "Save"
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
),
|
|
43
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
designSystem.Box,
|
|
45
|
+
{
|
|
46
|
+
background: "neutral0",
|
|
47
|
+
borderColor: "neutral150",
|
|
48
|
+
hasRadius: true,
|
|
49
|
+
paddingBottom: 4,
|
|
50
|
+
paddingLeft: 4,
|
|
51
|
+
paddingRight: 4,
|
|
52
|
+
paddingTop: 6,
|
|
53
|
+
shadow: "tableShadow",
|
|
54
|
+
children
|
|
55
|
+
}
|
|
56
|
+
) })
|
|
57
|
+
] });
|
|
58
|
+
}
|
|
59
|
+
function ContentTypeAccordion({
|
|
60
|
+
contentType,
|
|
61
|
+
contentTypeSettings,
|
|
62
|
+
dispatch
|
|
63
|
+
}) {
|
|
64
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
65
|
+
if (!contentType) return null;
|
|
66
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
67
|
+
designSystem.Box,
|
|
68
|
+
{
|
|
69
|
+
borderColor: !contentTypeSettings.default && "danger500",
|
|
70
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Item, { value: contentType.uid, size: "S", children: [
|
|
71
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Trigger, { children: contentType?.info.displayName }) }),
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 3, children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
74
|
+
designSystem.Field.Root,
|
|
75
|
+
{
|
|
76
|
+
name: "selectedContentTypes",
|
|
77
|
+
hint: formatMessage({
|
|
78
|
+
id: index.getTranslation("settings.page.defaultField.hint"),
|
|
79
|
+
defaultMessage: 'The selected field from the content type will be used to generate the URL alias. Use a field that is unique and descriptive, such as a "title" or "name".'
|
|
80
|
+
}),
|
|
81
|
+
error: !contentTypeSettings.default && formatMessage({
|
|
82
|
+
id: index.getTranslation("settings.page.defaultField.error"),
|
|
83
|
+
defaultMessage: "Please select a default field"
|
|
84
|
+
}),
|
|
85
|
+
required: true,
|
|
86
|
+
children: [
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
|
|
88
|
+
id: index.getTranslation("settings.page.defaultField"),
|
|
89
|
+
defaultMessage: "Default URL Alias field"
|
|
90
|
+
}) }),
|
|
91
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
92
|
+
designSystem.SingleSelect,
|
|
93
|
+
{
|
|
94
|
+
name: `defaultField-${contentType.uid}`,
|
|
95
|
+
onClear: () => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: "" } }),
|
|
96
|
+
value: contentTypeSettings?.default || "",
|
|
97
|
+
onChange: (value) => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: value } }),
|
|
98
|
+
children: Object.entries(contentType.attributes).map(([key], index2) => {
|
|
99
|
+
if (key === "id" || key === "documentId" || key === "createdAt" || key === "updatedAt" || key === "createdBy" || key === "updatedBy" || key === "webatlas_path" || key === "webatlas_override") return null;
|
|
100
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: key, children: key }, index2);
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
109
|
+
designSystem.Field.Root,
|
|
110
|
+
{
|
|
111
|
+
name: "urlAliasPattern",
|
|
112
|
+
hint: formatMessage({
|
|
113
|
+
id: index.getTranslation("settings.page.urlAliasPattern.hint"),
|
|
114
|
+
defaultMessage: 'The pattern to prepend to the generated URL alias. For example, if you enter "blog" and the value of default field is "My First Post", the generated URL alias will be "blog/my-first-post". Leave empty for no prefix.'
|
|
115
|
+
}),
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Label, { children: [
|
|
118
|
+
formatMessage({
|
|
119
|
+
id: index.getTranslation("settings.page.urlAliasPattern"),
|
|
120
|
+
defaultMessage: "URL Alias Pattern"
|
|
121
|
+
}),
|
|
122
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.Tooltip, { description: formatMessage({
|
|
123
|
+
id: index.getTranslation("settings.page.urlAliasPattern.tooltip"),
|
|
124
|
+
defaultMessage: "Leading and trailing slashes will be removed. Spaces will be replaced with hyphens. Special characters will be encoded."
|
|
125
|
+
}) })
|
|
126
|
+
] }),
|
|
127
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
128
|
+
designSystem.Field.Input,
|
|
129
|
+
{
|
|
130
|
+
value: contentTypeSettings.pattern,
|
|
131
|
+
onChange: (e) => dispatch({ type: "SET_PATTERN", payload: { ctUid: contentType.uid, pattern: e.target.value } }),
|
|
132
|
+
disabled: !contentTypeSettings.default,
|
|
133
|
+
type: "text",
|
|
134
|
+
placeholder: formatMessage({
|
|
135
|
+
id: index.getTranslation("settings.page.urlAliasPattern.placeholder"),
|
|
136
|
+
defaultMessage: "e.g. blog"
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
) })
|
|
144
|
+
] }) })
|
|
145
|
+
] }, contentType.uid)
|
|
146
|
+
},
|
|
147
|
+
contentType.uid
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
function reducer(settingsState, action) {
|
|
151
|
+
let updatedContentTypes;
|
|
152
|
+
switch (action.type) {
|
|
153
|
+
case "SET_SELECTED_CONTENT_TYPES":
|
|
154
|
+
updatedContentTypes = action.payload.map((ct) => {
|
|
155
|
+
return settingsState.selectedContentTypes.find((cta) => cta.uid === ct.uid) || ct;
|
|
156
|
+
});
|
|
157
|
+
return { ...settingsState, selectedContentTypes: updatedContentTypes };
|
|
158
|
+
case "SET_DEFAULT_FIELD":
|
|
159
|
+
updatedContentTypes = settingsState.selectedContentTypes.map(
|
|
160
|
+
(ct) => ct.uid === action.payload.ctUid ? { ...ct, default: action.payload.field } : ct
|
|
161
|
+
);
|
|
162
|
+
return { ...settingsState, selectedContentTypes: updatedContentTypes };
|
|
163
|
+
case "SET_PATTERN":
|
|
164
|
+
updatedContentTypes = settingsState.selectedContentTypes.map(
|
|
165
|
+
(ct) => ct.uid === action.payload.ctUid ? { ...ct, pattern: index.transformToUrl(action.payload.pattern) } : ct
|
|
166
|
+
);
|
|
167
|
+
return { ...settingsState, selectedContentTypes: updatedContentTypes };
|
|
168
|
+
default:
|
|
169
|
+
throw new Error();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const Settings = () => {
|
|
173
|
+
const { config, setConfig, loading, fetchError } = index.usePluginConfig();
|
|
174
|
+
const [settingsState, dispatch] = React.useReducer(reducer, config || { selectedContentTypes: [] });
|
|
175
|
+
const { contentTypes: allContentTypesData } = index.useAllContentTypes();
|
|
176
|
+
const allContentTypes = allContentTypesData?.filter((ct) => ct.pluginOptions?.webatlas?.active === true);
|
|
177
|
+
const [initialState, setInitialState] = React.useState(config || { selectedContentTypes: [] });
|
|
178
|
+
const { toggleNotification } = admin.useNotification();
|
|
179
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
180
|
+
const [isSaving, setIsSaving] = React.useState(false);
|
|
181
|
+
React.useEffect(() => {
|
|
182
|
+
setInitialState(config || { selectedContentTypes: [] });
|
|
183
|
+
}, [config]);
|
|
184
|
+
React.useEffect(() => {
|
|
185
|
+
if (!config) return;
|
|
186
|
+
dispatch({ type: "SET_SELECTED_CONTENT_TYPES", payload: config.selectedContentTypes });
|
|
187
|
+
}, [config]);
|
|
188
|
+
React.useEffect(() => {
|
|
189
|
+
if (fetchError) {
|
|
190
|
+
toggleNotification({
|
|
191
|
+
type: "danger",
|
|
192
|
+
message: formatMessage({
|
|
193
|
+
id: index.getTranslation("notification.error"),
|
|
194
|
+
defaultMessage: "An error occurred"
|
|
195
|
+
}) + ": " + fetchError
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}, [fetchError, toggleNotification, formatMessage]);
|
|
199
|
+
async function save() {
|
|
200
|
+
if (!settingsState || settingsState.selectedContentTypes.find((cta) => !cta.default) !== void 0) return;
|
|
201
|
+
setIsSaving(true);
|
|
202
|
+
try {
|
|
203
|
+
await setConfig(settingsState);
|
|
204
|
+
setInitialState(settingsState);
|
|
205
|
+
toggleNotification({
|
|
206
|
+
type: "success",
|
|
207
|
+
message: formatMessage({
|
|
208
|
+
id: index.getTranslation("notification.settings.saved"),
|
|
209
|
+
defaultMessage: "Settings saved successfully"
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
setIsSaving(false);
|
|
213
|
+
} catch (err) {
|
|
214
|
+
setIsSaving(false);
|
|
215
|
+
toggleNotification({
|
|
216
|
+
type: "danger",
|
|
217
|
+
message: formatMessage({
|
|
218
|
+
id: index.getTranslation("notification.error"),
|
|
219
|
+
defaultMessage: "An error occurred"
|
|
220
|
+
}) + ": " + err
|
|
221
|
+
});
|
|
222
|
+
console.error(err);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (loading) {
|
|
226
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PageWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(FullLoader.FullLoader, { height: 200 }) });
|
|
227
|
+
}
|
|
228
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(PageWrapper, { settingsState, initialState, save, isSaving, children: [
|
|
229
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
230
|
+
designSystem.Field.Root,
|
|
231
|
+
{
|
|
232
|
+
name: "selectedContentTypes",
|
|
233
|
+
hint: formatMessage({
|
|
234
|
+
id: index.getTranslation("settings.page.enabledContentTypes.hint"),
|
|
235
|
+
defaultMessage: "Select the content types for which you want to enable URL aliases"
|
|
236
|
+
}),
|
|
237
|
+
children: [
|
|
238
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
|
|
239
|
+
id: index.getTranslation("settings.page.enabledContentTypes"),
|
|
240
|
+
defaultMessage: "Enabled Content Types"
|
|
241
|
+
}) }),
|
|
242
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
243
|
+
designSystem.MultiSelect,
|
|
244
|
+
{
|
|
245
|
+
placeholder: formatMessage({
|
|
246
|
+
id: index.getTranslation("settings.page.enabledContentTypes.placeholder"),
|
|
247
|
+
defaultMessage: "Select content types..."
|
|
248
|
+
}),
|
|
249
|
+
onClear: () => dispatch({ type: "SET_SELECTED_CONTENT_TYPES", payload: [] }),
|
|
250
|
+
value: [...settingsState.selectedContentTypes.map((ct) => ct.uid)],
|
|
251
|
+
onChange: (value) => dispatch({
|
|
252
|
+
type: "SET_SELECTED_CONTENT_TYPES",
|
|
253
|
+
payload: value.map((v) => ({
|
|
254
|
+
uid: v,
|
|
255
|
+
default: "",
|
|
256
|
+
pattern: ""
|
|
257
|
+
}))
|
|
258
|
+
}),
|
|
259
|
+
withTags: true,
|
|
260
|
+
children: allContentTypes && allContentTypes.map(
|
|
261
|
+
(item) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.MultiSelectOption, { value: item.uid, children: item.info.displayName }, item.uid)
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
),
|
|
265
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
),
|
|
269
|
+
settingsState.selectedContentTypes && settingsState.selectedContentTypes.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: "selectedContentTypesAccordion", children: [
|
|
270
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
|
|
271
|
+
id: index.getTranslation("settings.page.contentTypeSettings"),
|
|
272
|
+
defaultMessage: "Content Type settings"
|
|
273
|
+
}) }),
|
|
274
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Root, { children: settingsState.selectedContentTypes?.map((contentTypeSettings) => {
|
|
275
|
+
const ct = allContentTypes?.find((item) => item.uid === contentTypeSettings.uid);
|
|
276
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ContentTypeAccordion, { contentType: ct, contentTypeSettings, dispatch }, contentTypeSettings.uid);
|
|
277
|
+
}) })
|
|
278
|
+
] }) })
|
|
279
|
+
] });
|
|
280
|
+
};
|
|
281
|
+
exports.default = Settings;
|
|
282
|
+
//# sourceMappingURL=index-Cw8m9qME.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Cw8m9qME.js","sources":["../../admin/src/pages/Settings/PageWrapper.tsx","../../admin/src/pages/Settings/ContentTypeAccordion.tsx","../../admin/src/pages/Settings/index.tsx"],"sourcesContent":["import { Button, Box } from '@strapi/design-system';\nimport { Page, Layouts} from '@strapi/strapi/admin'\nimport { PLUGIN_NAME } from '../../../../pluginId';\nimport { getTranslation } from '../../utils';\nimport { useIntl } from 'react-intl';\nimport type { ConfigContentType } from '../../../../types';\n\nexport default function PageWrapper({ \n settingsState, \n initialState, \n save, \n isSaving,\n children\n}: { \n settingsState?: any, \n initialState?: any, \n save?: () => void, \n isSaving?: boolean,\n children: React.ReactNode \n}) {\n\n const { formatMessage } = useIntl();\n \n return (\n <Page.Main>\n <Layouts.Header\n title={PLUGIN_NAME}\n subtitle={formatMessage({\n id: getTranslation('settings.page.subtitle'),\n defaultMessage: 'Settings',\n })}\n primaryAction={ settingsState && initialState && save &&\n <Button\n type=\"submit\"\n onClick={() => save()}\n loading={isSaving}\n disabled={\n JSON.stringify(settingsState) === JSON.stringify(initialState)\n || settingsState.selectedContentTypes.find((cta: ConfigContentType) => !cta.default) !== undefined\n || isSaving\n }\n >\n {formatMessage({\n id: getTranslation('save'),\n defaultMessage: 'Save',\n })}\n </Button>\n }\n />\n <Layouts.Content>\n <Box\n background='neutral0'\n borderColor=\"neutral150\"\n hasRadius\n paddingBottom={4}\n paddingLeft={4}\n paddingRight={4}\n paddingTop={6}\n shadow=\"tableShadow\"\n >\n {children}\n </Box>\n </Layouts.Content>\n </Page.Main>\n )\n}","import { SingleSelect, SingleSelectOption } from '@strapi/design-system';\nimport Tooltip from '../../components/Tooltip'\nimport { Box, Accordion, Field } from '@strapi/design-system';\nimport { getTranslation } from '../../utils';\nimport { useIntl } from 'react-intl';\nimport type { ContentType, ConfigContentType } from '../../../../types';\n\nexport default function ContentTypeAccordion({ \n contentType,\n contentTypeSettings,\n dispatch\n}: { \n contentType: ContentType | undefined, \n contentTypeSettings: ConfigContentType, \n dispatch: React.Dispatch<any>\n}) {\n \n const { formatMessage } = useIntl();\n\n if (!contentType) return null\n\n return (\n <Box\n borderColor={!contentTypeSettings.default && 'danger500'}\n key={contentType.uid}\n >\n <Accordion.Item key={contentType.uid} value={contentType.uid} size=\"S\">\n <Accordion.Header>\n <Accordion.Trigger>\n {contentType?.info.displayName}\n </Accordion.Trigger>\n </Accordion.Header>\n <Accordion.Content>\n <Box padding={3}>\n <Field.Root\n name=\"selectedContentTypes\"\n hint={formatMessage({\n id: getTranslation('settings.page.defaultField.hint'),\n defaultMessage: 'The selected field from the content type will be used to generate the URL alias. Use a field that is unique and descriptive, such as a \"title\" or \"name\".',\n })}\n error={!contentTypeSettings.default && formatMessage({\n id: getTranslation('settings.page.defaultField.error'),\n defaultMessage: 'Please select a default field',\n })}\n required\n >\n <Field.Label>\n {formatMessage({\n id: getTranslation('settings.page.defaultField'),\n defaultMessage: 'Default URL Alias field',\n })}\n </Field.Label>\n <SingleSelect\n name={`defaultField-${contentType.uid}`}\n onClear={() => dispatch({ type: 'SET_DEFAULT_FIELD', payload: { ctUid: contentType.uid, field: '' } })}\n value={contentTypeSettings?.default || ''}\n onChange={(value: string) => dispatch({ type: 'SET_DEFAULT_FIELD', payload: { ctUid: contentType.uid, field: value } })}\n >\n {Object.entries(contentType.attributes).map(([key], index) => {\n if (\n key === 'id' || \n key === 'documentId' ||\n key === 'createdAt' || \n key === 'updatedAt' || \n key === 'createdBy' || \n key === 'updatedBy' ||\n key === 'webatlas_path' ||\n key === 'webatlas_override'\n ) return null\n return <SingleSelectOption key={index} value={key}>{key}</SingleSelectOption>\n })}\n </SingleSelect>\n <Field.Hint/>\n </Field.Root>\n <Box paddingTop={4}>\n <Field.Root\n name=\"urlAliasPattern\"\n hint={formatMessage({\n id: getTranslation('settings.page.urlAliasPattern.hint'),\n defaultMessage: 'The pattern to prepend to the generated URL alias. For example, if you enter \"blog\" and the value of default field is \"My First Post\", the generated URL alias will be \"blog/my-first-post\". Leave empty for no prefix.',\n })}\n >\n <Field.Label>\n {formatMessage({\n id: getTranslation('settings.page.urlAliasPattern'),\n defaultMessage: 'URL Alias Pattern',\n })}\n <Tooltip description={formatMessage({\n id: getTranslation('settings.page.urlAliasPattern.tooltip'),\n defaultMessage: 'Leading and trailing slashes will be removed. Spaces will be replaced with hyphens. Special characters will be encoded.',\n })} />\n </Field.Label>\n <Field.Input\n value={contentTypeSettings.pattern}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => dispatch({ type: 'SET_PATTERN', payload: { ctUid: contentType.uid, pattern: e.target.value } })}\n disabled={!contentTypeSettings.default}\n type=\"text\"\n placeholder={formatMessage({\n id: getTranslation('settings.page.urlAliasPattern.placeholder'),\n defaultMessage: 'e.g. blog',\n })}\n />\n <Field.Hint />\n </Field.Root>\n </Box>\n </Box>\n </Accordion.Content>\n </Accordion.Item>\n </Box>\n \n )\n}","/*\n *\n * Settings\n * This file contains the settings page for the Webatlas plugin in Strapi.\n * It allows users to configure which content types are enabled for URL aliases and navigations,\n * as well as setting default fields and the URL alias patterns for each content type. \n *\n*/\n\nimport { useEffect, useState, useReducer } from 'react';\nimport { Box, Accordion, Field } from '@strapi/design-system';\nimport { useNotification } from '@strapi/strapi/admin'\nimport { MultiSelect, MultiSelectOption } from '@strapi/design-system';\nimport usePluginConfig from '../../hooks/usePluginConfig';\nimport type { ContentType, ConfigContentType, PluginConfig } from '../../../../types';\nimport transformToUrl from '../../../../utils/transformToUrl';\nimport useAllContentTypes from '../../hooks/useAllContentTypes';\nimport { getTranslation } from '../../utils';\nimport { useIntl } from 'react-intl';\nimport { FullLoader } from '../../components/UI';\nimport PageWrapper from './PageWrapper';\nimport ContentTypeAccordion from './ContentTypeAccordion';\n\ntype Action =\n | { type: 'SET_SELECTED_CONTENT_TYPES'; payload: ConfigContentType[] }\n | { type: 'SET_DEFAULT_FIELD'; payload: { ctUid: string; field: string } }\n | { type: 'SET_PATTERN'; payload: { ctUid: string; pattern: string } }\n\nfunction reducer(settingsState: PluginConfig, action: Action): PluginConfig {\n let updatedContentTypes\n switch (action.type) {\n case 'SET_SELECTED_CONTENT_TYPES':\n updatedContentTypes = action.payload.map(ct => {\n return settingsState.selectedContentTypes.find((cta: ConfigContentType) => cta.uid === ct.uid) || ct\n })\n return { ...settingsState, selectedContentTypes: updatedContentTypes };\n case 'SET_DEFAULT_FIELD':\n updatedContentTypes = settingsState.selectedContentTypes.map(ct =>\n ct.uid === action.payload.ctUid ? { ...ct, default: action.payload.field } : ct\n );\n return { ...settingsState, selectedContentTypes: updatedContentTypes };\n case 'SET_PATTERN':\n updatedContentTypes = settingsState.selectedContentTypes.map(ct =>\n ct.uid === action.payload.ctUid ? { ...ct, pattern: transformToUrl(action.payload.pattern) } : ct\n );\n return { ...settingsState, selectedContentTypes: updatedContentTypes };\n default:\n throw new Error();\n }\n}\n\nconst Settings = () => {\n const { config, setConfig, loading, fetchError } = usePluginConfig();\n const [settingsState, dispatch] = useReducer(reducer, config || { selectedContentTypes: [] });\n const { contentTypes: allContentTypesData } = useAllContentTypes();\n const allContentTypes = allContentTypesData?.filter((ct: ContentType) => ct.pluginOptions?.webatlas?.active === true);\n const [initialState, setInitialState] = useState(config || { selectedContentTypes: [] })\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const [isSaving, setIsSaving] = useState(false);\n\n useEffect(() => {\n setInitialState(config || { selectedContentTypes: [] })\n }, [config]);\n\n useEffect(() => {\n if (!config) return;\n dispatch({ type: 'SET_SELECTED_CONTENT_TYPES', payload: config.selectedContentTypes });\n }, [config]);\n \n useEffect(() => {\n if (fetchError) {\n toggleNotification({\n type: 'danger',\n message: formatMessage({\n id: getTranslation('notification.error'),\n defaultMessage: 'An error occurred',\n }) + ': ' + fetchError,\n });\n }\n }, [fetchError, toggleNotification, formatMessage]);\n\n async function save() {\n if (\n !settingsState \n || settingsState.selectedContentTypes.find((cta: ConfigContentType) => !cta.default) !== undefined\n ) return\n\n setIsSaving(true);\n try {\n await setConfig(settingsState)\n setInitialState(settingsState)\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTranslation('notification.settings.saved'),\n defaultMessage: 'Settings saved successfully',\n }),\n });\n setIsSaving(false);\n } catch (err) {\n setIsSaving(false);\n toggleNotification({\n type: 'danger',\n message: formatMessage({\n id: getTranslation('notification.error'),\n defaultMessage: 'An error occurred',\n }) + ': ' + err,\n });\n console.error(err);\n }\n }\n\n if (loading) {\n return <PageWrapper>\n <FullLoader height={200} />\n </PageWrapper>\n }\n\n return (\n <PageWrapper settingsState={settingsState} initialState={initialState} save={save} isSaving={isSaving}>\n <Field.Root\n name=\"selectedContentTypes\"\n hint={formatMessage({\n id: getTranslation('settings.page.enabledContentTypes.hint'),\n defaultMessage: 'Select the content types for which you want to enable URL aliases',\n })}\n >\n <Field.Label>\n {formatMessage({\n id: getTranslation('settings.page.enabledContentTypes'),\n defaultMessage: 'Enabled Content Types',\n })}\n </Field.Label>\n <MultiSelect\n placeholder={formatMessage({\n id: getTranslation('settings.page.enabledContentTypes.placeholder'),\n defaultMessage: 'Select content types...',\n })}\n onClear={() => dispatch({ type: 'SET_SELECTED_CONTENT_TYPES', payload: [] })}\n value={[...settingsState.selectedContentTypes.map((ct: ConfigContentType) => ct.uid)]}\n onChange={(value: string[]) =>\n dispatch({\n type: 'SET_SELECTED_CONTENT_TYPES',\n payload: value.map(v => ({\n uid: v,\n default: '',\n pattern: '',\n })),\n })\n }\n withTags\n >\n {allContentTypes && allContentTypes.map(item => \n <MultiSelectOption key={item.uid} value={item.uid}>{item.info.displayName}</MultiSelectOption>\n )}\n </MultiSelect>\n <Field.Hint/>\n </Field.Root>\n {settingsState.selectedContentTypes && settingsState.selectedContentTypes.length > 0 && \n <Box paddingTop={4}>\n <Field.Root name=\"selectedContentTypesAccordion\">\n <Field.Label>\n {formatMessage({\n id: getTranslation('settings.page.contentTypeSettings'),\n defaultMessage: 'Content Type settings',\n })}\n </Field.Label>\n <Accordion.Root>\n {settingsState.selectedContentTypes?.map((contentTypeSettings: ConfigContentType) => {\n const ct: ContentType | undefined = allContentTypes?.find((item) => item.uid === contentTypeSettings.uid)\n return <ContentTypeAccordion key={contentTypeSettings.uid} contentType={ct} contentTypeSettings={contentTypeSettings} dispatch={dispatch} />\n })}\n </Accordion.Root>\n </Field.Root>\n </Box>\n }\n </PageWrapper>\n );\n};\n\nexport default Settings;\n"],"names":["useIntl","jsxs","Page","jsx","Layouts","PLUGIN_NAME","getTranslation","Button","Box","Accordion","Field","SingleSelect","index","SingleSelectOption","Tooltip","transformToUrl","usePluginConfig","useReducer","useAllContentTypes","useState","useNotification","useEffect","FullLoader","MultiSelect","MultiSelectOption"],"mappings":";;;;;;;;;;AAOA,SAAwB,YAAY;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAMG;AAEK,QAAA,EAAE,cAAc,IAAIA,kBAAQ;AAGhC,SAAAC,gCAACC,MAAAA,KAAK,MAAL,EACC,UAAA;AAAA,IAAAC,2BAAA;AAAA,MAACC,MAAAA,QAAQ;AAAA,MAAR;AAAA,QACC,OAAO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,MAAN,CAAU,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACb;AAAA,IACC,cAAc,wBAAwB,cAAc,qBAAqB,SAAS,KACjFP,2BAAA,IAACK,kBAAI,EAAA,YAAY,GACf,UAACP,2BAAAA,KAAAS,aAAA,MAAM,MAAN,EAAW,MAAK,iCACf,UAAA;AAAA,MAACP,2BAAAA,IAAAO,aAAAA,MAAM,OAAN,EACE,UAAc,cAAA;AAAA,QACb,IAAIJ,qBAAe,mCAAmC;AAAA,QACtD,gBAAgB;AAAA,MACjB,CAAA,GACH;AAAA,MACAH,+BAACM,aAAAA,UAAU,MAAV,EACE,wBAAc,sBAAsB,IAAI,CAAC,wBAA2C;AAC7E,cAAA,KAA8B,iBAAiB,KAAK,CAAC,SAAS,KAAK,QAAQ,oBAAoB,GAAG;AACxG,8CAAQ,sBAAmD,EAAA,aAAa,IAAI,qBAA0C,SAAA,GAApF,oBAAoB,GAAoF;AAAA,MAAA,CAC3I,EACH,CAAA;AAAA,IAAA,EAAA,CACF,EACF,CAAA;AAAA,EAAA,GAEJ;AAEJ;;"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useReducer, useState, useEffect } from "react";
|
|
3
|
+
import { Button, Box, Accordion, Field, SingleSelect, SingleSelectOption, MultiSelect, MultiSelectOption } from "@strapi/design-system";
|
|
4
|
+
import { Page, Layouts, useNotification } from "@strapi/strapi/admin";
|
|
5
|
+
import { P as PLUGIN_NAME, g as getTranslation, T as Tooltip, b as usePluginConfig, c as useAllContentTypes, t as transformToUrl } from "./index-DohcUdej.mjs";
|
|
6
|
+
import { useIntl } from "react-intl";
|
|
7
|
+
import "@strapi/icons/symbols";
|
|
8
|
+
import { F as FullLoader } from "./FullLoader-CrPED_dY.mjs";
|
|
9
|
+
function PageWrapper({
|
|
10
|
+
settingsState,
|
|
11
|
+
initialState,
|
|
12
|
+
save,
|
|
13
|
+
isSaving,
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
const { formatMessage } = useIntl();
|
|
17
|
+
return /* @__PURE__ */ jsxs(Page.Main, { children: [
|
|
18
|
+
/* @__PURE__ */ jsx(
|
|
19
|
+
Layouts.Header,
|
|
20
|
+
{
|
|
21
|
+
title: PLUGIN_NAME,
|
|
22
|
+
subtitle: formatMessage({
|
|
23
|
+
id: getTranslation("settings.page.subtitle"),
|
|
24
|
+
defaultMessage: "Settings"
|
|
25
|
+
}),
|
|
26
|
+
primaryAction: settingsState && initialState && save && /* @__PURE__ */ jsx(
|
|
27
|
+
Button,
|
|
28
|
+
{
|
|
29
|
+
type: "submit",
|
|
30
|
+
onClick: () => save(),
|
|
31
|
+
loading: isSaving,
|
|
32
|
+
disabled: JSON.stringify(settingsState) === JSON.stringify(initialState) || settingsState.selectedContentTypes.find((cta) => !cta.default) !== void 0 || isSaving,
|
|
33
|
+
children: formatMessage({
|
|
34
|
+
id: getTranslation("save"),
|
|
35
|
+
defaultMessage: "Save"
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
),
|
|
41
|
+
/* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsx(
|
|
42
|
+
Box,
|
|
43
|
+
{
|
|
44
|
+
background: "neutral0",
|
|
45
|
+
borderColor: "neutral150",
|
|
46
|
+
hasRadius: true,
|
|
47
|
+
paddingBottom: 4,
|
|
48
|
+
paddingLeft: 4,
|
|
49
|
+
paddingRight: 4,
|
|
50
|
+
paddingTop: 6,
|
|
51
|
+
shadow: "tableShadow",
|
|
52
|
+
children
|
|
53
|
+
}
|
|
54
|
+
) })
|
|
55
|
+
] });
|
|
56
|
+
}
|
|
57
|
+
function ContentTypeAccordion({
|
|
58
|
+
contentType,
|
|
59
|
+
contentTypeSettings,
|
|
60
|
+
dispatch
|
|
61
|
+
}) {
|
|
62
|
+
const { formatMessage } = useIntl();
|
|
63
|
+
if (!contentType) return null;
|
|
64
|
+
return /* @__PURE__ */ jsx(
|
|
65
|
+
Box,
|
|
66
|
+
{
|
|
67
|
+
borderColor: !contentTypeSettings.default && "danger500",
|
|
68
|
+
children: /* @__PURE__ */ jsxs(Accordion.Item, { value: contentType.uid, size: "S", children: [
|
|
69
|
+
/* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { children: contentType?.info.displayName }) }),
|
|
70
|
+
/* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsxs(Box, { padding: 3, children: [
|
|
71
|
+
/* @__PURE__ */ jsxs(
|
|
72
|
+
Field.Root,
|
|
73
|
+
{
|
|
74
|
+
name: "selectedContentTypes",
|
|
75
|
+
hint: formatMessage({
|
|
76
|
+
id: getTranslation("settings.page.defaultField.hint"),
|
|
77
|
+
defaultMessage: 'The selected field from the content type will be used to generate the URL alias. Use a field that is unique and descriptive, such as a "title" or "name".'
|
|
78
|
+
}),
|
|
79
|
+
error: !contentTypeSettings.default && formatMessage({
|
|
80
|
+
id: getTranslation("settings.page.defaultField.error"),
|
|
81
|
+
defaultMessage: "Please select a default field"
|
|
82
|
+
}),
|
|
83
|
+
required: true,
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
|
|
86
|
+
id: getTranslation("settings.page.defaultField"),
|
|
87
|
+
defaultMessage: "Default URL Alias field"
|
|
88
|
+
}) }),
|
|
89
|
+
/* @__PURE__ */ jsx(
|
|
90
|
+
SingleSelect,
|
|
91
|
+
{
|
|
92
|
+
name: `defaultField-${contentType.uid}`,
|
|
93
|
+
onClear: () => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: "" } }),
|
|
94
|
+
value: contentTypeSettings?.default || "",
|
|
95
|
+
onChange: (value) => dispatch({ type: "SET_DEFAULT_FIELD", payload: { ctUid: contentType.uid, field: value } }),
|
|
96
|
+
children: Object.entries(contentType.attributes).map(([key], index) => {
|
|
97
|
+
if (key === "id" || key === "documentId" || key === "createdAt" || key === "updatedAt" || key === "createdBy" || key === "updatedBy" || key === "webatlas_path" || key === "webatlas_override") return null;
|
|
98
|
+
return /* @__PURE__ */ jsx(SingleSelectOption, { value: key, children: key }, index);
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
),
|
|
102
|
+
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(
|
|
107
|
+
Field.Root,
|
|
108
|
+
{
|
|
109
|
+
name: "urlAliasPattern",
|
|
110
|
+
hint: formatMessage({
|
|
111
|
+
id: getTranslation("settings.page.urlAliasPattern.hint"),
|
|
112
|
+
defaultMessage: 'The pattern to prepend to the generated URL alias. For example, if you enter "blog" and the value of default field is "My First Post", the generated URL alias will be "blog/my-first-post". Leave empty for no prefix.'
|
|
113
|
+
}),
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ jsxs(Field.Label, { children: [
|
|
116
|
+
formatMessage({
|
|
117
|
+
id: getTranslation("settings.page.urlAliasPattern"),
|
|
118
|
+
defaultMessage: "URL Alias Pattern"
|
|
119
|
+
}),
|
|
120
|
+
/* @__PURE__ */ jsx(Tooltip, { description: formatMessage({
|
|
121
|
+
id: getTranslation("settings.page.urlAliasPattern.tooltip"),
|
|
122
|
+
defaultMessage: "Leading and trailing slashes will be removed. Spaces will be replaced with hyphens. Special characters will be encoded."
|
|
123
|
+
}) })
|
|
124
|
+
] }),
|
|
125
|
+
/* @__PURE__ */ jsx(
|
|
126
|
+
Field.Input,
|
|
127
|
+
{
|
|
128
|
+
value: contentTypeSettings.pattern,
|
|
129
|
+
onChange: (e) => dispatch({ type: "SET_PATTERN", payload: { ctUid: contentType.uid, pattern: e.target.value } }),
|
|
130
|
+
disabled: !contentTypeSettings.default,
|
|
131
|
+
type: "text",
|
|
132
|
+
placeholder: formatMessage({
|
|
133
|
+
id: getTranslation("settings.page.urlAliasPattern.placeholder"),
|
|
134
|
+
defaultMessage: "e.g. blog"
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
) })
|
|
142
|
+
] }) })
|
|
143
|
+
] }, contentType.uid)
|
|
144
|
+
},
|
|
145
|
+
contentType.uid
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
function reducer(settingsState, action) {
|
|
149
|
+
let updatedContentTypes;
|
|
150
|
+
switch (action.type) {
|
|
151
|
+
case "SET_SELECTED_CONTENT_TYPES":
|
|
152
|
+
updatedContentTypes = action.payload.map((ct) => {
|
|
153
|
+
return settingsState.selectedContentTypes.find((cta) => cta.uid === ct.uid) || ct;
|
|
154
|
+
});
|
|
155
|
+
return { ...settingsState, selectedContentTypes: updatedContentTypes };
|
|
156
|
+
case "SET_DEFAULT_FIELD":
|
|
157
|
+
updatedContentTypes = settingsState.selectedContentTypes.map(
|
|
158
|
+
(ct) => ct.uid === action.payload.ctUid ? { ...ct, default: action.payload.field } : ct
|
|
159
|
+
);
|
|
160
|
+
return { ...settingsState, selectedContentTypes: updatedContentTypes };
|
|
161
|
+
case "SET_PATTERN":
|
|
162
|
+
updatedContentTypes = settingsState.selectedContentTypes.map(
|
|
163
|
+
(ct) => ct.uid === action.payload.ctUid ? { ...ct, pattern: transformToUrl(action.payload.pattern) } : ct
|
|
164
|
+
);
|
|
165
|
+
return { ...settingsState, selectedContentTypes: updatedContentTypes };
|
|
166
|
+
default:
|
|
167
|
+
throw new Error();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const Settings = () => {
|
|
171
|
+
const { config, setConfig, loading, fetchError } = usePluginConfig();
|
|
172
|
+
const [settingsState, dispatch] = useReducer(reducer, config || { selectedContentTypes: [] });
|
|
173
|
+
const { contentTypes: allContentTypesData } = useAllContentTypes();
|
|
174
|
+
const allContentTypes = allContentTypesData?.filter((ct) => ct.pluginOptions?.webatlas?.active === true);
|
|
175
|
+
const [initialState, setInitialState] = useState(config || { selectedContentTypes: [] });
|
|
176
|
+
const { toggleNotification } = useNotification();
|
|
177
|
+
const { formatMessage } = useIntl();
|
|
178
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
setInitialState(config || { selectedContentTypes: [] });
|
|
181
|
+
}, [config]);
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (!config) return;
|
|
184
|
+
dispatch({ type: "SET_SELECTED_CONTENT_TYPES", payload: config.selectedContentTypes });
|
|
185
|
+
}, [config]);
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
if (fetchError) {
|
|
188
|
+
toggleNotification({
|
|
189
|
+
type: "danger",
|
|
190
|
+
message: formatMessage({
|
|
191
|
+
id: getTranslation("notification.error"),
|
|
192
|
+
defaultMessage: "An error occurred"
|
|
193
|
+
}) + ": " + fetchError
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}, [fetchError, toggleNotification, formatMessage]);
|
|
197
|
+
async function save() {
|
|
198
|
+
if (!settingsState || settingsState.selectedContentTypes.find((cta) => !cta.default) !== void 0) return;
|
|
199
|
+
setIsSaving(true);
|
|
200
|
+
try {
|
|
201
|
+
await setConfig(settingsState);
|
|
202
|
+
setInitialState(settingsState);
|
|
203
|
+
toggleNotification({
|
|
204
|
+
type: "success",
|
|
205
|
+
message: formatMessage({
|
|
206
|
+
id: getTranslation("notification.settings.saved"),
|
|
207
|
+
defaultMessage: "Settings saved successfully"
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
setIsSaving(false);
|
|
211
|
+
} catch (err) {
|
|
212
|
+
setIsSaving(false);
|
|
213
|
+
toggleNotification({
|
|
214
|
+
type: "danger",
|
|
215
|
+
message: formatMessage({
|
|
216
|
+
id: getTranslation("notification.error"),
|
|
217
|
+
defaultMessage: "An error occurred"
|
|
218
|
+
}) + ": " + err
|
|
219
|
+
});
|
|
220
|
+
console.error(err);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (loading) {
|
|
224
|
+
return /* @__PURE__ */ jsx(PageWrapper, { children: /* @__PURE__ */ jsx(FullLoader, { height: 200 }) });
|
|
225
|
+
}
|
|
226
|
+
return /* @__PURE__ */ jsxs(PageWrapper, { settingsState, initialState, save, isSaving, children: [
|
|
227
|
+
/* @__PURE__ */ jsxs(
|
|
228
|
+
Field.Root,
|
|
229
|
+
{
|
|
230
|
+
name: "selectedContentTypes",
|
|
231
|
+
hint: formatMessage({
|
|
232
|
+
id: getTranslation("settings.page.enabledContentTypes.hint"),
|
|
233
|
+
defaultMessage: "Select the content types for which you want to enable URL aliases"
|
|
234
|
+
}),
|
|
235
|
+
children: [
|
|
236
|
+
/* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
|
|
237
|
+
id: getTranslation("settings.page.enabledContentTypes"),
|
|
238
|
+
defaultMessage: "Enabled Content Types"
|
|
239
|
+
}) }),
|
|
240
|
+
/* @__PURE__ */ jsx(
|
|
241
|
+
MultiSelect,
|
|
242
|
+
{
|
|
243
|
+
placeholder: formatMessage({
|
|
244
|
+
id: getTranslation("settings.page.enabledContentTypes.placeholder"),
|
|
245
|
+
defaultMessage: "Select content types..."
|
|
246
|
+
}),
|
|
247
|
+
onClear: () => dispatch({ type: "SET_SELECTED_CONTENT_TYPES", payload: [] }),
|
|
248
|
+
value: [...settingsState.selectedContentTypes.map((ct) => ct.uid)],
|
|
249
|
+
onChange: (value) => dispatch({
|
|
250
|
+
type: "SET_SELECTED_CONTENT_TYPES",
|
|
251
|
+
payload: value.map((v) => ({
|
|
252
|
+
uid: v,
|
|
253
|
+
default: "",
|
|
254
|
+
pattern: ""
|
|
255
|
+
}))
|
|
256
|
+
}),
|
|
257
|
+
withTags: true,
|
|
258
|
+
children: allContentTypes && allContentTypes.map(
|
|
259
|
+
(item) => /* @__PURE__ */ jsx(MultiSelectOption, { value: item.uid, children: item.info.displayName }, item.uid)
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
),
|
|
267
|
+
settingsState.selectedContentTypes && settingsState.selectedContentTypes.length > 0 && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsxs(Field.Root, { name: "selectedContentTypesAccordion", children: [
|
|
268
|
+
/* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
|
|
269
|
+
id: getTranslation("settings.page.contentTypeSettings"),
|
|
270
|
+
defaultMessage: "Content Type settings"
|
|
271
|
+
}) }),
|
|
272
|
+
/* @__PURE__ */ jsx(Accordion.Root, { children: settingsState.selectedContentTypes?.map((contentTypeSettings) => {
|
|
273
|
+
const ct = allContentTypes?.find((item) => item.uid === contentTypeSettings.uid);
|
|
274
|
+
return /* @__PURE__ */ jsx(ContentTypeAccordion, { contentType: ct, contentTypeSettings, dispatch }, contentTypeSettings.uid);
|
|
275
|
+
}) })
|
|
276
|
+
] }) })
|
|
277
|
+
] });
|
|
278
|
+
};
|
|
279
|
+
export {
|
|
280
|
+
Settings as default
|
|
281
|
+
};
|
|
282
|
+
//# sourceMappingURL=index-DKWn1eh9.mjs.map
|