datastake-daf 0.6.819 → 0.6.821
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/components/index.js +2264 -1099
- package/dist/hooks/index.js +16 -5
- package/dist/pages/index.js +251 -65
- package/dist/services/index.js +104 -9
- package/dist/utils/index.js +75 -8
- package/package.json +1 -1
- package/src/@daf/core/components/AuthForm/index.jsx +12 -3
- package/src/@daf/core/components/DynamicForm/_index.scss +1 -3
- package/src/@daf/core/components/EditForm/_index.scss +0 -4
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/hook.js +27 -1
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/index.jsx +2 -3
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/hook.js +0 -1
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/index.jsx +1 -3
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/index.jsx +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminModals/AddAccount/index.jsx +82 -10
- package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/index.jsx +51 -51
- package/src/@daf/core/components/Screens/Admin/AdminModals/CombineSubjects/index.jsx +6 -1
- package/src/@daf/core/components/Screens/Admin/AdminModals/NewAccount/index.jsx +53 -31
- package/src/@daf/core/components/Screens/Admin/AdminModals/NewUser/index.jsx +36 -10
- package/src/@daf/core/components/Screens/Admin/AdminModals/TransferRights/index.jsx +2 -2
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Accounts.jsx +37 -10
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Dashboard.jsx +2 -2
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Documents.jsx +81 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Events.jsx +77 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/index.js +2 -1
- package/src/@daf/core/components/Screens/Admin/AdminTables/AccountTable/helper.js +22 -30
- package/src/@daf/core/components/Screens/Admin/AdminTables/AccountTable/index.jsx +28 -16
- package/src/@daf/core/components/Screens/Admin/AdminTables/DocumentsTable/column.js +93 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/DocumentsTable/helper.js +43 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/DocumentsTable/index.jsx +201 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/EventsTable/column.js +113 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/EventsTable/helper.js +58 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/EventsTable/index.jsx +176 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/helper.js +3 -6
- package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/index.jsx +17 -2
- package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/helper.js +3 -6
- package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/index.jsx +27 -13
- package/src/@daf/core/components/Screens/Admin/AdminTables/UserTable/index.jsx +0 -1
- package/src/@daf/core/components/Screens/Admin/AdminTables/components/index.jsx +4 -2
- package/src/@daf/core/components/Screens/Admin/AdminTables/hook.js +3 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/Edit/index.jsx +21 -9
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/helper.js +16 -11
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/index.jsx +16 -4
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/View/helpers.js +9 -17
- package/src/@daf/core/components/Screens/Admin/AdminViews/index.jsx +12 -16
- package/src/@daf/core/components/Screens/Admin/AppInvitation/index.jsx +124 -99
- package/src/@daf/core/components/Screens/Admin/adminRoutes.js +44 -28
- package/src/@daf/hooks/useAdminDashboard.js +7 -4
- package/src/@daf/hooks/useSources.js +2 -1
- package/src/@daf/pages/Events/columns.js +15 -3
- package/src/@daf/pages/Locations/MineSite/columns.js +18 -1
- package/src/@daf/pages/TablePage/columns.js +2 -0
- package/src/@daf/pages/TablePage/hook.js +0 -2
- package/src/@daf/pages/View/hooks/useViewActions.js +13 -0
- package/src/@daf/pages/View/hooks/useViewPermissions.js +16 -0
- package/src/@daf/pages/View/index.jsx +32 -4
- package/src/@daf/services/AdminService.js +80 -8
- package/src/@daf/services/DashboardService.js +3 -3
- package/src/@daf/utils/filters.js +13 -15
- package/src/constants/locales/en/translation.js +24 -4
- package/src/constants/locales/fr/translation.js +17 -0
- package/src/constants/locales/sp/translation.js +28 -7
- package/src/helpers/copyToClipboard.js +60 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/SubjectsView.jsx +0 -395
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/configTransformer.js +0 -137
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/index.js +0 -9
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/index.jsx +0 -196
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/configTransformer.js +0 -216
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/index.js +0 -7
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/index.jsx +0 -184
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/config.js +0 -64
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/helpers.js +0 -10
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/index.jsx +0 -77
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/config.js +0 -51
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/helpers.js +0 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/index.jsx +0 -76
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useCallback, useMemo } from "react";
|
|
2
|
-
import Header from "../../../Header/index.jsx";
|
|
3
|
-
import Loading from "../../../Loading/index.jsx";
|
|
4
|
-
import SideBarMenu from "../AdminViews/components/SidebarMenu/index.jsx";
|
|
5
|
-
import ViewLocation from "../AdminViews/ViewLocation/index.jsx";
|
|
6
|
-
import ViewStakeholder from "../AdminViews/ViewStakeholder/index.jsx";
|
|
7
|
-
import EditLocation from "../AdminViews/EditLocation/index.jsx";
|
|
8
|
-
import EditStakeholder from "../AdminViews/EditStakeholder/index.jsx";
|
|
9
|
-
import { config as locationConfig } from "../AdminViews/ViewLocation/config.js";
|
|
10
|
-
import { config as stakeholderConfig } from "../AdminViews/ViewStakeholder/config.js";
|
|
11
|
-
import NotFound from "../../NotFound/index.jsx";
|
|
12
|
-
import { Form, message, Modal } from "antd";
|
|
13
|
-
import { ExclamationCircleOutlined } from "@ant-design/icons";
|
|
14
|
-
import { NOTIFICATION_MODE, useForms, FormsProvider } from "../../../../context/Forms/index.js";
|
|
15
|
-
import { getMainApiUrl, getAppHeader as getBaseAppHeader } from "../../../../../services/BaseService.js";
|
|
16
|
-
|
|
17
|
-
function withFormsProvider(Component) {
|
|
18
|
-
return function WrappedWithFormsProvider(props) {
|
|
19
|
-
return (
|
|
20
|
-
<FormsProvider>
|
|
21
|
-
<Component {...props} />
|
|
22
|
-
</FormsProvider>
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function normalizeFormData(data) {
|
|
29
|
-
if (!data || typeof data !== 'object') {
|
|
30
|
-
return data;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const normalized = { ...data };
|
|
34
|
-
|
|
35
|
-
Object.keys(normalized).forEach(key => {
|
|
36
|
-
const value = normalized[key];
|
|
37
|
-
|
|
38
|
-
if (value === null || value === undefined) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
if (value.length > 0 && typeof value[0] === 'object' && value[0] !== null) {
|
|
44
|
-
if ('value' in value[0]) {
|
|
45
|
-
normalized[key] = value.map(item => item.value);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (typeof value === 'object' && 'value' in value) {
|
|
52
|
-
normalized[key] = value.value;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return normalized;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Admin Subjects View Screen
|
|
61
|
-
* This component handles viewing and editing individual subjects (locations or stakeholders)
|
|
62
|
-
*
|
|
63
|
-
* @param {Object} config - Application configuration
|
|
64
|
-
* @param {string} config.subject - Subject type: "location" or "stakeholder"
|
|
65
|
-
* @param {string} config.id - Subject ID from route params
|
|
66
|
-
* @param {string} config.mode - Mode: "view" or "edit"
|
|
67
|
-
* @param {string} config.module - Module identifier
|
|
68
|
-
* @param {Function} config.goTo - Navigation function
|
|
69
|
-
* @param {Function} config.t - Translation function
|
|
70
|
-
* @param {Object} config.location - Router location object
|
|
71
|
-
* @param {Function} config.getRedirectLink - Function to get redirect links
|
|
72
|
-
* @param {Function} config.renderBreadCrumbs - Function to render breadcrumbs
|
|
73
|
-
* @param {Object} config.options - Options object with countries, categories, etc.
|
|
74
|
-
* @param {Function} config.AdminService - Admin service for API calls
|
|
75
|
-
* @param {Function} config.handleError - Error handling function
|
|
76
|
-
*/
|
|
77
|
-
function AdminSubjectsViewScreen({ config }) {
|
|
78
|
-
const {
|
|
79
|
-
subject,
|
|
80
|
-
id,
|
|
81
|
-
mode = "view",
|
|
82
|
-
module,
|
|
83
|
-
goTo,
|
|
84
|
-
t,
|
|
85
|
-
location,
|
|
86
|
-
getRedirectLink,
|
|
87
|
-
renderBreadCrumbs,
|
|
88
|
-
options,
|
|
89
|
-
AdminService,
|
|
90
|
-
handleError,
|
|
91
|
-
userRoles = [],
|
|
92
|
-
accountStatuses = [],
|
|
93
|
-
getApiBaseUrl = getMainApiUrl,
|
|
94
|
-
getAppHeader = getBaseAppHeader,
|
|
95
|
-
} = config;
|
|
96
|
-
|
|
97
|
-
const [loading, setLoading] = useState(false);
|
|
98
|
-
const [data, setData] = useState({});
|
|
99
|
-
const [editData, setEditData] = useState({});
|
|
100
|
-
const [isChanged, setIsChanged] = useState(false);
|
|
101
|
-
const [selectedGroup, setSelectedGroup] = useState("");
|
|
102
|
-
const [MainForm] = Form.useForm();
|
|
103
|
-
const { setNotificationMode, changeNotificationState, ajaxForms } = useForms();
|
|
104
|
-
|
|
105
|
-
const configs = useMemo(() => {
|
|
106
|
-
return subject === "location" ? locationConfig : stakeholderConfig;
|
|
107
|
-
}, [subject]);
|
|
108
|
-
|
|
109
|
-
const conf = useMemo(() => {
|
|
110
|
-
if (!Array.isArray(configs) || configs.length === 0) {
|
|
111
|
-
console.warn("configs is not a valid array:", configs);
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!selectedGroup) {
|
|
116
|
-
setSelectedGroup(configs[0].key);
|
|
117
|
-
return configs[0];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const foundConfig = configs.find((c) => c.key === selectedGroup);
|
|
121
|
-
return foundConfig || configs[0];
|
|
122
|
-
}, [selectedGroup, configs]);
|
|
123
|
-
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
const normalizedData = normalizeFormData(data);
|
|
126
|
-
|
|
127
|
-
console.log(' Form Data Normalization:', {
|
|
128
|
-
rawData: data,
|
|
129
|
-
normalizedData: normalizedData,
|
|
130
|
-
changes: Object.keys(data).filter(key =>
|
|
131
|
-
JSON.stringify(data[key]) !== JSON.stringify(normalizedData[key])
|
|
132
|
-
).map(key => ({
|
|
133
|
-
field: key,
|
|
134
|
-
original: data[key],
|
|
135
|
-
normalized: normalizedData[key]
|
|
136
|
-
}))
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
MainForm.setFieldsValue(normalizedData);
|
|
140
|
-
setEditData(normalizedData);
|
|
141
|
-
}, [data, MainForm]);
|
|
142
|
-
|
|
143
|
-
const goToView = useCallback(() => {
|
|
144
|
-
changeNotificationState({
|
|
145
|
-
onYes: () => {
|
|
146
|
-
setEditData(data);
|
|
147
|
-
setIsChanged(false);
|
|
148
|
-
goTo(`/app/view/management-${subject}/${id}`);
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
}, [goTo, changeNotificationState, data, subject, id]);
|
|
152
|
-
|
|
153
|
-
const fetchData = useCallback(async () => {
|
|
154
|
-
try {
|
|
155
|
-
setLoading(true);
|
|
156
|
-
|
|
157
|
-
let response;
|
|
158
|
-
if (subject === "location") {
|
|
159
|
-
response = await AdminService.viewLocation({ id });
|
|
160
|
-
} else if (subject === "stakeholder") {
|
|
161
|
-
response = await AdminService.viewStakeholder({ id });
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (response?.data) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (!response.data.id) {
|
|
168
|
-
console.error(' Warning: Backend response missing UUID (id field). Only datastakeId present:', {
|
|
169
|
-
datastakeId: response.data.datastakeId,
|
|
170
|
-
fullData: response.data
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
setData(response.data);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
setLoading(false);
|
|
178
|
-
} catch (err) {
|
|
179
|
-
if (handleError) {
|
|
180
|
-
handleError(err);
|
|
181
|
-
}
|
|
182
|
-
setLoading(false);
|
|
183
|
-
}
|
|
184
|
-
}, [id, subject, AdminService, handleError]);
|
|
185
|
-
|
|
186
|
-
useEffect(() => {
|
|
187
|
-
fetchData();
|
|
188
|
-
}, [fetchData]);
|
|
189
|
-
|
|
190
|
-
const breadCrumbs = useMemo(() => {
|
|
191
|
-
if (renderBreadCrumbs) {
|
|
192
|
-
return renderBreadCrumbs({
|
|
193
|
-
view: subject === "location" ? "location" : "stakeholder",
|
|
194
|
-
t,
|
|
195
|
-
goTo,
|
|
196
|
-
id,
|
|
197
|
-
isView: mode === "view",
|
|
198
|
-
isEdit: mode === "edit",
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return [];
|
|
202
|
-
}, [renderBreadCrumbs, subject, t, goTo, id, mode]);
|
|
203
|
-
|
|
204
|
-
const formOptions = useMemo(() => {
|
|
205
|
-
const opts = options || {};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
...opts,
|
|
210
|
-
|
|
211
|
-
countries: opts.countries || [],
|
|
212
|
-
// category: opts.categoriesOptions || [],
|
|
213
|
-
locationCategories: opts.locationCategories || [],
|
|
214
|
-
|
|
215
|
-
};
|
|
216
|
-
}, [options]);
|
|
217
|
-
|
|
218
|
-
const handleDelete = useCallback(() => {
|
|
219
|
-
const subjectName = subject === "location" ? t("location") : t("stakeholder");
|
|
220
|
-
|
|
221
|
-
Modal.confirm({
|
|
222
|
-
title: t("Delete") + " " + subjectName,
|
|
223
|
-
icon: <ExclamationCircleOutlined />,
|
|
224
|
-
content: t(`Are you sure you want to delete this ${subjectName}? This action cannot be undone.`),
|
|
225
|
-
okText: t("Delete"),
|
|
226
|
-
okType: "danger",
|
|
227
|
-
cancelText: t("Cancel"),
|
|
228
|
-
onOk: async () => {
|
|
229
|
-
setLoading(true);
|
|
230
|
-
try {
|
|
231
|
-
const uuid = data.id;
|
|
232
|
-
|
|
233
|
-
if (!uuid) {
|
|
234
|
-
throw new Error('UUID not found in subject data');
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
await AdminService.deleteSubject({
|
|
238
|
-
subject,
|
|
239
|
-
id: uuid
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
message.success(t(`${subjectName} deleted successfully`));
|
|
243
|
-
goTo(`/app/management/subject/${subject}`);
|
|
244
|
-
} catch (err) {
|
|
245
|
-
handleError(err);
|
|
246
|
-
setLoading(false);
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
});
|
|
250
|
-
}, [subject, data, AdminService, handleError, t, goTo]);
|
|
251
|
-
|
|
252
|
-
const actionButtons = useMemo(() => {
|
|
253
|
-
if (mode === "view") {
|
|
254
|
-
return [
|
|
255
|
-
{
|
|
256
|
-
type: "primary",
|
|
257
|
-
tooltip: t("Edit"),
|
|
258
|
-
icon: "Edit",
|
|
259
|
-
onClick: () => goTo(`/app/edit/management-${subject}/${id}`),
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
type: "danger",
|
|
263
|
-
tooltip: t("Delete"),
|
|
264
|
-
icon: "Delete",
|
|
265
|
-
onClick: handleDelete,
|
|
266
|
-
},
|
|
267
|
-
];
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return [
|
|
271
|
-
{
|
|
272
|
-
type: "primary",
|
|
273
|
-
tooltip: t("Save"),
|
|
274
|
-
icon: "Save",
|
|
275
|
-
disabled: !isChanged,
|
|
276
|
-
onClick: () => {
|
|
277
|
-
MainForm.validateFields()
|
|
278
|
-
.then(async (formData) => {
|
|
279
|
-
setLoading(true);
|
|
280
|
-
|
|
281
|
-
try {
|
|
282
|
-
const allowedKeys = conf?.items?.map(item => item.key) || [];
|
|
283
|
-
const filteredData = {};
|
|
284
|
-
allowedKeys.forEach(key => {
|
|
285
|
-
if (formData[key] !== undefined) {
|
|
286
|
-
filteredData[key] = formData[key];
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
const uuid = editData.id || data.id;
|
|
291
|
-
|
|
292
|
-
console.log('🔍 Debug - Save operation:', {
|
|
293
|
-
editDataId: editData.id,
|
|
294
|
-
dataId: data.id,
|
|
295
|
-
editDataDatastakeId: editData.datastakeId,
|
|
296
|
-
dataDatastakeId: data.datastakeId,
|
|
297
|
-
uuidUsed: uuid,
|
|
298
|
-
routeParamId: id
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
if (!uuid) {
|
|
302
|
-
console.error('UUID not found. Available data:', {
|
|
303
|
-
editData,
|
|
304
|
-
data,
|
|
305
|
-
routeParamId: id
|
|
306
|
-
});
|
|
307
|
-
throw new Error('UUID not found in subject data. Please refresh the page and try again.');
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
if (typeof uuid !== 'string' || uuid.length < 20) {
|
|
311
|
-
console.error('Invalid UUID format detected:', uuid);
|
|
312
|
-
throw new Error('Invalid UUID format');
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
await AdminService.updateSubject({
|
|
316
|
-
subject,
|
|
317
|
-
id: uuid,
|
|
318
|
-
data: filteredData
|
|
319
|
-
});
|
|
320
|
-
await fetchData();
|
|
321
|
-
message.success(t("Information saved successfully"));
|
|
322
|
-
setNotificationMode(NOTIFICATION_MODE.EMPTY);
|
|
323
|
-
setIsChanged(false);
|
|
324
|
-
goTo(`/app/view/management-${subject}/${id}`);
|
|
325
|
-
} catch (err) {
|
|
326
|
-
handleError(err);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
setLoading(false);
|
|
330
|
-
})
|
|
331
|
-
.catch(() => {});
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
tooltip: t("Cancel"),
|
|
336
|
-
icon: "Close",
|
|
337
|
-
onClick: goToView,
|
|
338
|
-
},
|
|
339
|
-
];
|
|
340
|
-
}, [t, mode, MainForm, goToView, isChanged, editData, fetchData, subject, id, goTo, handleError, AdminService, setNotificationMode, data, conf, handleDelete]);
|
|
341
|
-
|
|
342
|
-
const ViewComponent = subject === "location" ? ViewLocation : ViewStakeholder;
|
|
343
|
-
const EditComponent = subject === "location" ? EditLocation : EditStakeholder;
|
|
344
|
-
|
|
345
|
-
return (
|
|
346
|
-
<div className={mode === "view" ? "daf-view-form" : "daf-edit-form"}>
|
|
347
|
-
{loading && <Loading background="white" />}
|
|
348
|
-
<Header
|
|
349
|
-
title={data.name || t("Loading...")}
|
|
350
|
-
breadcrumbs={breadCrumbs}
|
|
351
|
-
actionButtons={actionButtons}
|
|
352
|
-
/>
|
|
353
|
-
<div className="view-content">
|
|
354
|
-
<SideBarMenu
|
|
355
|
-
selectedGroup={selectedGroup}
|
|
356
|
-
onChange={(v) => setSelectedGroup(v)}
|
|
357
|
-
t={t}
|
|
358
|
-
config={configs}
|
|
359
|
-
/>
|
|
360
|
-
{mode === "edit" ? (
|
|
361
|
-
<EditComponent
|
|
362
|
-
t={t}
|
|
363
|
-
conf={conf}
|
|
364
|
-
data={editData}
|
|
365
|
-
formOptions={formOptions}
|
|
366
|
-
MainForm={MainForm}
|
|
367
|
-
setData={setEditData}
|
|
368
|
-
isChanged={isChanged}
|
|
369
|
-
setIsChanged={setIsChanged}
|
|
370
|
-
goToView={goToView}
|
|
371
|
-
getApiBaseUrl={getApiBaseUrl}
|
|
372
|
-
getAppHeader={getAppHeader}
|
|
373
|
-
ajaxForms={ajaxForms}
|
|
374
|
-
/>
|
|
375
|
-
) : (
|
|
376
|
-
<ViewComponent
|
|
377
|
-
userRoles={userRoles}
|
|
378
|
-
formOptions={formOptions}
|
|
379
|
-
conf={conf}
|
|
380
|
-
data={data}
|
|
381
|
-
t={t}
|
|
382
|
-
goTo={goTo}
|
|
383
|
-
location={location}
|
|
384
|
-
getRedirectLink={getRedirectLink}
|
|
385
|
-
accountStatuses={accountStatuses}
|
|
386
|
-
module={module}
|
|
387
|
-
/>
|
|
388
|
-
)}
|
|
389
|
-
</div>
|
|
390
|
-
</div>
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export default withFormsProvider(AdminSubjectsViewScreen);
|
|
395
|
-
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function transformConfigItem(item, formOptions = {}, t = (s) => s) {
|
|
3
|
-
const {
|
|
4
|
-
key,
|
|
5
|
-
label,
|
|
6
|
-
type,
|
|
7
|
-
optionsName,
|
|
8
|
-
level,
|
|
9
|
-
placeholder,
|
|
10
|
-
rules,
|
|
11
|
-
showFormIf,
|
|
12
|
-
disabled,
|
|
13
|
-
defaultValue,
|
|
14
|
-
meta: configMeta = {},
|
|
15
|
-
...rest
|
|
16
|
-
} = item;
|
|
17
|
-
|
|
18
|
-
const option = {
|
|
19
|
-
type: type || "text",
|
|
20
|
-
label: label,
|
|
21
|
-
meta: { ...configMeta },
|
|
22
|
-
...rest,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
if (placeholder) option.placeholder = placeholder;
|
|
26
|
-
if (rules && Array.isArray(rules)) option.rules = rules;
|
|
27
|
-
if (showFormIf) option.showFormIf = showFormIf;
|
|
28
|
-
if (disabled !== undefined) {
|
|
29
|
-
option.disabled = disabled;
|
|
30
|
-
option.meta.disableEdit = disabled;
|
|
31
|
-
}
|
|
32
|
-
if (defaultValue !== undefined) option.meta.defaultValue = defaultValue;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const mapOptions = (sourceKey) => {
|
|
36
|
-
if (sourceKey && formOptions[sourceKey]) {
|
|
37
|
-
return formOptions[sourceKey].map((opt) => {
|
|
38
|
-
if (typeof opt === 'object' && opt !== null) {
|
|
39
|
-
return {
|
|
40
|
-
value: opt.value,
|
|
41
|
-
label: t(opt.label || opt.value),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return { value: opt, label: t(opt) };
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return [];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (type === "select" || type === "multiselect") {
|
|
52
|
-
option.options = mapOptions(optionsName || level);
|
|
53
|
-
|
|
54
|
-
if (option.options.length === 0) {
|
|
55
|
-
console.warn(`No options found for field "${key}"`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (type === "multiselect") {
|
|
59
|
-
option.mode = "multiple";
|
|
60
|
-
option.type = "select";
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (type === "ajaxSelect") {
|
|
65
|
-
const { entity, method, mapper, filters } = item;
|
|
66
|
-
|
|
67
|
-
if (!entity || !method || !mapper) {
|
|
68
|
-
console.error(`ajaxSelect field "${key}" is missing properties`);
|
|
69
|
-
option.type = "text";
|
|
70
|
-
option.disabled = true;
|
|
71
|
-
} else {
|
|
72
|
-
const filtersString = filters ? JSON.stringify(filters) : "{}";
|
|
73
|
-
const mapperString = JSON.stringify(mapper);
|
|
74
|
-
option.meta.call = `${entity}::${method}(${filtersString})::${mapperString}`;
|
|
75
|
-
option.type = "ajaxSelect";
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (optionsName || level) {
|
|
79
|
-
option.options = mapOptions(optionsName || level);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (option.meta.noAddNew) {
|
|
83
|
-
option.onNewSetValue = false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (type === "administrative") {
|
|
89
|
-
option.type = "text";
|
|
90
|
-
option.disabled = true;
|
|
91
|
-
option.meta.disableEdit = false;
|
|
92
|
-
if (level) option.meta.level = level;
|
|
93
|
-
}
|
|
94
|
-
if (type === "switch" || type === "checkbox") {
|
|
95
|
-
option.type = type;
|
|
96
|
-
if (defaultValue === undefined) option.meta.defaultValue = false;
|
|
97
|
-
}
|
|
98
|
-
if (type === "date" || type === "datetime" || type === "year") option.type = type;
|
|
99
|
-
if (type === "textarea") {
|
|
100
|
-
option.type = "textarea";
|
|
101
|
-
option.rows = item.rows || 4;
|
|
102
|
-
}
|
|
103
|
-
if (type === "number") {
|
|
104
|
-
option.type = "text";
|
|
105
|
-
option.meta.inputType = "number";
|
|
106
|
-
}
|
|
107
|
-
if (option.position === undefined) option.position = 0;
|
|
108
|
-
|
|
109
|
-
return option;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function transformConfigToEditForm(conf, formOptions = {}, t = (s) => s) {
|
|
113
|
-
if (!conf || !conf.items || !Array.isArray(conf.items)) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const options = {};
|
|
118
|
-
conf.items.forEach((item, index) => {
|
|
119
|
-
const transformedOption = transformConfigItem(item, formOptions, t);
|
|
120
|
-
transformedOption.position = item.position !== undefined ? item.position : index;
|
|
121
|
-
options[item.key] = transformedOption;
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
id: conf.key || "edit-form",
|
|
126
|
-
introText: "",
|
|
127
|
-
formTitles: conf.formTitles || {},
|
|
128
|
-
options,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function getConfigFieldKeys(conf) {
|
|
133
|
-
if (!conf || !conf.items || !Array.isArray(conf.items)) {
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
return conf.items.map((item) => item.key);
|
|
137
|
-
}
|