@dartech/arsenal-ui 1.3.85 → 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
@@ -3745,7 +3745,6 @@ const FileValueWidget = ({
3745
3745
  setValue,
3746
3746
  register
3747
3747
  } = useFormContext();
3748
- const [fileType, setFileType] = useState(null);
3749
3748
  const fileValue = useWatch({
3750
3749
  control,
3751
3750
  name
@@ -3757,44 +3756,25 @@ const FileValueWidget = ({
3757
3756
  const base64 = yield convertBase64(file);
3758
3757
  setValue(name, base64);
3759
3758
  }), [name, setValue]);
3760
- useEffect(() => {
3761
- if (fileValue) {
3762
- const type = fileValue.substring(fileValue.indexOf(':') + 1, fileValue.indexOf(';base64'));
3763
- if (type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
3764
- setFileType('application/xls');
3765
- } else if (type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
3766
- setFileType('application/docx');
3767
- } else {
3768
- setFileType(type);
3769
- }
3759
+ return jsxs(Button, Object.assign({
3760
+ component: "label",
3761
+ variant: "contained",
3762
+ size: "large",
3763
+ color: "primary",
3764
+ sx: {
3765
+ marginTop: 4
3770
3766
  }
3771
- }, [fileValue]);
3772
- return jsxs(Fragment, {
3773
- children: [fileType && jsx(Box, Object.assign({
3774
- mb: 2
3775
- }, {
3776
- children: jsx(Typography, Object.assign({
3777
- variant: "subtitle2"
3778
- }, {
3779
- children: `Uploaded file type: ${fileType}`
3780
- }))
3781
- })), jsxs(Button, Object.assign({
3782
- component: "label",
3783
- variant: "contained",
3784
- size: "large",
3785
- color: "primary"
3786
- }, {
3787
- children: [fileType ? 'Change file' : 'Upload file', jsx("input", Object.assign({
3788
- type: "hidden"
3789
- }, register(`${name}`, {
3790
- required: true
3791
- }))), jsx("input", {
3792
- type: "file",
3793
- hidden: true,
3794
- onChange: handleFileRead
3795
- })]
3796
- }))]
3797
- });
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
+ }));
3798
3778
  };
3799
3779
  var FileValueWidget$1 = FileValueWidget;
3800
3780
 
@@ -5660,6 +5640,34 @@ const DefinitionFiller = ({
5660
5640
  }));
5661
5641
  };
5662
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
+
5663
5671
  const PropertyValueComponent = ({
5664
5672
  property,
5665
5673
  data,
@@ -5670,7 +5678,10 @@ const PropertyValueComponent = ({
5670
5678
  backgroundColor: '#fff',
5671
5679
  border: '1px solid #ccc',
5672
5680
  borderRadius: '4px',
5673
- padding: '4px'
5681
+ padding: '4px',
5682
+ overflow: 'hidden',
5683
+ whiteSpace: 'nowrap',
5684
+ textOverflow: 'ellipsis'
5674
5685
  }
5675
5686
  }, {
5676
5687
  children: value === null ? 'null' : value.toString()
@@ -5690,6 +5701,24 @@ const PropertyValueComponent = ({
5690
5701
  return typeof data === 'object' ? jsx(JsonView, {
5691
5702
  value: data
5692
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
+ });
5693
5722
  default:
5694
5723
  return defaultRender(data);
5695
5724
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.85",
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;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  label?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  label?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  format: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  label?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  label?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { PropertyUnion } from '../../../interfaces';
3
2
  type PropertyItemProps = {
4
3
  property: PropertyUnion;