@trackunit/custom-field-components 1.0.28 → 1.0.32
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/index.cjs.js +13 -1
- package/index.esm.js +13 -1
- package/package.json +10 -10
package/index.cjs.js
CHANGED
|
@@ -239,6 +239,18 @@ const AddStringListField = ({ id, label, isEditing, setIsEditing, onAdd }) => {
|
|
|
239
239
|
return (jsxRuntime.jsxs(Modal, { className: "max-w-lg", dataTestId: `${id}-edit-modal`, isOpen: isEditing, onDismissClick: handleDiscard, children: [jsxRuntime.jsx(reactComponents.CardHeader, { heading: t("customfield.stringlistfield.addField.Heading", { label: label }), onClose: handleDiscard }), jsxRuntime.jsx(reactComponents.CardBody, { children: jsxRuntime.jsx(reactFormComponents.TextInput, { dataTestId: `${id}-edit-modal-input`, onChange: e => setInputValue(e.target.value), placeholder: t("customfield.stringlistfield.addField.InputPlaceholder", { label: label }), value: inputValue }) }), jsxRuntime.jsxs(reactComponents.CardFooter, { children: [jsxRuntime.jsx(reactComponents.Button, { dataTestId: `${id}-edit-modal-discard-button`, onClick: handleDiscard, variant: "secondary", children: t("customfield.stringlistfield.discard") }), jsxRuntime.jsx(reactComponents.Button, { dataTestId: `${id}-edit-modal-add-button`, onClick: handleAdd, children: t("customfield.stringlistfield.add") })] })] }));
|
|
240
240
|
};
|
|
241
241
|
|
|
242
|
+
const StringListInput = ({ value: initialValue, onSave, onDelete, disabled, id, index }) => {
|
|
243
|
+
const [localValue, setLocalValue] = react.useState(initialValue);
|
|
244
|
+
react.useEffect(() => {
|
|
245
|
+
setLocalValue(initialValue);
|
|
246
|
+
}, [initialValue]);
|
|
247
|
+
const handleBlur = react.useCallback(() => {
|
|
248
|
+
if (localValue !== initialValue) {
|
|
249
|
+
onSave(localValue);
|
|
250
|
+
}
|
|
251
|
+
}, [localValue, initialValue, onSave]);
|
|
252
|
+
return (jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx(reactFormComponents.TextInput, { "data-testid": `${id}-${index}-input`, disabled: disabled, onBlur: handleBlur, onChange: e => setLocalValue(e.target.value), value: localValue }), jsxRuntime.jsx(reactComponents.IconButton, { disabled: disabled, icon: jsxRuntime.jsx(reactComponents.Icon, { name: "Trash", size: "small" }), onClick: onDelete, variant: "secondary-danger" })] }));
|
|
253
|
+
};
|
|
242
254
|
/**
|
|
243
255
|
* A custom field that displays a list of strings.
|
|
244
256
|
*/
|
|
@@ -268,7 +280,7 @@ const StringListField = ({ defaultValue = [], label, description, disabled, vali
|
|
|
268
280
|
handleRemoveValue(index);
|
|
269
281
|
}
|
|
270
282
|
};
|
|
271
|
-
return (jsxRuntime.jsxs(reactComponents.Card, { ...props, className: "w-full", "data-testid": dataTestId, children: [jsxRuntime.jsx(reactComponents.CardHeader, { accessories: jsxRuntime.jsx(reactComponents.Tooltip, { label: description }), heading: label, headingVariant: "secondary" }), jsxRuntime.jsx(reactComponents.CardBody, { children: field.value.length === 0 ? (jsxRuntime.jsx(reactComponents.Text, { children: t("customfield.stringlistfield.noValuesAddedYet") })) : (jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: field.value.map((value, index) => (jsxRuntime.
|
|
283
|
+
return (jsxRuntime.jsxs(reactComponents.Card, { ...props, className: "w-full", "data-testid": dataTestId, children: [jsxRuntime.jsx(reactComponents.CardHeader, { accessories: jsxRuntime.jsx(reactComponents.Tooltip, { label: description }), heading: label, headingVariant: "secondary" }), jsxRuntime.jsx(reactComponents.CardBody, { children: field.value.length === 0 ? (jsxRuntime.jsx(reactComponents.Text, { children: t("customfield.stringlistfield.noValuesAddedYet") })) : (jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: field.value.map((value, index) => (jsxRuntime.jsx(StringListInput, { disabled: disabled, id: id, index: index, onDelete: () => handleRemoveValueConfirmation(index), onSave: newValue => handleFieldChange(index, newValue), value: value }, `${id}-${index}`))) })) }), !disabled ? (jsxRuntime.jsx(reactComponents.CardFooter, { children: jsxRuntime.jsx(reactComponents.Button, { disabled: disabled, onClick: () => setIsEditing(true), variant: "secondary", children: t("customfield.stringlistfield.add", { label: label }) }) })) : null, jsxRuntime.jsx(AddStringListField, { id: id, isEditing: isEditing, label: label, onAdd: (newItem) => {
|
|
272
284
|
field.onChange([...field.value, newItem]);
|
|
273
285
|
}, setIsEditing: setIsEditing })] }));
|
|
274
286
|
}, rules: validationRules }));
|
package/index.esm.js
CHANGED
|
@@ -237,6 +237,18 @@ const AddStringListField = ({ id, label, isEditing, setIsEditing, onAdd }) => {
|
|
|
237
237
|
return (jsxs(Modal, { className: "max-w-lg", dataTestId: `${id}-edit-modal`, isOpen: isEditing, onDismissClick: handleDiscard, children: [jsx(CardHeader, { heading: t("customfield.stringlistfield.addField.Heading", { label: label }), onClose: handleDiscard }), jsx(CardBody, { children: jsx(TextInput, { dataTestId: `${id}-edit-modal-input`, onChange: e => setInputValue(e.target.value), placeholder: t("customfield.stringlistfield.addField.InputPlaceholder", { label: label }), value: inputValue }) }), jsxs(CardFooter, { children: [jsx(Button, { dataTestId: `${id}-edit-modal-discard-button`, onClick: handleDiscard, variant: "secondary", children: t("customfield.stringlistfield.discard") }), jsx(Button, { dataTestId: `${id}-edit-modal-add-button`, onClick: handleAdd, children: t("customfield.stringlistfield.add") })] })] }));
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
+
const StringListInput = ({ value: initialValue, onSave, onDelete, disabled, id, index }) => {
|
|
241
|
+
const [localValue, setLocalValue] = useState(initialValue);
|
|
242
|
+
useEffect(() => {
|
|
243
|
+
setLocalValue(initialValue);
|
|
244
|
+
}, [initialValue]);
|
|
245
|
+
const handleBlur = useCallback(() => {
|
|
246
|
+
if (localValue !== initialValue) {
|
|
247
|
+
onSave(localValue);
|
|
248
|
+
}
|
|
249
|
+
}, [localValue, initialValue, onSave]);
|
|
250
|
+
return (jsxs("div", { className: "flex items-center gap-2", children: [jsx(TextInput, { "data-testid": `${id}-${index}-input`, disabled: disabled, onBlur: handleBlur, onChange: e => setLocalValue(e.target.value), value: localValue }), jsx(IconButton, { disabled: disabled, icon: jsx(Icon, { name: "Trash", size: "small" }), onClick: onDelete, variant: "secondary-danger" })] }));
|
|
251
|
+
};
|
|
240
252
|
/**
|
|
241
253
|
* A custom field that displays a list of strings.
|
|
242
254
|
*/
|
|
@@ -266,7 +278,7 @@ const StringListField = ({ defaultValue = [], label, description, disabled, vali
|
|
|
266
278
|
handleRemoveValue(index);
|
|
267
279
|
}
|
|
268
280
|
};
|
|
269
|
-
return (jsxs(Card, { ...props, className: "w-full", "data-testid": dataTestId, children: [jsx(CardHeader, { accessories: jsx(Tooltip, { label: description }), heading: label, headingVariant: "secondary" }), jsx(CardBody, { children: field.value.length === 0 ? (jsx(Text, { children: t("customfield.stringlistfield.noValuesAddedYet") })) : (jsx("div", { className: "flex flex-wrap gap-2", children: field.value.map((value, index) => (
|
|
281
|
+
return (jsxs(Card, { ...props, className: "w-full", "data-testid": dataTestId, children: [jsx(CardHeader, { accessories: jsx(Tooltip, { label: description }), heading: label, headingVariant: "secondary" }), jsx(CardBody, { children: field.value.length === 0 ? (jsx(Text, { children: t("customfield.stringlistfield.noValuesAddedYet") })) : (jsx("div", { className: "flex flex-wrap gap-2", children: field.value.map((value, index) => (jsx(StringListInput, { disabled: disabled, id: id, index: index, onDelete: () => handleRemoveValueConfirmation(index), onSave: newValue => handleFieldChange(index, newValue), value: value }, `${id}-${index}`))) })) }), !disabled ? (jsx(CardFooter, { children: jsx(Button, { disabled: disabled, onClick: () => setIsEditing(true), variant: "secondary", children: t("customfield.stringlistfield.add", { label: label }) }) })) : null, jsx(AddStringListField, { id: id, isEditing: isEditing, label: label, onAdd: (newItem) => {
|
|
270
282
|
field.onChange([...field.value, newItem]);
|
|
271
283
|
}, setIsEditing: setIsEditing })] }));
|
|
272
284
|
}, rules: validationRules }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/custom-field-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
"react-select": "^5.8.0",
|
|
13
13
|
"@testing-library/react": "15.0.6",
|
|
14
14
|
"jest-fetch-mock": "^3.0.3",
|
|
15
|
-
"@trackunit/react-form-components": "1.0.
|
|
16
|
-
"@trackunit/shared-utils": "1.2.
|
|
17
|
-
"@trackunit/custom-field-api": "1.0.
|
|
18
|
-
"@trackunit/iris-app-runtime-core": "1.0.
|
|
19
|
-
"@trackunit/react-components": "1.1.
|
|
20
|
-
"@trackunit/react-modal": "1.0.
|
|
21
|
-
"@trackunit/react-core-hooks": "1.0.
|
|
22
|
-
"@trackunit/i18n-library-translation": "1.0.
|
|
23
|
-
"@trackunit/iris-app-runtime-core-api": "1.0.
|
|
15
|
+
"@trackunit/react-form-components": "1.0.29",
|
|
16
|
+
"@trackunit/shared-utils": "1.2.5",
|
|
17
|
+
"@trackunit/custom-field-api": "1.0.19",
|
|
18
|
+
"@trackunit/iris-app-runtime-core": "1.0.13",
|
|
19
|
+
"@trackunit/react-components": "1.1.11",
|
|
20
|
+
"@trackunit/react-modal": "1.0.29",
|
|
21
|
+
"@trackunit/react-core-hooks": "1.0.13",
|
|
22
|
+
"@trackunit/i18n-library-translation": "1.0.17",
|
|
23
|
+
"@trackunit/iris-app-runtime-core-api": "1.0.13"
|
|
24
24
|
},
|
|
25
25
|
"module": "./index.esm.js",
|
|
26
26
|
"main": "./index.cjs.js",
|