Skip to content

Commit

Permalink
fix: ( dot-binary-field-editor ): #30982 Files without an extension c…
Browse files Browse the repository at this point in the history
…annot be edited / saved (#31028)

### Proposed Changes
* Support for the safe without an extension, as there is no constraint
on the field. If the field is restricted to a specific extension via
properties, the constraint should be respected, such as in this case:
text/plain.
* 
<img width="752" alt="image"
src="https://github.com/user-attachments/assets/09bd4044-1397-460f-8bd6-872f4c4cfb1e"
/>


### Screenshots
  • Loading branch information
hmoreras authored Dec 30, 2024
1 parent f518903 commit f8831de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,23 @@ describe('DotBinaryFieldEditorComponent', () => {
expect(component.form.valid).toBe(false);
}));

it('should set form as valid when there is no extension', fakeAsync(() => {
dotBinaryFieldValidatorService.setAccept([]);
spectator.detectChanges();

const spy = jest.spyOn(component.name, 'setErrors');

component.form.setValue({
name: 'testNoExtension',
content: 'test'
});

tick(1000);

expect(spy).not.toHaveBeenCalled();
expect(component.form.valid).toBe(true);
}));

afterEach(() => {
jest.restoreAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class DotBinaryFieldEditorComponent implements OnInit, OnChanges {
@Output() readonly cancel = new EventEmitter<void>();
@ViewChild('editorRef', { static: true }) editorRef!: MonacoEditorComponent;
readonly form = new FormGroup({
name: new FormControl('', [Validators.required, Validators.pattern(/^[^.]+\.[^.]+$/)]),
name: new FormControl('', [Validators.required]),
content: new FormControl('')
});
mimeType = '';
Expand Down Expand Up @@ -189,7 +189,7 @@ export class DotBinaryFieldEditorComponent implements OnInit, OnChanges {
this.updateLanguageForFileExtension(fileExtension);
}

this.validateFileType(fileExtension);
this.validateFileType();
this.cd.detectChanges();
}

Expand All @@ -210,13 +210,12 @@ export class DotBinaryFieldEditorComponent implements OnInit, OnChanges {
this.updateEditorLanguage(id);
}

private validateFileType(fileExtension: string) {
private validateFileType() {
const isValidType = this.dotBinaryFieldValidatorService.isValidType({
extension: this.extension,
mimeType: this.mimeType
});

if (fileExtension && !isValidType) {
if (!isValidType) {
this.name.setErrors({ invalidExtension: this.invalidFileMessage });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export const FileFieldStore = signalStore(
});
},
/**
* setAcceptedFiles is used to set accepted files
* Sets the maximum file size allowed for uploads.
*
* @param {number} maxFileSize - The maximum file size.
*/
setMaxSizeFile: (maxFileSize: number) => {
patchState(store, {
Expand Down

0 comments on commit f8831de

Please sign in to comment.