@bindu-dashing/dam-solution-v2 5.9.223 → 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: [
@@ -105,20 +105,14 @@ export default function EditAssetTemplate({ assetTemplate, inputTypes, }) {
105
105
  }
106
106
  }
107
107
  });
108
- const payload = {
109
- name: get(updatedValues, "name"),
110
- placeholder: get(updatedValues, "placeholder"),
111
- isMandatory: get(updatedValues, "isMandatory", false),
112
- inputTypeSettings,
113
- label: get(field, "label", get(field, "name", "")),
114
- defaultName: get(field, "defaultName"),
115
- mapId,
116
- defaultValue: get(updatedValues, "defaultValue"),
117
- };
108
+ const defaultName = get(field, "defaultName");
109
+ const skipPlaceholder = includes([InputTypes.CHECKBOX, InputTypes.RADIO], defaultName);
110
+ const payload = Object.assign(Object.assign({ name: get(updatedValues, "name") }, (skipPlaceholder ? {} : { placeholder: get(updatedValues, "placeholder") })), { isMandatory: get(updatedValues, "isMandatory", false), inputTypeSettings, label: get(field, "label", get(field, "name", "")), defaultName,
111
+ mapId, defaultValue: get(updatedValues, "defaultValue") });
118
112
  if (get(updatedValues, "_id", null)) {
119
113
  payload["_id"] = get(updatedValues, "_id");
120
114
  }
121
- if (includes([InputTypes.CHECKBOX, InputTypes.RADIO, InputTypes.SELECT], get(field, "defaultName"))) {
115
+ if (includes([InputTypes.CHECKBOX, InputTypes.RADIO, InputTypes.SELECT], defaultName)) {
122
116
  payload["options"] = get(updatedValues, "options", []);
123
117
  }
124
118
  return payload;
@@ -145,7 +139,9 @@ export default function EditAssetTemplate({ assetTemplate, inputTypes, }) {
145
139
  showNotification(`Field ${i + 1}: Name is required`, NotificationStatus.ERROR);
146
140
  return false;
147
141
  }
148
- if (!get(field, "placeholder") || get(field, "placeholder", "").trim() === "") {
142
+ // Checkbox and radio don't have placeholders - skip validation for them
143
+ const skipPlaceholder = includes([InputTypes.CHECKBOX, InputTypes.RADIO], get(field, "defaultName"));
144
+ if (!skipPlaceholder && (!get(field, "placeholder") || get(field, "placeholder", "").trim() === "")) {
149
145
  showNotification(`Field ${i + 1}: Placeholder is required`, NotificationStatus.ERROR);
150
146
  return false;
151
147
  }
@@ -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
- return (_jsx("div", { title: value || "-", 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: value || "-" }, get(field, "_id")));
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 { BrandUserEntity, MetaDataFieldEntity } from "../../utilities/constants/interface";
4
- export declare const buildInitialValues: (formData: Record<string, any>, metaFields: MetaDataFieldEntity[], isEditMode: boolean) => {
5
- [x: string]: any;
6
- };
7
- export declare const getFormItem: (item: MetaDataFieldEntity, fromDefaultValue: boolean, userOptions?: BrandUserEntity[], teamOptions?: {
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 { find, first, get, includes, isArray, isNumber, map, mapValues, nth, } from "lodash";
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,40 +10,56 @@ 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
- export const buildInitialValues = (formData, metaFields, isEditMode) => {
14
- const dataWithDefaultValues = metaFields.reduce((acc, field) => {
15
- const id = get(field, "_id");
16
- const defaultValue = get(field, "defaultValue");
17
- if (defaultValue) {
18
- acc[id] = defaultValue;
19
- }
20
- return acc;
21
- }, {});
22
- return mapValues(isEditMode ? formData : dataWithDefaultValues, (value, key) => {
23
- const field = find(metaFields, { _id: key });
24
- if (!field)
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:
25
38
  return value;
26
- const defaultName = get(field, "defaultName");
27
- const inputTypeSettings = get(field, "inputTypeSettings", {});
28
- const allowMultiple = get(inputTypeSettings, `${InputSupportedTypes.ALLOW_MULTIPLE}`, false);
29
- switch (defaultName) {
30
- case InputTypes.DATE:
31
- return value ? dayjs(value) : undefined;
32
- case InputTypes.DATE_RANGE:
33
- return isArray(value) && get(value, "length") === 2
34
- ? [dayjs(first(value)), dayjs(nth(value, 1))]
35
- : undefined;
36
- case InputTypes.SELECT:
37
- return allowMultiple ? value || [] : value !== null && value !== void 0 ? value : undefined;
38
- case InputTypes.CHECKBOX:
39
- return value || [];
40
- default:
41
- return value;
42
- }
39
+ }
40
+ };
41
+ export const buildInitialValues = (formData, metaFields, isEditMode) => {
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) => {
46
+ const id = get(field, "_id") || get(field, "mapId");
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);
43
58
  });
59
+ return result;
44
60
  };
45
61
  export const getFormItem = (item, fromDefaultValue, userOptions, teamOptions) => {
46
- const name = get(item, "_id");
62
+ const name = get(item, "_id") || get(item, "mapId");
47
63
  const label = get(item, "name");
48
64
  const placeholder = get(item, "placeholder", "");
49
65
  const defaultName = get(item, "defaultName");
@@ -227,7 +243,7 @@ const MetaForm = ({ metaFields, metaData, form, isEditMode, }) => {
227
243
  metadata: buildInitialValues(metaData, metaFields, isEditMode),
228
244
  };
229
245
  form.setFieldsValue(formData);
230
- }, [metaData, metaFields]);
246
+ }, [metaData, metaFields, isEditMode, form]);
231
247
  const userOptions = useMemo(() => {
232
248
  return map(brandUsers, (user) => getUserAvatar(user));
233
249
  }, [brandUsers, brandId]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.9.223",
3
+ "version": "5.9.227",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",