Skip to content

Commit 5c1258c

Browse files
Fix/uat registry bugs (#437)
* fix(uat): registrations bugs * fix(files): multiple uploads * fix(files): multiple uploads * fix(files): hierarchy dragging files
1 parent 802b60c commit 5c1258c

File tree

3 files changed

+91
-70
lines changed

3 files changed

+91
-70
lines changed

src/app/features/files/components/move-file-dialog/move-file-dialog.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h2 class="font-normal">{{ storageName }}</h2>
99
</div>
1010

1111
<div class="files-table flex flex-column">
12-
@if (previousFolder) {
12+
@if (previousFolder()) {
1313
<div class="files-table-row py-2 px-3">
1414
<div
1515
tabindex="0"
@@ -25,7 +25,7 @@ <h2 class="font-normal">{{ storageName }}</h2>
2525
}
2626

2727
@for (file of files(); track $index) {
28-
<div class="files-table-row flex align-items-center py-2" [class]="foldersStack.length ? 'pl-6' : 'px-3'">
28+
<div class="files-table-row flex align-items-center py-2" [class]="foldersStack().length ? 'pl-6' : 'px-3'">
2929
<div class="flex align-items-center gap-2">
3030
@if (file.kind !== 'folder') {
3131
<osf-icon class="disabled-icon" iconClass="fas fa-file disabled-icon"></osf-icon>

src/app/features/files/components/move-file-dialog/move-file-dialog.component.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ export class MoveFileDialogComponent {
4848
readonly isFilesUpdating = signal(false);
4949
readonly rootFolders = select(FilesSelectors.getRootFolders);
5050

51-
readonly isFolderSame = computed(() => {
52-
return this.currentFolder()?.id === this.config.data.file.relationships.parentFolderId;
53-
});
54-
5551
readonly storageName =
5652
this.config.data.storageName || this.translateService.instant('files.dialogs.moveFile.osfStorage');
5753

@@ -65,15 +61,24 @@ export class MoveFileDialogComponent {
6561
getRootFolderFiles: GetRootFolderFiles,
6662
});
6763

68-
foldersStack: OsfFile[] = this.config.data.foldersStack ?? [];
69-
previousFolder: OsfFile | null = null;
64+
foldersStack = signal<OsfFile[]>(this.config.data.foldersStack ?? []);
65+
previousFolder = signal<OsfFile | null>(null);
7066

7167
pageNumber = signal(1);
7268

7369
itemsPerPage = 10;
7470
first = 0;
7571
filesLink = '';
7672

73+
readonly isFolderSame = computed(() => {
74+
const stack = this.foldersStack();
75+
if (stack.length === 0) {
76+
return true;
77+
}
78+
const parentFolder = stack[stack.length - 1];
79+
return this.currentFolder()?.id === parentFolder?.id;
80+
});
81+
7782
constructor() {
7883
this.initPreviousFolder();
7984
const filesLink = this.currentFolder()?.relationships?.filesLink;
@@ -92,32 +97,37 @@ export class MoveFileDialogComponent {
9297
}
9398

9499
initPreviousFolder() {
95-
const foldersStack = this.foldersStack;
96-
if (foldersStack.length === 0) {
97-
this.previousFolder = null;
100+
const stack = this.foldersStack();
101+
if (stack.length === 0) {
102+
this.previousFolder.set(null);
98103
} else {
99-
this.previousFolder = foldersStack[foldersStack.length - 1];
104+
this.previousFolder.set(stack[stack.length - 1]);
100105
}
101106
}
102107

103108
openFolder(file: OsfFile) {
104109
if (file.kind !== 'folder') return;
105110
const current = this.currentFolder();
106111
if (current) {
107-
this.previousFolder = current;
108-
this.foldersStack.push(current);
112+
this.previousFolder.set(current);
113+
this.foldersStack.update((stack) => [...stack, current]);
109114
}
110115
this.dispatch.getMoveFileFiles(file.relationships.filesLink);
111116
this.dispatch.setMoveFileCurrentFolder(file);
112117
}
113118

114119
openParentFolder() {
115-
const previous = this.foldersStack.pop() ?? null;
116-
this.previousFolder = this.foldersStack.length > 0 ? this.foldersStack[this.foldersStack.length - 1] : null;
117-
if (previous) {
118-
this.dispatch.setMoveFileCurrentFolder(previous);
119-
this.dispatch.getMoveFileFiles(previous.relationships.filesLink);
120-
}
120+
this.foldersStack.update((stack) => {
121+
const newStack = [...stack];
122+
const previous = newStack.pop() ?? null;
123+
this.previousFolder.set(newStack.length > 0 ? newStack[newStack.length - 1] : null);
124+
125+
if (previous) {
126+
this.dispatch.setMoveFileCurrentFolder(previous);
127+
this.dispatch.getMoveFileFiles(previous.relationships.filesLink);
128+
}
129+
return newStack;
130+
});
121131
}
122132

123133
moveFile(): void {
@@ -146,16 +156,14 @@ export class MoveFileDialogComponent {
146156
this.dispatch.setCurrentFolder(this.currentFolder());
147157
this.dispatch.setMoveFileCurrentFolder(null);
148158
this.isFilesUpdating.set(false);
149-
this.dialogRef.close();
159+
this.dialogRef.close(this.foldersStack());
150160
}),
151161
catchError((error) => {
152162
this.toastService.showError(error.error.message);
153163
return throwError(() => error);
154164
})
155165
)
156166
.subscribe((file) => {
157-
this.dialogRef.close();
158-
159167
if (file.id) {
160168
const filesLink = this.currentFolder()?.relationships.filesLink;
161169
const rootFolders = this.rootFolders();

src/app/shared/components/files-tree/files-tree.component.ts

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DialogService } from 'primeng/dynamicdialog';
55
import { PaginatorState } from 'primeng/paginator';
66
import { Tree, TreeNodeDropEvent } from 'primeng/tree';
77

8-
import { EMPTY, finalize, firstValueFrom, Observable, take } from 'rxjs';
8+
import { EMPTY, finalize, Observable, take } from 'rxjs';
99

1010
import { Clipboard } from '@angular/cdk/clipboard';
1111
import { DatePipe } from '@angular/common';
@@ -114,6 +114,22 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
114114
}
115115
});
116116

117+
constructor() {
118+
effect(() => {
119+
const currentFolder = this.currentFolder();
120+
if (currentFolder) {
121+
this.updateFilesList(currentFolder).subscribe(() => this.folderIsOpening.emit(false));
122+
}
123+
});
124+
125+
effect(() => {
126+
const storageChanged = this.storage();
127+
if (storageChanged) {
128+
this.foldersStack = [];
129+
}
130+
});
131+
}
132+
117133
ngAfterViewInit(): void {
118134
if (!this.viewOnly()) {
119135
this.dropZoneContainerRef()!.nativeElement.addEventListener('dragenter', this.dragEnterHandler);
@@ -176,22 +192,6 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
176192
}
177193
}
178194

179-
constructor() {
180-
effect(() => {
181-
const currentFolder = this.currentFolder();
182-
if (currentFolder) {
183-
this.updateFilesList(currentFolder).subscribe(() => this.folderIsOpening.emit(false));
184-
}
185-
});
186-
187-
effect(() => {
188-
const storageChanged = this.storage();
189-
if (storageChanged) {
190-
this.foldersStack = [];
191-
}
192-
});
193-
}
194-
195195
openEntry(file: OsfFile) {
196196
if (file.kind === 'file') {
197197
if (file.guid) {
@@ -366,21 +366,27 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
366366
? this.translateService.instant('files.dialogs.moveFile.title')
367367
: this.translateService.instant('files.dialogs.copyFile.title');
368368

369-
this.dialogService.open(MoveFileDialogComponent, {
370-
width: '552px',
371-
focusOnShow: false,
372-
header: header,
373-
closeOnEscape: true,
374-
modal: true,
375-
closable: true,
376-
data: {
377-
file: file,
378-
resourceId: this.resourceId(),
379-
action: action,
380-
storageName: this.storage()?.label,
381-
foldersStack: [...this.foldersStack],
382-
},
383-
});
369+
this.dialogService
370+
.open(MoveFileDialogComponent, {
371+
width: '552px',
372+
focusOnShow: false,
373+
header: header,
374+
closeOnEscape: true,
375+
modal: true,
376+
closable: true,
377+
data: {
378+
file: file,
379+
resourceId: this.resourceId(),
380+
action: action,
381+
storageName: this.storage()?.label,
382+
foldersStack: [...this.foldersStack],
383+
},
384+
})
385+
.onClose.subscribe((foldersStack) => {
386+
if (foldersStack) {
387+
this.foldersStack = [...foldersStack];
388+
}
389+
});
384390
});
385391
}
386392

@@ -424,17 +430,20 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
424430

425431
const dropNode = event.dropNode as OsfFile;
426432
const dragNode = event.dragNode as OsfFile;
427-
let path = dropNode?.path;
428433
const moveLink = dragNode?.links?.move;
429-
let parentFolder: OsfFile | null = null;
434+
let targetFolder: OsfFile | null = null;
435+
let path = '';
430436

431437
if (dropNode?.previousFolder) {
432-
parentFolder = await firstValueFrom(this.filesService.getFolder(dropNode.relationships.parentFolderLink));
433-
if (!parentFolder.relationships.parentFolderLink) {
434-
path = '/';
438+
if (this.foldersStack.length > 0) {
439+
targetFolder = this.foldersStack[this.foldersStack.length - 1];
440+
path = targetFolder?.path || '/';
435441
} else {
436-
path = parentFolder.path;
442+
path = '/';
437443
}
444+
} else {
445+
targetFolder = dropNode;
446+
path = dropNode?.path || '/';
438447
}
439448

440449
if (!path) {
@@ -446,19 +455,23 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
446455
.pipe(
447456
take(1),
448457
finalize(() => {
449-
this.actions().setCurrentFolder(dropNode?.previousFolder ? parentFolder : dropNode);
458+
if (dropNode?.previousFolder) {
459+
if (this.foldersStack.length > 0) {
460+
this.foldersStack.pop();
461+
}
462+
this.actions().setCurrentFolder(targetFolder);
463+
} else {
464+
if (this.currentFolder()) {
465+
this.foldersStack.push(this.currentFolder()!);
466+
}
467+
this.actions().setCurrentFolder(targetFolder);
468+
}
450469
})
451470
)
452471
.subscribe((file) => {
453472
if (file.id) {
454-
if (dropNode?.previousFolder) {
455-
const filesLink = parentFolder?.relationships.filesLink;
456-
457-
if (filesLink) {
458-
this.actions().getFiles(filesLink);
459-
}
460-
} else {
461-
const filesLink = dropNode?.relationships.filesLink;
473+
const filesLink = targetFolder?.relationships.filesLink;
474+
if (filesLink) {
462475
this.actions().getFiles(filesLink);
463476
}
464477
}

0 commit comments

Comments
 (0)