From 001c928c708c6cac3de524d0de8d40fda4c06fed Mon Sep 17 00:00:00 2001 From: jonathan-schmitt-mx Date: Thu, 22 Jun 2023 16:36:07 -0600 Subject: [PATCH] added restrictionUniqueName and changed file add and delete to accept based on uniqueness --- package-lock.json | 4 ++-- package.json | 6 +++--- src/FileDropper.tsx | 1 + src/FileDropper.xml | 4 ++++ src/package.xml | 2 +- src/store/fileDropperStore.ts | 9 ++++++--- typings/FileDropperProps.d.ts | 1 + 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 380b586..498e3cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "filedropper", - "version": "1.3.2", + "version": "1.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "filedropper", - "version": "1.3.2", + "version": "1.4.1", "license": "Apache-2.0", "dependencies": { "@bem-react/classname": "^1.5.8", diff --git a/package.json b/package.json index b33e4d9..c038ef0 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "filedropper", "widgetName": "FileDropper", - "version": "1.4.1", + "version": "1.5.0", "description": "Drop files in your Mendix Application", "copyright": "Mendix 2020", "author": "Jelte Lagendijk ", "config": { - "widgetPath": "./dist/MxTestProject/widgets", - "projectPath": "./dist/MxTestProject/", + "widgetPath": "../../widgets", + "projectPath": "../../", "mendixHost": "http://windows:8080", "developmentPort": "3000" }, diff --git a/src/FileDropper.tsx b/src/FileDropper.tsx index 0a35c6c..b0c376a 100644 --- a/src/FileDropper.tsx +++ b/src/FileDropper.tsx @@ -92,6 +92,7 @@ class FileDropperContainer extends Component { autoSave: props.dataAutoSave, maxNumber: props.restrictionMaxFileCount, maxSize: maxFileSize, + uniqueName: props.restrictionUniqueName, validationMessages, accept, texts, diff --git a/src/FileDropper.xml b/src/FileDropper.xml index 4d906b0..86e9e80 100644 --- a/src/FileDropper.xml +++ b/src/FileDropper.xml @@ -77,6 +77,10 @@ Note 1: This might not always be accurate. There can be differences between platforms & browsers. To be sure it is better to use the 'onAccept Microflow' Note 2: When using an Entity that is/inherits 'System.Image', Mime types will always be ignored and set to 'image/*'. You can further restrict this using the 'onAccept Microflow' + + Restrict Duplicates + Restrict uploads to have unique names. If true, will ignore a file upload with a repeated name, regardless of file path. + diff --git a/src/package.xml b/src/package.xml index 7aecd89..3edea43 100644 --- a/src/package.xml +++ b/src/package.xml @@ -1,6 +1,6 @@ - + diff --git a/src/store/fileDropperStore.ts b/src/store/fileDropperStore.ts index f48c4d1..e393cfb 100644 --- a/src/store/fileDropperStore.ts +++ b/src/store/fileDropperStore.ts @@ -25,6 +25,7 @@ export interface FileDropperStoreOptions { accept?: string; maxNumber?: number; maxSize?: number; + uniqueName: boolean; contextObject?: mendix.lib.MxObject; validationMessages?: ValidationMessage[]; saveBase64?: boolean; @@ -34,6 +35,7 @@ export class FileDropperStore implements FileDropperStoreProps { public accept: string | undefined; public maxNumber: number; public maxSize: number | undefined; + public uniqueName: boolean; public saveMethod: ((file: IFileDropperFile) => Promise) | null; public deleteMethod: ((file: IFileDropperFile) => Promise) | null; @@ -72,7 +74,7 @@ export class FileDropperStore implements FileDropperStoreProps { // We need to make sure we first clear all subscriptions, otherwise it will delete twice this.subscriptionHandler({}); const files = this.files; - const found = files.findIndex(f => f.name === file.name); + const found = files.findIndex(f => f.guid === file.guid); if (found !== -1) { if (file.status === "saved" && this.deleteMethod !== null) { const deleted = yield this.deleteMethod(file); @@ -111,6 +113,7 @@ export class FileDropperStore implements FileDropperStoreProps { maxNumber, accept, maxSize, + uniqueName, texts, validationMessages, saveBase64 @@ -128,6 +131,7 @@ export class FileDropperStore implements FileDropperStoreProps { this.accept = accept; this.maxNumber = typeof maxNumber !== "undefined" ? maxNumber : 0; this.maxSize = maxSize; + this.uniqueName = uniqueName; this.texts = texts; } @@ -157,8 +161,7 @@ export class FileDropperStore implements FileDropperStoreProps { @action public addFile(file: File): void { - const found = this.files.findIndex(f => f.name === file.name); - if (found === -1) { + if (!this.uniqueName || this.files.every(f => f.name !== file.name)) { const newFile = new FileDropperFile(file, this.saveMethod, this.saveBase64); this.files.push(newFile); this.saveFile(newFile); diff --git a/typings/FileDropperProps.d.ts b/typings/FileDropperProps.d.ts index c4687ae..bea8031 100644 --- a/typings/FileDropperProps.d.ts +++ b/typings/FileDropperProps.d.ts @@ -39,6 +39,7 @@ export interface FileDropperContainerProps extends CommonProps { restrictionMaxFileSize: number; restrictionMaxFileCount: number; restrictionMimeType: string; + restrictionUniqueName: boolean; verificationOnAcceptMicroflow: string; verificationEntity: string;