@bindu-dashing/dam-solution-v2 5.8.173 → 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
|
|
47
|
-
//
|
|
48
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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,7 +182,6 @@ 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 || {};
|
|
150
|
-
// For SELECT/RADIO/CHECKBOX fields, only show Default Value when options exist
|
|
151
185
|
const isOptionsBasedField = includes([InputTypes.SELECT, InputTypes.CHECKBOX, InputTypes.RADIO], defaultName);
|
|
152
186
|
if (isOptionsBasedField && options.length === 0) {
|
|
153
187
|
// Don't show Default Value field if no options exist
|
|
@@ -185,6 +219,29 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
185
219
|
},
|
|
186
220
|
});
|
|
187
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
|
+
}
|
|
188
245
|
// Rule for DATE and DATE_RANGE: check time part if allow time is selected
|
|
189
246
|
if ((defaultName === InputTypes.DATE ||
|
|
190
247
|
defaultName === InputTypes.DATE_RANGE) &&
|
|
@@ -196,9 +253,6 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
196
253
|
return Promise.resolve();
|
|
197
254
|
// For DATE
|
|
198
255
|
if (defaultName === InputTypes.DATE) {
|
|
199
|
-
// Check if value has time methods (dayjs object with time support)
|
|
200
|
-
// When showTime is enabled, dayjs object will have hour/minute/second methods
|
|
201
|
-
// 00:00:00 is a valid time, so we check for the presence of time methods, not non-zero values
|
|
202
256
|
const hasTimeMethods = value &&
|
|
203
257
|
typeof value.hour === "function" &&
|
|
204
258
|
typeof value.minute === "function" &&
|
|
@@ -213,8 +267,6 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
213
267
|
// For DATE_RANGE
|
|
214
268
|
if (defaultName === InputTypes.DATE_RANGE && Array.isArray(value)) {
|
|
215
269
|
const [start, end] = value;
|
|
216
|
-
// Check for presence of time methods, not non-zero values
|
|
217
|
-
// 00:00:00 is a valid time selection
|
|
218
270
|
const startHasTimeMethods = start &&
|
|
219
271
|
typeof start.hour === "function" &&
|
|
220
272
|
typeof start.minute === "function" &&
|
|
@@ -238,7 +290,7 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
238
290
|
const defaultValueItem = getFormItem(Object.assign(Object.assign({}, item), { additionalRules: rules }), true);
|
|
239
291
|
setDefaultValueInput(defaultValueItem);
|
|
240
292
|
};
|
|
241
|
-
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: "
|
|
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: [
|
|
242
294
|
{ required: true, message: "Name is required" },
|
|
243
295
|
{
|
|
244
296
|
validator: (_, value) => {
|
|
@@ -249,12 +301,12 @@ export default function AddFieldProperties({ field, setCurrentFieldIndex, onUpda
|
|
|
249
301
|
return Promise.reject("Name must be unique");
|
|
250
302
|
},
|
|
251
303
|
},
|
|
252
|
-
], 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: [
|
|
253
305
|
{
|
|
254
306
|
required: true,
|
|
255
307
|
message: "Placeholder is required",
|
|
256
308
|
},
|
|
257
|
-
], children: _jsx(Input, { placeholder: "Enter Field Placeholder", className: "md-lib-h-12" }) }), 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 ||
|
|
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 ||
|
|
258
310
|
get(currentInputType, "defaultName") ==
|
|
259
311
|
InputTypes.DATE_RANGE) && (_jsx(DateField, { field: field, supportedTypes: get(currentInputType, "supportedTypes", []) })), includes([
|
|
260
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")) {
|