@dartech/arsenal-ui 1.3.84 → 1.3.86
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.js
CHANGED
@@ -709,9 +709,10 @@ const ControlAutocomplete = _a => {
|
|
709
709
|
options = [],
|
710
710
|
multiple,
|
711
711
|
textFieldProps = {},
|
712
|
-
disableCloseOnSelect
|
712
|
+
disableCloseOnSelect,
|
713
|
+
useStringValue
|
713
714
|
} = _a,
|
714
|
-
autocompleteProps = __rest(_a, ["control", "validate", "name", "label", "required", "defaultValue", "disabled", "hideErrorMessage", "onChange", "labelKey", "valueKey", "options", "multiple", "textFieldProps", "disableCloseOnSelect"]);
|
715
|
+
autocompleteProps = __rest(_a, ["control", "validate", "name", "label", "required", "defaultValue", "disabled", "hideErrorMessage", "onChange", "labelKey", "valueKey", "options", "multiple", "textFieldProps", "disableCloseOnSelect", "useStringValue"]);
|
715
716
|
const _b = useController({
|
716
717
|
name,
|
717
718
|
control,
|
@@ -724,14 +725,16 @@ const ControlAutocomplete = _a => {
|
|
724
725
|
_c = _b.field,
|
725
726
|
{
|
726
727
|
ref,
|
727
|
-
onChange
|
728
|
+
onChange,
|
729
|
+
value
|
728
730
|
} = _c,
|
729
|
-
fieldProps = __rest(_c, ["ref", "onChange"]),
|
731
|
+
fieldProps = __rest(_c, ["ref", "onChange", "value"]),
|
730
732
|
{
|
731
733
|
fieldState: {
|
732
734
|
error
|
733
735
|
}
|
734
736
|
} = _b;
|
737
|
+
const [localValue, setLocalValue] = useState();
|
735
738
|
const {
|
736
739
|
getOptionLabel,
|
737
740
|
isOptionEqualToValue,
|
@@ -741,9 +744,16 @@ const ControlAutocomplete = _a => {
|
|
741
744
|
labelKey
|
742
745
|
});
|
743
746
|
const handleChange = (_, value) => {
|
744
|
-
onChange(value);
|
747
|
+
onChange(useStringValue ? value[valueKey] : value);
|
748
|
+
setLocalValue(value);
|
745
749
|
};
|
750
|
+
useEffect(() => {
|
751
|
+
if (typeof value === 'string' && valueKey && useStringValue && !localValue && options.length && !!options[0] && typeof options[0] === 'object') {
|
752
|
+
setLocalValue(options.find(el => el[valueKey] === value));
|
753
|
+
}
|
754
|
+
}, [localValue, options, useStringValue, value, valueKey]);
|
746
755
|
return jsx(Autocomplete, Object.assign({}, fieldProps, {
|
756
|
+
value: useStringValue ? localValue !== null && localValue !== void 0 ? localValue : null : value,
|
747
757
|
fullWidth: true,
|
748
758
|
disablePortal: true,
|
749
759
|
size: "small",
|
@@ -3735,7 +3745,6 @@ const FileValueWidget = ({
|
|
3735
3745
|
setValue,
|
3736
3746
|
register
|
3737
3747
|
} = useFormContext();
|
3738
|
-
const [fileType, setFileType] = useState(null);
|
3739
3748
|
const fileValue = useWatch({
|
3740
3749
|
control,
|
3741
3750
|
name
|
@@ -3747,44 +3756,25 @@ const FileValueWidget = ({
|
|
3747
3756
|
const base64 = yield convertBase64(file);
|
3748
3757
|
setValue(name, base64);
|
3749
3758
|
}), [name, setValue]);
|
3750
|
-
|
3751
|
-
|
3752
|
-
|
3753
|
-
|
3754
|
-
|
3755
|
-
|
3756
|
-
|
3757
|
-
} else {
|
3758
|
-
setFileType(type);
|
3759
|
-
}
|
3759
|
+
return jsxs(Button, Object.assign({
|
3760
|
+
component: "label",
|
3761
|
+
variant: "contained",
|
3762
|
+
size: "large",
|
3763
|
+
color: "primary",
|
3764
|
+
sx: {
|
3765
|
+
marginTop: 4
|
3760
3766
|
}
|
3761
|
-
},
|
3762
|
-
|
3763
|
-
|
3764
|
-
|
3765
|
-
|
3766
|
-
|
3767
|
-
|
3768
|
-
|
3769
|
-
|
3770
|
-
|
3771
|
-
|
3772
|
-
component: "label",
|
3773
|
-
variant: "contained",
|
3774
|
-
size: "large",
|
3775
|
-
color: "primary"
|
3776
|
-
}, {
|
3777
|
-
children: [fileType ? 'Change file' : 'Upload file', jsx("input", Object.assign({
|
3778
|
-
type: "hidden"
|
3779
|
-
}, register(`${name}`, {
|
3780
|
-
required: true
|
3781
|
-
}))), jsx("input", {
|
3782
|
-
type: "file",
|
3783
|
-
hidden: true,
|
3784
|
-
onChange: handleFileRead
|
3785
|
-
})]
|
3786
|
-
}))]
|
3787
|
-
});
|
3767
|
+
}, {
|
3768
|
+
children: [fileValue ? 'Change file' : 'Upload file', jsx("input", Object.assign({
|
3769
|
+
type: "hidden"
|
3770
|
+
}, register(`${name}`, {
|
3771
|
+
required: true
|
3772
|
+
}))), jsx("input", {
|
3773
|
+
type: "file",
|
3774
|
+
hidden: true,
|
3775
|
+
onChange: handleFileRead
|
3776
|
+
})]
|
3777
|
+
}));
|
3788
3778
|
};
|
3789
3779
|
var FileValueWidget$1 = FileValueWidget;
|
3790
3780
|
|
@@ -5650,6 +5640,34 @@ const DefinitionFiller = ({
|
|
5650
5640
|
}));
|
5651
5641
|
};
|
5652
5642
|
|
5643
|
+
const FileDefinitionValueView = ({
|
5644
|
+
property,
|
5645
|
+
data
|
5646
|
+
}) => {
|
5647
|
+
const {
|
5648
|
+
name
|
5649
|
+
} = property;
|
5650
|
+
const downloadFile = useCallback((contentBase64, fileName) => {
|
5651
|
+
const linkSource = contentBase64;
|
5652
|
+
const downloadLink = document.createElement('a');
|
5653
|
+
document.body.appendChild(downloadLink);
|
5654
|
+
downloadLink.href = linkSource;
|
5655
|
+
downloadLink.target = '_self';
|
5656
|
+
downloadLink.download = fileName;
|
5657
|
+
downloadLink.click();
|
5658
|
+
}, []);
|
5659
|
+
return jsx(Button, Object.assign({
|
5660
|
+
component: "label",
|
5661
|
+
variant: "contained",
|
5662
|
+
size: "large",
|
5663
|
+
color: "primary",
|
5664
|
+
onClick: () => downloadFile(data, name)
|
5665
|
+
}, {
|
5666
|
+
children: "Download File"
|
5667
|
+
}));
|
5668
|
+
};
|
5669
|
+
var FileDefinitionValueView$1 = FileDefinitionValueView;
|
5670
|
+
|
5653
5671
|
const PropertyValueComponent = ({
|
5654
5672
|
property,
|
5655
5673
|
data,
|
@@ -5660,7 +5678,10 @@ const PropertyValueComponent = ({
|
|
5660
5678
|
backgroundColor: '#fff',
|
5661
5679
|
border: '1px solid #ccc',
|
5662
5680
|
borderRadius: '4px',
|
5663
|
-
padding: '4px'
|
5681
|
+
padding: '4px',
|
5682
|
+
overflow: 'hidden',
|
5683
|
+
whiteSpace: 'nowrap',
|
5684
|
+
textOverflow: 'ellipsis'
|
5664
5685
|
}
|
5665
5686
|
}, {
|
5666
5687
|
children: value === null ? 'null' : value.toString()
|
@@ -5680,6 +5701,24 @@ const PropertyValueComponent = ({
|
|
5680
5701
|
return typeof data === 'object' ? jsx(JsonView, {
|
5681
5702
|
value: data
|
5682
5703
|
}) : defaultRender(data);
|
5704
|
+
case PropertyType.FILE_REFERENCE:
|
5705
|
+
return jsx(Button, Object.assign({
|
5706
|
+
component: Link,
|
5707
|
+
color: "primary",
|
5708
|
+
variant: "contained",
|
5709
|
+
target: "_blank",
|
5710
|
+
to: data,
|
5711
|
+
sx: {
|
5712
|
+
marginTop: 4
|
5713
|
+
}
|
5714
|
+
}, {
|
5715
|
+
children: "Download via link"
|
5716
|
+
}));
|
5717
|
+
case PropertyType.FILE:
|
5718
|
+
return jsx(FileDefinitionValueView$1, {
|
5719
|
+
data: data,
|
5720
|
+
property: property
|
5721
|
+
});
|
5683
5722
|
default:
|
5684
5723
|
return defaultRender(data);
|
5685
5724
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dartech/arsenal-ui",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.86",
|
4
4
|
"author": "DAR",
|
5
5
|
"publishConfig": {
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
@@ -27,7 +27,6 @@
|
|
27
27
|
"classnames": "^2.3.1",
|
28
28
|
"@tanstack/react-query": "^4.24.10",
|
29
29
|
"@rollup/plugin-node-resolve": "13.3.0",
|
30
|
-
"axios": "1.4.0",
|
31
30
|
"qs": "6.11.0"
|
32
31
|
},
|
33
32
|
"module": "./index.js",
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { FileProperty } from '../../../interfaces';
|
3
|
+
type Props = {
|
4
|
+
property: FileProperty;
|
5
|
+
data: string;
|
6
|
+
};
|
7
|
+
declare const FileDefinitionValueView: ({ property, data }: Props) => JSX.Element;
|
8
|
+
export default FileDefinitionValueView;
|
@@ -60,10 +60,11 @@ export type ControlAutocompleteProps = Omit<AutocompleteProps<unknown, boolean,
|
|
60
60
|
*/
|
61
61
|
options: string[] | unknown[];
|
62
62
|
textFieldProps?: TextFieldProps;
|
63
|
+
useStringValue?: boolean;
|
63
64
|
};
|
64
65
|
/**
|
65
66
|
* Material UI `Autocomplete` controlled component. Used with react-hook-form
|
66
67
|
* @category Forms
|
67
68
|
*/
|
68
|
-
export declare const ControlAutocomplete: ({ control, validate, name, label, required, defaultValue, disabled, hideErrorMessage, onChange: customOnChange, labelKey, valueKey, options, multiple, textFieldProps, disableCloseOnSelect, ...autocompleteProps }: ControlAutocompleteProps) => JSX.Element;
|
69
|
+
export declare const ControlAutocomplete: ({ control, validate, name, label, required, defaultValue, disabled, hideErrorMessage, onChange: customOnChange, labelKey, valueKey, options, multiple, textFieldProps, disableCloseOnSelect, useStringValue, ...autocompleteProps }: ControlAutocompleteProps) => JSX.Element;
|
69
70
|
export default ControlAutocomplete;
|