@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,139 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useReducer, useState, useRef, useEffect } from "react";
3
- import { Field } from "@strapi/design-system";
4
- import { useNotification, Page } from "@strapi/strapi/admin";
5
- import { c as usePluginConfig, g as getTranslation, p as pluginPermissions } 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
- function reducer(newConfig, action) {
11
- switch (action.type) {
12
- case "SET_MAX_DEPTH":
13
- if (!newConfig) return null;
14
- return {
15
- ...newConfig,
16
- navigation: { ...newConfig.navigation, maxDepth: action.payload },
17
- selectedContentTypes: newConfig.selectedContentTypes || []
18
- };
19
- case "SET_CONFIG":
20
- return action.payload;
21
- default:
22
- throw new Error();
23
- }
24
- }
25
- const Settings = () => {
26
- const { config: fetchedConfig, setConfig, loading, fetchError } = usePluginConfig();
27
- const [config, dispatch] = useReducer(reducer, fetchedConfig);
28
- const { toggleNotification } = useNotification();
29
- const { formatMessage } = useIntl();
30
- const [isSaving, setIsSaving] = useState(false);
31
- const initialConfig = useRef(fetchedConfig);
32
- useEffect(() => {
33
- initialConfig.current = fetchedConfig;
34
- if (fetchedConfig) dispatch({ type: "SET_CONFIG", payload: fetchedConfig });
35
- }, [fetchedConfig]);
36
- useEffect(() => {
37
- if (fetchError) {
38
- toggleNotification({
39
- type: "danger",
40
- message: formatMessage({
41
- id: getTranslation("notification.error"),
42
- defaultMessage: "An error occurred"
43
- }) + ": " + fetchError
44
- });
45
- }
46
- }, [fetchError, toggleNotification, formatMessage]);
47
- async function save() {
48
- if (!config) return;
49
- setIsSaving(true);
50
- try {
51
- await setConfig({ navigation: config.navigation });
52
- initialConfig.current = config;
53
- toggleNotification({
54
- type: "success",
55
- message: formatMessage({
56
- id: getTranslation("notification.settings.saved"),
57
- defaultMessage: "Settings saved successfully"
58
- })
59
- });
60
- setIsSaving(false);
61
- } catch (err) {
62
- setIsSaving(false);
63
- toggleNotification({
64
- type: "danger",
65
- message: formatMessage({
66
- id: getTranslation("notification.error"),
67
- defaultMessage: "An error occurred"
68
- }) + ": " + err
69
- });
70
- strapi.log.error(err);
71
- }
72
- }
73
- if (loading) {
74
- return /* @__PURE__ */ jsx(
75
- PageWrapper,
76
- {
77
- isSaving,
78
- subtitle: formatMessage({
79
- id: getTranslation("loading"),
80
- defaultMessage: "Loading..."
81
- }),
82
- disabledCondition: true,
83
- children: /* @__PURE__ */ jsx(FullLoader, { height: 200 })
84
- }
85
- );
86
- }
87
- return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions["settings.navigation"], children: /* @__PURE__ */ jsx(
88
- PageWrapper,
89
- {
90
- save,
91
- isSaving,
92
- subtitle: formatMessage({
93
- id: getTranslation("settings.page.navigation.subtitle"),
94
- defaultMessage: "Configure navigation settings"
95
- }),
96
- disabledCondition: JSON.stringify(config) === JSON.stringify(initialConfig.current),
97
- children: /* @__PURE__ */ jsx(
98
- ContentBox,
99
- {
100
- title: formatMessage({
101
- id: getTranslation("settings.page.navigation.navigation"),
102
- defaultMessage: "Navigation"
103
- }),
104
- children: /* @__PURE__ */ jsxs(Field.Root, { name: "maxNavDepth", children: [
105
- /* @__PURE__ */ jsx(Field.Label, { children: /* @__PURE__ */ jsx(SettingTitle, { children: formatMessage({
106
- id: getTranslation("settings.page.navigation.maxNavDepth.label"),
107
- defaultMessage: "Max depth of navigation tree"
108
- }) }) }),
109
- /* @__PURE__ */ jsx(
110
- Field.Input,
111
- {
112
- id: "maxNavDepth",
113
- type: "number",
114
- min: 0,
115
- step: 1,
116
- value: config?.navigation?.maxDepth !== void 0 ? config.navigation.maxDepth + 1 : "",
117
- onChange: (e) => dispatch({
118
- type: "SET_MAX_DEPTH",
119
- payload: Number(e.target.value) - 1
120
- }),
121
- onBlur: (e) => {
122
- if (e.target.value === "") return;
123
- dispatch({
124
- type: "SET_MAX_DEPTH",
125
- payload: Number(e.target.value) - 1
126
- });
127
- }
128
- }
129
- ),
130
- /* @__PURE__ */ jsx(Field.Hint, {})
131
- ] })
132
- }
133
- )
134
- }
135
- ) });
136
- };
137
- export {
138
- Settings as default
139
- };