Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete folder or file from file group #744

Merged
merged 23 commits into from
Oct 17, 2017
Merged

Conversation

ascobie
Copy link
Member

@ascobie ascobie commented Oct 6, 2017

Fix #733

Only allow deletion from a storage container. Ignore files and folders on compute nodes.
Storage API only allows deleting blobs one at a time.

delete

@@ -36,6 +40,7 @@ export class BlobFilesBrowserComponent implements OnChanges, OnDestroy {
if (inputs.upload) {
this.fileExplorerConfig = {
canDropExternalFiles: Boolean(this.upload),
canDeleteFiles: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above Boolean(this.delete)

// TODO: Check with Tim as to whether i can chain 2 background tasks to run one after another.
// In which case most of this can be moved into DataContainerFilesComponent.
// task 1: get files to delete
// task 2: delete files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could but I don't think thats a good idea, it would look weird. Maybe what you could do is have it send back an observable that resolve files instead of the actual files so the waiting can be done in the background task

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but otherwise I think its all good like that for now until we make that generic FileSystem

yes: () => {
const listParams = { recursive: true, startswith: path };
const data = this.storageService.listBlobs(Promise.resolve(this.container), listParams);
return data.fetchAll().flatMap(() => data.items.take(1)).map((items) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would not use .map here because it won't run unless you subscribe to it. I know this funciton is being passed up to the dialog which subscribe to it but it is a bit confusing to actually do state actions in the map. I would just have it
const obs = ...
obs.subscribe(...)
return obs;


return this.backgroundTaskService.startTask(taskTitle, (task) => {
let deleted = 0;
let observable = Observable.interval(250).take(fileCount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

task.progress.next(deleted / fileCount * 100);

if (response && blobCache) {
blobCache.deleteItem(files[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be the deleteBlobIfexists that remove from the cache. I feel this would be better. THat way you don't have to do that everytime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a .subscribe(() => { /* remove from cache */ })?

probably a very good idea and one that i am not sure why i didn't think of :)

complete: () => {
task.progress.next(100);
// tslint:disable-next-line:max-line-length
const message = `${deleted} files were successfully removed from the file group: ${this.container.name}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note this is where I think starting to think about i18n would be good. Long string like that don't look good in the code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sure, and every time i see loads of UI text in the code i think the same thing.

task.progress.next(100);
// tslint:disable-next-line:max-line-length
const message = `${deleted} files were successfully removed from the file group: ${this.container.name}`;
this.notificationService.success("Removed files from group", message, { persist: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really want to persist that one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not, though i saw it was in a few other places. can remove.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah error and warning are persisted by default but info and success disapear.
I force it to displayed for stuff where you have actions that you might want to do

public handleDeleteEvent(event: FileDeleteEvent) {
const { path } = event;
this.dialogService.confirm(`Delete files`, {
description: event.isDirectory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make a description variable no to have this ternary condition inline

yes: () => {
const listParams = { recursive: true, startswith: path };
const data = this.storageService.listBlobs(this.container, listParams);
const obs = data.fetchAll().flatMap(() => data.items.take(1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .shareReplay(1) at the end so it doesn't trigger the flatMap for every subscription

}

/**
* Load the inital data
*/
public init() {
this._loadFilesInPath("");
if (this._cache) {
this._fileDeleted = this._cache.deleted.subscribe((key: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:_fileDeletedSub

});

return observable;
// TODO: would like to get the deleted count from this call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use next instead of complete and make the service return the number of files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean the number of files(because you can just do files.length above) or the number of files that actually existsed and were deleted?

error: (error) => {
// tslint:disable-next-line:max-line-length
const message = `Not all files were able to be removed from the file group: ${this.container.name}`;
this.notificationService.error("Error while deleting files", message, { persist: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to specify presist true for error its the default

const observable = Observable.interval(100).take(fileCount);
observable.subscribe({
next: (i) => {
deleted++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't deleted the same as i?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, though i need to change it to be the actual number of deleted files.

Copy link
Member

@timotheeguerin timotheeguerin Oct 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but actually what do you expect to show if the number is different? Some files wasn't deleted successfully or some files were already deleted?

because of option 2 I don't really see the point of showing 23/26 files deleted. This feels more confusing to me and let you wonder why there is three that are not deleted(even though they actually are)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i expected i would show a warning that not all files were able to be deleted. but maybe i just shouldn't bother ....

@ascobie ascobie merged commit 3c24947 into master Oct 17, 2017
@ascobie ascobie deleted the feature/delete-group-files branch October 17, 2017 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants