1- import { ListValue , ObjectItem } from "mendix" ;
2- import { FileUploaderContainerProps , UploadModeEnum } from "../../typings/FileUploaderProps" ;
1+ import { DynamicValue , ListValue , ObjectItem } from "mendix" ;
2+ import { FileUploaderContainerProps , MaxFilePerUploadTypeEnum , UploadModeEnum } from "../../typings/FileUploaderProps" ;
33import { action , computed , makeObservable , observable } from "mobx" ;
4+ import { Big } from "big.js" ;
45import { getImageUploaderFormats , parseAllowedFormats } from "../utils/parseAllowedFormats" ;
56import { FileStore } from "./FileStore" ;
67import { FileRejection } from "react-dropzone" ;
@@ -27,6 +28,8 @@ export class FileUploaderStore {
2728 _maxFileSize = 0 ;
2829 _ds ?: ListValue ;
2930 _maxFilesPerUpload : number ;
31+ _maxFilePerUploadType : MaxFilePerUploadTypeEnum ;
32+ _maxFilesPerUploadExpression : DynamicValue < Big > ;
3033
3134 errorMessage ?: string = undefined ;
3235
@@ -37,6 +40,8 @@ export class FileUploaderStore {
3740 this . _maxFileSizeMiB = props . maxFileSize ;
3841 this . _maxFileSize = this . _maxFileSizeMiB * 1024 * 1024 ;
3942 this . _maxFilesPerUpload = props . maxFilesPerUpload ;
43+ this . _maxFilePerUploadType = props . maxFilePerUploadType ;
44+ this . _maxFilesPerUploadExpression = props . maxFilesPerUploadExpression ;
4045 this . _uploadMode = props . uploadMode ;
4146
4247 this . objectCreationHelper = new ObjectCreationHelper ( this . _widgetName , props . objectCreationTimeout ) ;
@@ -79,7 +84,9 @@ export class FileUploaderStore {
7984 files : observable ,
8085 existingItemsLoaded : observable ,
8186 errorMessage : observable ,
82- allowedFormatsDescription : computed
87+ allowedFormatsDescription : computed ,
88+ maxFilesPerUpload : computed ,
89+ isFileUploadLimitReached : computed
8390 } ) ;
8491
8592 this . updateProps ( props ) ;
@@ -94,6 +101,11 @@ export class FileUploaderStore {
94101 this . _ds = props . associatedImages ;
95102 }
96103
104+ // Update max files properties
105+ this . _maxFilesPerUpload = props . maxFilesPerUpload ;
106+ this . _maxFilePerUploadType = props . maxFilePerUploadType ;
107+ this . _maxFilesPerUploadExpression = props . maxFilesPerUploadExpression ;
108+
97109 this . translations . updateProps ( props ) ;
98110 this . updateProcessor . processUpdate ( this . _ds ) ;
99111 }
@@ -113,6 +125,28 @@ export class FileUploaderStore {
113125 . join ( ", " ) ;
114126 }
115127
128+ get maxFilesPerUpload ( ) : number | undefined {
129+ if ( this . _maxFilePerUploadType === "expression" ) {
130+ const expressionValue = this . _maxFilesPerUploadExpression . value ;
131+ if ( expressionValue && ! isNaN ( Number ( expressionValue ) ) ) {
132+ return Number ( expressionValue ) ;
133+ }
134+ // Fallback to default if expression is invalid
135+ return undefined ;
136+ }
137+ return this . _maxFilesPerUpload ;
138+ }
139+
140+ get isFileUploadLimitReached ( ) : boolean {
141+ const activeFiles = this . files . filter (
142+ file => file . fileStatus !== "missing" && file . fileStatus !== "removedFile"
143+ ) ;
144+ if ( ! this . maxFilesPerUpload || this . maxFilesPerUpload === 0 ) {
145+ return false ;
146+ }
147+ return activeFiles . length >= this . maxFilesPerUpload ;
148+ }
149+
116150 setMessage ( msg ?: string ) : void {
117151 this . errorMessage = msg ;
118152 }
@@ -128,7 +162,7 @@ export class FileUploaderStore {
128162
129163 if ( fileRejections . length && fileRejections [ 0 ] . errors [ 0 ] . code === "too-many-files" ) {
130164 this . setMessage (
131- this . translations . get ( "uploadFailureTooManyFilesMessage" , this . _maxFilesPerUpload . toString ( ) )
165+ this . translations . get ( "uploadFailureTooManyFilesMessage" , this . maxFilesPerUpload ? .toString ( ) ?? "" )
132166 ) ;
133167 return ;
134168 }
0 commit comments