@bindu-dashing/dam-solution-v2 5.8.172 → 5.8.174

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.
@@ -29,25 +29,20 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
29
29
  const [defaultValueInput, setDefaultValueInput] = useState("");
30
30
  const [loading, setLoading] = useState(false);
31
31
  const [form] = Form.useForm();
32
- // Watch form values and errors to determine if Update button should be enabled
33
32
  const formValues = Form.useWatch([], form);
34
33
  const [isFormValid, setIsFormValid] = useState(false);
35
34
  useEffect(() => {
36
35
  const checkFormValidity = () => __awaiter(this, void 0, void 0, function* () {
37
36
  try {
38
- // Check if required fields are filled and valid
39
37
  const errors = form.getFieldsError();
40
- const touchedFields = form.isFieldsTouched(['name', 'placeholder'], true);
41
38
  const hasErrors = errors.some((error) => error.errors.length > 0);
42
39
  // Get current form values
43
40
  const values = form.getFieldsValue();
44
41
  const nameFilled = !!(values.name && typeof values.name === 'string' && values.name.trim() !== '');
45
42
  const placeholderFilled = !!(values.placeholder && typeof values.placeholder === 'string' && values.placeholder.trim() !== '');
46
- // Enable button only if:
47
- // 1. Required fields are filled
48
- // 2. No validation errors
49
- // 3. Fields are touched (user has interacted with them)
50
- setIsFormValid(Boolean(!!touchedFields && nameFilled && placeholderFilled && !hasErrors));
43
+ // Enable Update button if mandatory fields are filled and there are no errors
44
+ // No need to require fields to be "touched" when they already have valid values
45
+ setIsFormValid(Boolean(nameFilled && placeholderFilled && !hasErrors));
51
46
  }
52
47
  catch (error) {
53
48
  setIsFormValid(false);
@@ -59,8 +54,11 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
59
54
  try {
60
55
  setLoading(true);
61
56
  const allValues = Object.assign({}, values);
62
- if (allValues === null || allValues === void 0 ? void 0 : allValues.defaultValue) {
63
- allValues["defaultValue"] = getFormattedDefaultValue(allValues);
57
+ // Format defaultValue if it exists (including empty string/null/undefined)
58
+ if (allValues.hasOwnProperty("defaultValue")) {
59
+ const formattedValue = getFormattedDefaultValue(allValues);
60
+ // Set to undefined if empty/null, otherwise use formatted value
61
+ allValues["defaultValue"] = formattedValue === null || formattedValue === "" ? undefined : formattedValue;
64
62
  }
65
63
  if (get(field, "_id", null)) {
66
64
  allValues["_id"] = get(field, "_id");
@@ -103,6 +101,23 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
103
101
  return defaultValue || [];
104
102
  case InputTypes.SELECT:
105
103
  return allowMultiple ? defaultValue || [] : defaultValue || undefined;
104
+ case InputTypes.NUMBERS:
105
+ // Ensure defaultValue is a valid number, convert string to number if needed
106
+ if (defaultValue === null || defaultValue === undefined || defaultValue === "") {
107
+ return undefined;
108
+ }
109
+ if (typeof defaultValue === "number" && !isNaN(defaultValue) && isFinite(defaultValue)) {
110
+ return defaultValue;
111
+ }
112
+ if (typeof defaultValue === "string") {
113
+ const parsed = Number(defaultValue);
114
+ const trimmedValue = defaultValue.trim();
115
+ if (!isNaN(parsed) && isFinite(parsed) && trimmedValue !== "") {
116
+ return parsed;
117
+ }
118
+ }
119
+ // If value is not a valid number, return undefined
120
+ return undefined;
106
121
  default:
107
122
  return defaultValue;
108
123
  }
@@ -122,6 +137,25 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
122
137
  return allowMultiple ? value || [] : value !== null && value !== void 0 ? value : undefined;
123
138
  case InputTypes.CHECKBOX:
124
139
  return value || [];
140
+ case InputTypes.NUMBERS:
141
+ // Convert string to number if valid, otherwise return undefined
142
+ if (value === null || value === undefined || value === "") {
143
+ return undefined;
144
+ }
145
+ const valueType = typeof value;
146
+ if (valueType === "number" && !isNaN(value) && isFinite(value)) {
147
+ return value;
148
+ }
149
+ if (valueType === "string") {
150
+ const stringVal = value;
151
+ const parsed = Number(stringVal);
152
+ const trimmedValue = stringVal.trim();
153
+ if (!isNaN(parsed) && isFinite(parsed) && trimmedValue !== "") {
154
+ return parsed;
155
+ }
156
+ }
157
+ // If value is not a valid number, return undefined
158
+ return undefined;
125
159
  default:
126
160
  return value;
127
161
  }
@@ -132,12 +166,13 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
132
166
  // Check initial form validity after setting field values
133
167
  setTimeout(() => {
134
168
  const errors = form.getFieldsError();
135
- const touchedFields = form.isFieldsTouched(['name', 'placeholder'], true);
136
169
  const hasErrors = errors.some((error) => error.errors && error.errors.length > 0);
137
170
  const values = form.getFieldsValue();
138
171
  const nameFilled = !!(values.name && typeof values.name === 'string' && values.name.trim() !== '');
139
172
  const placeholderFilled = !!(values.placeholder && typeof values.placeholder === 'string' && values.placeholder.trim() !== '');
140
- setIsFormValid(Boolean(!!touchedFields && nameFilled && placeholderFilled && !hasErrors));
173
+ // Enable Update button if mandatory fields are filled and there are no errors
174
+ // No need to require fields to be "touched" when they already have valid values
175
+ setIsFormValid(Boolean(nameFilled && placeholderFilled && !hasErrors));
141
176
  }, 100);
142
177
  }, [field, form]);
143
178
  // Update defaultValueInput whenever form values change
@@ -147,6 +182,12 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
147
182
  const defaultName = currentInputType === null || currentInputType === void 0 ? void 0 : currentInputType.defaultName;
148
183
  const options = ((_a = formValues.options) === null || _a === void 0 ? void 0 : _a.filter((opt) => (opt === null || opt === void 0 ? void 0 : opt.label) && (opt === null || opt === void 0 ? void 0 : opt.value))) || [];
149
184
  const settings = formValues.inputTypeSettings || {};
185
+ const isOptionsBasedField = includes([InputTypes.SELECT, InputTypes.CHECKBOX, InputTypes.RADIO], defaultName);
186
+ if (isOptionsBasedField && options.length === 0) {
187
+ // Don't show Default Value field if no options exist
188
+ setDefaultValueInput(null);
189
+ return;
190
+ }
150
191
  // Use a specific placeholder for default value input, or fallback to field placeholder
151
192
  const defaultValuePlaceholder = "Enter default value";
152
193
  const item = {
@@ -178,6 +219,29 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
178
219
  },
179
220
  });
180
221
  }
222
+ // Rule for NUMBERS: ensure only numeric values are accepted
223
+ if (defaultName === InputTypes.NUMBERS) {
224
+ rules.push({
225
+ validator: (_, value) => {
226
+ if (value === undefined || value === null || value === "") {
227
+ return Promise.resolve();
228
+ }
229
+ // Check if value is a valid number
230
+ if (typeof value === "number" && !isNaN(value) && isFinite(value)) {
231
+ return Promise.resolve();
232
+ }
233
+ // Try to parse string values
234
+ if (typeof value === "string") {
235
+ const parsed = Number(value);
236
+ const trimmedValue = value.trim();
237
+ if (!isNaN(parsed) && isFinite(parsed) && trimmedValue !== "") {
238
+ return Promise.resolve();
239
+ }
240
+ }
241
+ return Promise.reject("Default value must be a valid number");
242
+ },
243
+ });
244
+ }
181
245
  // Rule for DATE and DATE_RANGE: check time part if allow time is selected
182
246
  if ((defaultName === InputTypes.DATE ||
183
247
  defaultName === InputTypes.DATE_RANGE) &&
@@ -189,9 +253,6 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
189
253
  return Promise.resolve();
190
254
  // For DATE
191
255
  if (defaultName === InputTypes.DATE) {
192
- // Check if value has time methods (dayjs object with time support)
193
- // When showTime is enabled, dayjs object will have hour/minute/second methods
194
- // 00:00:00 is a valid time, so we check for the presence of time methods, not non-zero values
195
256
  const hasTimeMethods = value &&
196
257
  typeof value.hour === "function" &&
197
258
  typeof value.minute === "function" &&
@@ -206,8 +267,6 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
206
267
  // For DATE_RANGE
207
268
  if (defaultName === InputTypes.DATE_RANGE && Array.isArray(value)) {
208
269
  const [start, end] = value;
209
- // Check for presence of time methods, not non-zero values
210
- // 00:00:00 is a valid time selection
211
270
  const startHasTimeMethods = start &&
212
271
  typeof start.hour === "function" &&
213
272
  typeof start.minute === "function" &&
@@ -230,18 +289,8 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
230
289
  // Pass rules to getFormItem
231
290
  const defaultValueItem = getFormItem(Object.assign(Object.assign({}, item), { additionalRules: rules }), true);
232
291
  setDefaultValueInput(defaultValueItem);
233
- // Check form validity after values change
234
- setTimeout(() => {
235
- const errors = form.getFieldsError();
236
- const touchedFields = form.isFieldsTouched(['name', 'placeholder'], true);
237
- const hasErrors = errors.some((error) => error.errors && error.errors.length > 0);
238
- const values = form.getFieldsValue();
239
- const nameFilled = !!(values.name && typeof values.name === 'string' && values.name.trim() !== '');
240
- const placeholderFilled = !!(values.placeholder && typeof values.placeholder === 'string' && values.placeholder.trim() !== '');
241
- setIsFormValid(Boolean(!!touchedFields && nameFilled && placeholderFilled && !hasErrors));
242
- }, 0);
243
292
  };
244
- 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, className: "md-lib-pb-20", children: [_jsx(Form.Item, { name: "isMandatory", valuePropName: "checked", children: _jsx(Checkbox, { children: "Marks as mandatory field" }) }), _jsx(Form.Item, { name: "name", label: "Field Name", rules: [
293
+ 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, className: "md-lib-pb-20", children: [_jsx(Form.Item, { name: "isMandatory", valuePropName: "checked", children: _jsx(Checkbox, { children: "Marks as mandatory field" }) }), _jsx(Form.Item, { name: "name", label: "Name", rules: [
245
294
  { required: true, message: "Name is required" },
246
295
  {
247
296
  validator: (_, value) => {
@@ -252,12 +301,12 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
252
301
  return Promise.reject("Name must be unique");
253
302
  },
254
303
  },
255
- ], children: _jsx(Input, { placeholder: "Enter name", className: "md-lib-h-12" }) }), _jsx(Form.Item, { label: "Placeholder", name: "placeholder", rules: [
304
+ ], children: _jsx(Input, { placeholder: "Enter name", className: "md-lib-h-12", maxLength: 255, showCount: true }) }), _jsx(Form.Item, { label: "Placeholder", name: "placeholder", rules: [
256
305
  {
257
306
  required: true,
258
307
  message: "Placeholder is required",
259
308
  },
260
- ], children: _jsx(Input, { placeholder: "Enter Field Placeholder", className: "md-lib-h-12" }) }), defaultValueInput, _jsxs("div", { children: [!!get(currentInputType, "supportedTypes.length") && (_jsx("h3", { className: "md-lib-text-md md-lib-font-semibold md-lib-mb-2", children: "Field Validations" })), _jsxs(Form.Item, { name: "field_validations", children: [includes([InputTypes.PARAGRAPH, InputTypes.TEXT, InputTypes.LINK], get(currentInputType, "defaultName")) && (_jsx(TextField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []) })), get(currentInputType, "defaultName") == InputTypes.NUMBERS && (_jsx(NumberField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []) })), (get(currentInputType, "defaultName") == InputTypes.DATE ||
309
+ ], children: _jsx(Input, { placeholder: "Enter Field Placeholder", className: "md-lib-h-12", maxLength: 255, showCount: true }) }), defaultValueInput && defaultValueInput, _jsxs("div", { children: [!!get(currentInputType, "supportedTypes.length") && (_jsx("h3", { className: "md-lib-text-md md-lib-font-semibold md-lib-mb-2", children: "Field Validations" })), _jsxs(Form.Item, { name: "field_validations", children: [includes([InputTypes.PARAGRAPH, InputTypes.TEXT, InputTypes.LINK], get(currentInputType, "defaultName")) && (_jsx(TextField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []) })), get(currentInputType, "defaultName") == InputTypes.NUMBERS && (_jsx(NumberField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []) })), (get(currentInputType, "defaultName") == InputTypes.DATE ||
261
310
  get(currentInputType, "defaultName") ==
262
311
  InputTypes.DATE_RANGE) && (_jsx(DateField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []) })), includes([
263
312
  InputTypes.SELECT,
@@ -55,7 +55,6 @@ export default function CreateOrEditAssetTemplate() {
55
55
  try {
56
56
  const response = yield api.get(FETCH_INPUT_TYPES_URL);
57
57
  const filteredData = (_a = get(response, "data", [])) === null || _a === void 0 ? void 0 : _a.filter((input) => get(input, "defaultName") !== InputTypes.PERSON);
58
- // Sort widgets alphabetically by name
59
58
  const sortedData = filteredData === null || filteredData === void 0 ? void 0 : filteredData.sort((a, b) => {
60
59
  const nameA = get(a, "name", "").toLowerCase();
61
60
  const nameB = get(b, "name", "").toLowerCase();
@@ -47,7 +47,6 @@ export default function EditAssetTemplate({ assetTemplate, inputTypes, }) {
47
47
  const navigate = useAppNavigate();
48
48
  const damConfig = useDamConfig();
49
49
  const api = useMemo(() => createApiClient(damConfig), [damConfig]);
50
- // Track original values for change detection
51
50
  const originalName = useMemo(() => get(assetTemplate, "name", ""), [assetTemplate]);
52
51
  const originalDescription = useMemo(() => get(assetTemplate, "description", ""), [assetTemplate]);
53
52
  const originalFields = useMemo(() => get(assetTemplate, "metadataFields", []), [assetTemplate]);
@@ -69,23 +68,18 @@ export default function EditAssetTemplate({ assetTemplate, inputTypes, }) {
69
68
  });
70
69
  }, [assetTemplate]);
71
70
  const { name, description, currentFieldIndex, fields, loading, showOutputFormat, imagePickerOutputFormat, imagePickerOutputFormatError, } = state;
72
- // Check if there are changes to name or description
73
71
  const hasNameOrDescriptionChanges = useMemo(() => {
74
72
  return name.trim() !== originalName.trim() ||
75
73
  description.trim() !== originalDescription.trim();
76
74
  }, [name, description, originalName, originalDescription]);
77
- // Check if there are changes to fields
78
75
  const hasFieldChanges = useMemo(() => {
79
76
  if (fields.length !== originalFields.length)
80
77
  return true;
81
- // Simple comparison - can be enhanced if needed
82
78
  return JSON.stringify(fields) !== JSON.stringify(originalFields);
83
79
  }, [fields, originalFields]);
84
- // Check if there are changes to imagePickerOutputFormat
85
80
  const hasImagePickerOutputFormatChanges = useMemo(() => {
86
81
  return JSON.stringify(imagePickerOutputFormat) !== JSON.stringify(originalImagePickerOutputFormat);
87
82
  }, [imagePickerOutputFormat, originalImagePickerOutputFormat]);
88
- // Enable save button if there are changes and no field is being edited
89
83
  const canSave = hasNameOrDescriptionChanges || hasFieldChanges || hasImagePickerOutputFormatChanges;
90
84
  const transformInputTypePayload = (updatedValues, field, mapId) => {
91
85
  const supportedTypes = get(field, "supportedTypes", []);
@@ -35,8 +35,6 @@ import { EMPTY_ASSET_TEMPLATE_WIDGETS_URL } from "../utilities/constants/imageUr
35
35
  import _ from "lodash";
36
36
  import useAppParams from "../utilities/useAppParams";
37
37
  export const getWidgetIcon = (defaultName) => {
38
- // Guard against undefined, null, or non-string values
39
- // Use explicit checks and ensure we have a valid string before calling toUpperCase
40
38
  if (defaultName === undefined || defaultName === null) {
41
39
  return null;
42
40
  }
@@ -254,14 +252,12 @@ export default function FieldsSection({ name, inputTypes, transformInputTypePayl
254
252
  : `selected-${index}`}`)))) }), provided.placeholder] }))) }) }), !!currentField && !showOutputFormat && (_jsx("div", { className: "md-lib-col-span-1 md-lib-bg-white dark:md-lib-bg-darkPrimaryHoverColor", children: _jsx(AddFieldProperties, { field: currentField, index: currentFieldIndex, setCurrentFieldIndex: (val) => setCurrentFieldIndex(val), onUpdateField: (updatedValues, field, index) => onUpdateField(updatedValues, field, index), currentInputType: currentInputType, allFields: fields, onCancel: (index) => {
255
253
  if (index !== null) {
256
254
  const fieldToCancel = fields[index];
257
- // If field doesn't have _id, it's a new unsaved field - remove it
258
255
  if (!get(fieldToCancel, "_id")) {
259
256
  const updatedFields = filter(fields, (field, i) => i !== index);
260
257
  const updatedImagePickerOutputFormat = filter(imagePickerOutputFormat, (field) => get(field, "mapId") !== get(fieldToCancel, "mapId"));
261
258
  setState((prevState) => (Object.assign(Object.assign({}, prevState), { fields: updatedFields, currentFieldIndex: null, imagePickerOutputFormat: updatedImagePickerOutputFormat })));
262
259
  }
263
260
  else {
264
- // Existing field - just close the properties panel
265
261
  setCurrentFieldIndex(null);
266
262
  }
267
263
  }
@@ -91,11 +91,9 @@ export const getFormItem = (item, fromDefaultValue, userOptions) => {
91
91
  message = `Maximum ${max} characters allowed.`;
92
92
  }
93
93
  rules.push(Object.assign(Object.assign(Object.assign({}, (hasMin ? { min } : {})), (hasMax ? { max } : {})), { message }));
94
- // Set maxLength for Input/TextArea components - use configured max or default to 255
95
94
  if (hasMax && isNumber(max)) {
96
95
  maxLength = max;
97
96
  }
98
- // If character limit is enabled but no max is set, keep default 255
99
97
  }
100
98
  // REGEX
101
99
  if (get(settings, "REGEX.allow") && get(settings, "REGEX.value")) {
@@ -20,7 +20,7 @@ export declare const REMOVE_OK_TEXT = "Yes, Remove";
20
20
  export declare const ARCHIVE_OK_TEXT = "Yes, Archive";
21
21
  export declare const DELETE_OK_TEXT = "Yes, Delete";
22
22
  export declare const DEACTIVATE_OK_TEXT = "Yes, Deactivate";
23
- export declare const DELETE_CONFIRMATION_MESSAGE = ":action :entity?";
23
+ export declare const DELETE_CONFIRMATION_MESSAGE = "Are you sure want to :action :entity?";
24
24
  export declare const DELETE_MESSAGE_DESCRIPTION = "Are you sure you want to delete.";
25
25
  export declare const CREATE_SUCCESS = "Created Successfully";
26
26
  export declare const DELETE_SUCCESS = "Deleted Successfully";
@@ -20,7 +20,7 @@ export const REMOVE_OK_TEXT = "Yes, Remove";
20
20
  export const ARCHIVE_OK_TEXT = "Yes, Archive";
21
21
  export const DELETE_OK_TEXT = "Yes, Delete";
22
22
  export const DEACTIVATE_OK_TEXT = "Yes, Deactivate";
23
- export const DELETE_CONFIRMATION_MESSAGE = ":action :entity?";
23
+ export const DELETE_CONFIRMATION_MESSAGE = "Are you sure want to :action :entity?";
24
24
  export const DELETE_MESSAGE_DESCRIPTION = "Are you sure you want to delete.";
25
25
  export const CREATE_SUCCESS = "Created Successfully";
26
26
  export const DELETE_SUCCESS = "Deleted Successfully";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.172",
3
+ "version": "5.8.174",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",