@bindu-dashing/dam-solution-v2 5.9.224 → 5.9.227
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.
|
@@ -11,20 +11,40 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
import { Button, Checkbox, Form, Input } from "antd";
|
|
12
12
|
import TextField from "./fieldProperties/TextField";
|
|
13
13
|
import NumberField from "./fieldProperties/NumberField";
|
|
14
|
-
import { useEffect, useState } from "react";
|
|
14
|
+
import { useEffect, useMemo, useState } from "react";
|
|
15
15
|
import DateField from "./fieldProperties/DateField";
|
|
16
16
|
import OptionsField from "./fieldProperties/OptionsField";
|
|
17
17
|
import { InputSupportedTypes, InputTypes, NotificationStatus, } from "../utilities/constants/interface";
|
|
18
|
-
import { first, get, includes, isArray, nth } from "lodash";
|
|
18
|
+
import { first, get, includes, isArray, map, nth } from "lodash";
|
|
19
19
|
import { useDamConfig } from "../hocs/DamConfigContext";
|
|
20
20
|
import useAppNavigate from "../utilities/useAppNavigate";
|
|
21
21
|
import { getFormItem } from "../MyDrive/fileDetails/MetaForm";
|
|
22
|
+
import { useQueryClient } from "react-query";
|
|
23
|
+
import { getCurrentBrandUsers } from "../react-query/hooks/brand-hooks";
|
|
24
|
+
import { getUserAvatar } from "../settings/getUserAvatar";
|
|
22
25
|
import dayjs from "dayjs";
|
|
23
26
|
import { DATE_FORMAT, DATE_WITH_TIME_FORMAT } from "../hocs/appConstants";
|
|
24
27
|
import { showNotification } from "../common/notifications";
|
|
25
28
|
import { UPDATE_SUCCESS } from "../utilities/constants/messages";
|
|
26
29
|
export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpdateField, currentInputType, index, allFields, onCancel, }) {
|
|
27
|
-
const { styles } = useDamConfig();
|
|
30
|
+
const { styles, brand, teams } = useDamConfig();
|
|
31
|
+
const queryClient = useQueryClient();
|
|
32
|
+
const brandId = get(brand, "_id");
|
|
33
|
+
const brandUsers = getCurrentBrandUsers(queryClient, brandId);
|
|
34
|
+
const userOptions = useMemo(() => map(brandUsers, (user) => getUserAvatar(user)), [brandUsers, brandId]);
|
|
35
|
+
const teamOptions = useMemo(() => {
|
|
36
|
+
const externalTeams = (teams || []).filter((team) => get(team, "id") != null || get(team, "_id") != null);
|
|
37
|
+
return map(externalTeams, (team) => {
|
|
38
|
+
const teamId = get(team, "id") || get(team, "_id");
|
|
39
|
+
const teamName = get(team, "name", "");
|
|
40
|
+
const teamType = get(team, "type", "");
|
|
41
|
+
return {
|
|
42
|
+
label: `${teamId} ${teamName} ${teamType}`,
|
|
43
|
+
value: teamId,
|
|
44
|
+
key: `${teamId} - ${teamName} - ${teamType}`,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}, [teams]);
|
|
28
48
|
const navigate = useAppNavigate();
|
|
29
49
|
const [defaultValueInput, setDefaultValueInput] = useState("");
|
|
30
50
|
const [loading, setLoading] = useState(false);
|
|
@@ -220,6 +240,13 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
220
240
|
setDisabledReason(null);
|
|
221
241
|
}, 100);
|
|
222
242
|
}, [field, form]);
|
|
243
|
+
// Rebuild default value input when teams/users load (TEAM/PERSON need these options)
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
const defaultName = get(currentInputType, "defaultName");
|
|
246
|
+
if (defaultName === InputTypes.TEAM || defaultName === InputTypes.PERSON) {
|
|
247
|
+
handleFormValuesChange();
|
|
248
|
+
}
|
|
249
|
+
}, [teamOptions, userOptions]);
|
|
223
250
|
// Strip time from dayjs (set to midnight) - used when "Allow time" is toggled OFF
|
|
224
251
|
const stripTimeFromDayjs = (d) => {
|
|
225
252
|
if (!d || typeof d.hour !== "function")
|
|
@@ -366,8 +393,8 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
366
393
|
},
|
|
367
394
|
});
|
|
368
395
|
}
|
|
369
|
-
// Pass rules to getFormItem
|
|
370
|
-
const defaultValueItem = getFormItem(Object.assign(Object.assign({}, item), { additionalRules: rules }), true);
|
|
396
|
+
// Pass rules to getFormItem; TEAM and PERSON need options from context
|
|
397
|
+
const defaultValueItem = getFormItem(Object.assign(Object.assign({}, item), { additionalRules: rules }), true, defaultName === InputTypes.PERSON ? userOptions : undefined, defaultName === InputTypes.TEAM ? teamOptions : undefined);
|
|
371
398
|
setDefaultValueInput(defaultValueItem);
|
|
372
399
|
};
|
|
373
400
|
return (_jsxs("div", { className: "md-lib-p-4", children: [_jsxs("div", { className: "md-lib-flex md-lib-items-center md-lib-gap-2", children: [_jsx("h2", { className: "md-lib-text-xl md-lib-font-semibold", children: "Properties" }), _jsxs("p", { className: "md-lib-ml-auto md-lib-text-sm md-lib-truncate", style: { color: styles === null || styles === void 0 ? void 0 : styles.secondaryTextColor }, children: ["Type: ", get(field, "name", "N/A")] })] }), _jsx("div", { className: "md-lib-mt-4 md-lib-relative", children: _jsxs(Form, { layout: "vertical", form: form, requiredMark: true, scrollToFirstError: true, onFinish: onUpdate, initialValues: field, onValuesChange: handleFormValuesChange, children: [_jsx(Form.Item, { name: "isMandatory", valuePropName: "checked", children: _jsx(Checkbox, { children: "Marks as mandatory field" }) }), _jsx(Form.Item, { name: "name", label: "Name", rules: [
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { LIST_VIEW_DATE_FORMAT, LOCAL_TIMEZONE, UPLOAD_FILE_IN_PROGRESS_WHITE_IMAGE, } from "../hocs/appConstants";
|
|
3
3
|
import { DriveModes, EntityType, InputTypes, SortByKeys, SortOrders, ThumbnailStatus, } from "../utilities/constants/interface";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
|
-
import { filter, get, groupBy, includes, map, reverse, sortBy, toLower, } from "lodash";
|
|
5
|
+
import { filter, get, groupBy, includes, isArray, map, reverse, sortBy, toLower, } from "lodash";
|
|
6
6
|
import LoadMoreItems from "../common/LoadMoreItems";
|
|
7
7
|
import FolderMenuOptions from "./FolderMenuOptions";
|
|
8
8
|
import { Image, Tooltip } from "antd";
|
|
@@ -38,6 +38,22 @@ const formatGroupDate = (date) => {
|
|
|
38
38
|
return "Yesterday";
|
|
39
39
|
return d.format(LIST_VIEW_DATE_FORMAT);
|
|
40
40
|
};
|
|
41
|
+
const formatMetadataDisplayValue = (value, field) => {
|
|
42
|
+
if (value === undefined || value === null || value === "")
|
|
43
|
+
return null;
|
|
44
|
+
const defaultName = get(field, "defaultName");
|
|
45
|
+
if (defaultName === InputTypes.DATE) {
|
|
46
|
+
return dayjs(value).format(LIST_VIEW_DATE_FORMAT);
|
|
47
|
+
}
|
|
48
|
+
if (defaultName === InputTypes.DATE_RANGE && isArray(value) && value.length === 2) {
|
|
49
|
+
const [start, end] = value;
|
|
50
|
+
return `${dayjs(start).format(LIST_VIEW_DATE_FORMAT)} - ${dayjs(end).format(LIST_VIEW_DATE_FORMAT)}`;
|
|
51
|
+
}
|
|
52
|
+
if (defaultName === InputTypes.CHECKBOX || (defaultName === InputTypes.SELECT && isArray(value))) {
|
|
53
|
+
return isArray(value) ? value.join(", ") : value;
|
|
54
|
+
}
|
|
55
|
+
return String(value);
|
|
56
|
+
};
|
|
41
57
|
const FolderListView = ({ folders, foldersFetching, hasNextPage, fetchNextPage, selectedFileIds, selectedFolderIds, setSelectedItems, isImagePicker, setSelectedFile, setParentFolderId, selectedPickerFile, location, assets, sortByKey, sortOrder, setSortOrders, onSearch, searchKey, searchValue, metadataKey, metadataValue, setSelectedKeys, }) => {
|
|
42
58
|
const navigate = useAppNavigate();
|
|
43
59
|
const [state, setState] = useState({
|
|
@@ -210,7 +226,16 @@ const FolderListView = ({ folders, foldersFetching, hasNextPage, fetchNextPage,
|
|
|
210
226
|
? currentAsset === null || currentAsset === void 0 ? void 0 : currentAsset.name
|
|
211
227
|
: "-" }), metaFields.map((field) => {
|
|
212
228
|
const value = get(folder, `metadata.${field._id}`);
|
|
213
|
-
|
|
229
|
+
const isFile = get(folder, "type") === EntityType.FILE;
|
|
230
|
+
const fieldFromAsset = isFile && currentAsset
|
|
231
|
+
? get(currentAsset, "metadataFields", []).find((f) => get(f, "_id") === field._id || get(f, "mapId") === field._id)
|
|
232
|
+
: null;
|
|
233
|
+
const defaultValue = isFile && fieldFromAsset ? get(fieldFromAsset, "defaultValue") : get(field, "defaultValue");
|
|
234
|
+
const rawDisplay = value !== null && value !== void 0 ? value : (isFile ? defaultValue : undefined);
|
|
235
|
+
const displayValue = rawDisplay != null && rawDisplay !== ""
|
|
236
|
+
? formatMetadataDisplayValue(rawDisplay, fieldFromAsset || field)
|
|
237
|
+
: null;
|
|
238
|
+
return (_jsx("div", { title: displayValue || "-", className: "md-lib-text-secondaryTextColor dark:md-lib-text-darkTextColor md-lib-block md-lib-truncate md-lib-text-sm md-lib-w-[120px] md-lib-gap-2", children: displayValue || "-" }, get(field, "_id")));
|
|
214
239
|
}), !metaFields.some((f) => toLower(String(get(f, "name", ""))).includes("download") &&
|
|
215
240
|
toLower(String(get(f, "name", ""))).includes("count")) && (_jsx("div", { title: get(folder, "type") === EntityType.FILE
|
|
216
241
|
? String((_b = get(folder, "fileDownload", []).length) !== null && _b !== void 0 ? _b : "-")
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { FormInstance } from "antd";
|
|
3
|
-
import {
|
|
4
|
-
export declare const buildInitialValues: (formData: Record<string, any>, metaFields: MetaDataFieldEntity[], isEditMode: boolean) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { MetaDataFieldEntity } from "../../utilities/constants/interface";
|
|
4
|
+
export declare const buildInitialValues: (formData: Record<string, any>, metaFields: MetaDataFieldEntity[], isEditMode: boolean) => Record<string, any>;
|
|
5
|
+
export declare const getFormItem: (item: MetaDataFieldEntity, fromDefaultValue: boolean, userOptions?: {
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
value: string;
|
|
8
|
+
key?: string;
|
|
9
|
+
}[], teamOptions?: {
|
|
8
10
|
label: React.ReactNode;
|
|
9
11
|
value: string;
|
|
10
12
|
key?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo } from "react";
|
|
3
3
|
import { Form, Input, InputNumber, DatePicker, Select, Checkbox, Radio, Typography, } from "antd";
|
|
4
|
-
import {
|
|
4
|
+
import { first, get, includes, isArray, isNumber, map, nth, } from "lodash";
|
|
5
5
|
import dayjs from "dayjs";
|
|
6
6
|
import { InputSupportedTypes, InputTypes, } from "../../utilities/constants/interface";
|
|
7
7
|
import { INVALID_URL } from "../../utilities/constants/messages";
|
|
@@ -10,47 +10,53 @@ import { getCurrentBrandUsers } from "../../react-query/hooks/brand-hooks";
|
|
|
10
10
|
import { getUserAvatar } from "../../settings/getUserAvatar";
|
|
11
11
|
import { useDamConfig } from "../../hocs/DamConfigContext";
|
|
12
12
|
const { RangePicker } = DatePicker;
|
|
13
|
+
const transformValueForField = (value, field) => {
|
|
14
|
+
const defaultName = get(field, "defaultName");
|
|
15
|
+
const inputTypeSettings = get(field, "inputTypeSettings", {});
|
|
16
|
+
const allowMultiple = get(inputTypeSettings, `${InputSupportedTypes.ALLOW_MULTIPLE}`, false);
|
|
17
|
+
switch (defaultName) {
|
|
18
|
+
case InputTypes.DATE:
|
|
19
|
+
return value ? dayjs(value) : undefined;
|
|
20
|
+
case InputTypes.DATE_RANGE:
|
|
21
|
+
return isArray(value) && get(value, "length") === 2
|
|
22
|
+
? [dayjs(first(value)), dayjs(nth(value, 1))]
|
|
23
|
+
: undefined;
|
|
24
|
+
case InputTypes.SELECT:
|
|
25
|
+
return allowMultiple ? value || [] : value !== null && value !== void 0 ? value : undefined;
|
|
26
|
+
case InputTypes.CHECKBOX:
|
|
27
|
+
return value || [];
|
|
28
|
+
case InputTypes.NUMBERS:
|
|
29
|
+
if (value === null || value === undefined || value === "")
|
|
30
|
+
return undefined;
|
|
31
|
+
const num = Number(value);
|
|
32
|
+
return !Number.isNaN(num) && isFinite(num) ? num : value;
|
|
33
|
+
case InputTypes.TEXT:
|
|
34
|
+
case InputTypes.PARAGRAPH:
|
|
35
|
+
case InputTypes.LINK:
|
|
36
|
+
return value != null ? String(value) : undefined;
|
|
37
|
+
default:
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
13
41
|
export const buildInitialValues = (formData, metaFields, isEditMode) => {
|
|
14
|
-
|
|
42
|
+
// Always build from metaFields (current template) so we include all fields
|
|
43
|
+
// and apply template defaults when editing + assigning a NEW template
|
|
44
|
+
const result = {};
|
|
45
|
+
metaFields.forEach((field) => {
|
|
15
46
|
const id = get(field, "_id") || get(field, "mapId");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const defaultName = get(field, "defaultName");
|
|
28
|
-
const inputTypeSettings = get(field, "inputTypeSettings", {});
|
|
29
|
-
const allowMultiple = get(inputTypeSettings, `${InputSupportedTypes.ALLOW_MULTIPLE}`, false);
|
|
30
|
-
switch (defaultName) {
|
|
31
|
-
case InputTypes.DATE:
|
|
32
|
-
return value ? dayjs(value) : undefined;
|
|
33
|
-
case InputTypes.DATE_RANGE:
|
|
34
|
-
return isArray(value) && get(value, "length") === 2
|
|
35
|
-
? [dayjs(first(value)), dayjs(nth(value, 1))]
|
|
36
|
-
: undefined;
|
|
37
|
-
case InputTypes.SELECT:
|
|
38
|
-
return allowMultiple ? value || [] : value !== null && value !== void 0 ? value : undefined;
|
|
39
|
-
case InputTypes.CHECKBOX:
|
|
40
|
-
return value || [];
|
|
41
|
-
case InputTypes.NUMBERS:
|
|
42
|
-
if (value === null || value === undefined || value === "")
|
|
43
|
-
return undefined;
|
|
44
|
-
const num = Number(value);
|
|
45
|
-
return !Number.isNaN(num) && isFinite(num) ? num : value;
|
|
46
|
-
case InputTypes.TEXT:
|
|
47
|
-
case InputTypes.PARAGRAPH:
|
|
48
|
-
case InputTypes.LINK:
|
|
49
|
-
return value != null ? String(value) : undefined;
|
|
50
|
-
default:
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
47
|
+
if (!id)
|
|
48
|
+
return;
|
|
49
|
+
const formValue = formData[id];
|
|
50
|
+
const templateDefault = get(field, "defaultValue");
|
|
51
|
+
// In edit mode: use file's value if present (from existing metadata), else template default
|
|
52
|
+
// In create mode: use template default
|
|
53
|
+
// When assigning NEW template to existing file, formData has old template's keys,
|
|
54
|
+
// so formValue is undefined for new template's fields - use template default
|
|
55
|
+
const hasExistingValue = formValue !== undefined && formValue !== null;
|
|
56
|
+
const rawValue = isEditMode && hasExistingValue ? formValue : templateDefault;
|
|
57
|
+
result[id] = transformValueForField(rawValue, field);
|
|
53
58
|
});
|
|
59
|
+
return result;
|
|
54
60
|
};
|
|
55
61
|
export const getFormItem = (item, fromDefaultValue, userOptions, teamOptions) => {
|
|
56
62
|
const name = get(item, "_id") || get(item, "mapId");
|