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

Clean up frontend change tracker and snackbars related to undoing operations #3480

Merged
merged 3 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,30 @@
},
removeNode: withChangeTracker(function(changeTracker) {
this.track('Delete');
this.showSnackbar({
duration: null,
text: this.$tr('removingItems', { count: 1 }),
actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
});

return this.deleteClipboardNode({
id: this.nodeId,
}).then(() => {
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('removedFromClipboard'),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
// TODO: implement revert functionality for clipboard
// actionText: this.$tr('undo'),
// actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
}),
duplicateNode: withChangeTracker(function(changeTracker) {
this.track('Copy');
this.showSnackbar({
duration: null,
text: this.$tr('creatingCopies'),
actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
});

return this.copyAll({
nodes: [this.contentNode],
}).then(() => {
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('copiedItemsToClipboard'),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
// TODO: implement revert functionality for clipboard
// actionText: this.$tr('undo'),
// actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
}),
track(label) {
Expand All @@ -131,11 +121,8 @@
makeACopy: 'Make a copy',
moveTo: 'Move to...',
remove: 'Delete',
undo: 'Undo',
cancel: 'Cancel',
creatingCopies: 'Copying in clipboard...',
// undo: 'Undo',
copiedItemsToClipboard: 'Copied in clipboard',
removingItems: 'Deleting from clipboard...',
removedFromClipboard: 'Deleted from clipboard',
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,13 @@
},
copyToClipboard: withChangeTracker(function(ids, changeTracker) {
const nodes = this.getRealContentNodes(ids);
this.showSnackbar({
duration: null,
text: this.$tr('creatingClipboardCopies'),
actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
});

return this.copyAll({ nodes }).then(() => {
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('copiedItemsToClipboard'),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
// TODO: implement revert functionality for clipboard
// actionText: this.$tr('undo'),
// actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
}),
calculateMoveNodes() {
Expand Down Expand Up @@ -347,24 +341,16 @@
return Promise.resolve([]);
}

this.showSnackbar({
duration: null,
text: this.$tr('creatingClipboardCopies'),
//! COMMENTED OUT UNTIL FUNCTIONALITY UPDATED
// actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
});

return promiseChunk(trees, 1, ([tree]) => {
// `tree` is exactly the params for copy
return this.copy(tree);
}).then(() => {
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('copiedItemsToClipboard'),
//! COMMENTED OUT UNTIL FUNCTIONALITY UPDATED
// TODO: implement revert functionality for clipboard
// actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
// actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
}),
removeNodes: withChangeTracker(function(changeTracker) {
Expand All @@ -375,36 +361,25 @@
return Promise.resolve([]);
}

this.showSnackbar({
duration: null,
text: this.$tr('removingItems'),
//! COMMENTED OUT UNTIL FUNCTIONALITY UPDATED
// actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
});

return this.deleteClipboardNodes(selectionIds).then(() => {
this.resetSelectionState();
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('removedFromClipboard'),
//! COMMENTED OUT UNTIL FUNCTIONALITY UPDATED
// TODO: implement revert functionality for clipboard
// actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
// actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
}),
},
$trs: {
selectAll: 'Select all',
undo: 'Undo',
cancel: 'Cancel',
// undo: 'Undo',
close: 'Close',
duplicateSelectedButton: 'Make a copy',
moveSelectedButton: 'Move',
deleteSelectedButton: 'Delete',
removingItems: 'Deleting from clipboard...',
removedFromClipboard: 'Deleted from clipboard',
creatingClipboardCopies: 'Copying in clipboard...',
copiedItemsToClipboard: 'Copied in clipboard',
emptyDefaultTitle: 'No resources in your clipboard',
emptyDefaultText:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@

<script>

import { mapActions } from 'vuex';
import camelCase from 'lodash/camelCase';
import ContentNodeValidator from '../ContentNodeValidator';
import ContentNodeChangedIcon from '../ContentNodeChangedIcon';
Expand Down Expand Up @@ -300,15 +299,13 @@
copying(isCopying, wasCopying) {
if (wasCopying && !isCopying) {
this.highlight = true;
this.deleteTask({ task_id: this.taskId });
setTimeout(() => {
this.highlight = false;
}, 2500);
}
},
},
methods: {
...mapActions('task', ['deleteTask']),
handleTileClick(e) {
// Ensures that clicking an icon button is not treated the same as clicking the card
if (e.target && e.target.tagName !== 'svg' && !this.copying) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import { mapActions, mapGetters } from 'vuex';
import { RouteNames } from '../constants';
import MoveModal from './move/MoveModal';
import { ContentNode } from 'shared/data/resources';
import { withChangeTracker } from 'shared/data/changes';
import { RELATIVE_TREE_POSITIONS } from 'shared/data/constants';

Expand Down Expand Up @@ -103,7 +104,7 @@
},
},
methods: {
...mapActions(['showSnackbar', 'clearSnackbar']),
...mapActions(['showSnackbar']),
...mapActions('contentNode', ['createContentNode', 'moveContentNodes', 'copyContentNode']),
...mapActions('clipboard', ['copy']),
newTopicNode() {
Expand Down Expand Up @@ -154,29 +155,24 @@
const redirect = this.getRemoveNodeRedirect();
return this.moveContentNodes({ id__in: [this.nodeId], parent: this.trashId }).then(() => {
redirect();
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('removedItems'),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
}).then(() => changeTracker.cleanUp());
});
}),
copyToClipboard: withChangeTracker(function(changeTracker) {
this.trackAction('Copy to clipboard');
this.showSnackbar({
duration: null,
text: this.$tr('creatingClipboardCopies'),
actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
});

return this.copy({ node_id: this.node.node_id, channel_id: this.node.channel_id }).then(
() => {
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('copiedToClipboardSnackbar'),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
// TODO: implement revert functionality for clipboard
// actionText: this.$tr('undo'),
// actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
}
);
}),
Expand All @@ -185,21 +181,23 @@
this.showSnackbar({
duration: null,
text: this.$tr('creatingCopies'),
actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
// TODO: determine how to cancel copying while it's in progress,
// TODO: if that's something we want
// actionText: this.$tr('cancel'),
// actionCallback: () => changeTracker.revert(),
});
return this.copyContentNode({
id: this.nodeId,
target: this.nodeId,
position: RELATIVE_TREE_POSITIONS.RIGHT,
}).then(() => {
return this.clearSnackbar();
// TODO: Shows too quickly, need to show when copy task completes
// return this.showSnackbar({
// text: this.$tr('copiedSnackbar'),
// actionText: this.$tr('undo'),
// actionCallback: () => changeTracker.revert(),
// });
}).then(node => {
ContentNode.waitForCopying([node.id]).then(() => {
this.showSnackbar({
text: this.$tr('copiedSnackbar'),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
});
}),
trackAction(eventLabel) {
Expand All @@ -218,12 +216,9 @@
makeACopy: 'Make a copy',
copyToClipboard: 'Copy to clipboard',
remove: 'Remove',

undo: 'Undo',
cancel: 'Cancel',
creatingCopies: 'Copying...',
creatingClipboardCopies: 'Copying to clipboard...',
// copiedSnackbar: 'Copy operation complete',
copiedSnackbar: 'Copy operation complete',
copiedToClipboardSnackbar: 'Copied to clipboard',
removedItems: 'Sent to trash',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
import { DraggableTypes, DropEffect } from 'shared/mixins/draggable/constants';
import { DraggableFlags } from 'shared/vuex/draggablePlugin/module/constants';
import DraggableRegion from 'shared/views/draggable/DraggableRegion';
import { ContentNode } from 'shared/data/resources';

export default {
name: 'CurrentTopicView',
Expand Down Expand Up @@ -416,7 +417,7 @@
},
},
methods: {
...mapActions(['showSnackbar', 'clearSnackbar']),
...mapActions(['showSnackbar']),
...mapActions(['setViewMode', 'addViewModeOverride', 'removeViewModeOverride']),
...mapActions('contentNode', [
'createContentNode',
Expand Down Expand Up @@ -598,41 +599,36 @@
if (nextRoute) {
this.$router.replace(nextRoute);
}
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('removedItems', { count: id__in.length }),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
}).then(() => changeTracker.cleanUp());
});
}),
copyToClipboard: withChangeTracker(function(ids, changeTracker) {
this.trackClickEvent('Copy to clipboard');
const nodes = this.getContentNodes(ids);
this.showSnackbar({
duration: null,
text: this.$tr('creatingClipboardCopies'),
//! COMMENTED OUT UNTIL FUNCTIONALITY UPDATED
// actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
});

return this.copyAll({ nodes }).then(() => {
this.clearSelections();
return this.showSnackbar({
this.showSnackbar({
text: this.$tr('copiedItemsToClipboard'),
//! COMMENTED OUT UNTIL FUNCTIONALITY UPDATED
// TODO: implement revert functionality for clipboard
// actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
});
// actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
}),
duplicateNodes: withChangeTracker(function(id__in, changeTracker) {
this.trackClickEvent('Copy');
this.showSnackbar({
duration: null,
text: this.$tr('creatingCopies'),
actionText: this.$tr('cancel'),
actionCallback: () => changeTracker.revert(),
// TODO: determine how to cancel copying while it's in progress,
// TODO: if that's something we want
// actionText: this.$tr('cancel'),
// actionCallback: () => changeTracker.revert(),
});
return Promise.all(
id__in.map(id =>
Expand All @@ -642,15 +638,15 @@
position: RELATIVE_TREE_POSITIONS.RIGHT,
})
)
).then(() => {
).then(nodes => {
this.clearSelections();
return this.clearSnackbar();
// TODO: Shows too quickly, need to show when copy task completes
// return this.showSnackbar({
// text: this.$tr('copiedItems'),
// actionText: this.$tr('undo'),
// actionCallback: () => changeTracker.revert(),
// });
ContentNode.waitForCopying(nodes.map(n => n.id)).then(() => {
this.showSnackbar({
text: this.$tr('copiedItems'),
actionText: this.$tr('undo'),
actionCallback: () => changeTracker.revert(),
}).then(() => changeTracker.cleanUp());
});
});
}),
scroll(e) {
Expand Down Expand Up @@ -699,10 +695,8 @@
selectionCount:
'{topicCount, plural,\n =1 {# folder}\n other {# folders}}, {resourceCount, plural,\n =1 {# resource}\n other {# resources}}',
undo: 'Undo',
cancel: 'Cancel',
creatingCopies: 'Copying...',
creatingClipboardCopies: 'Copying to clipboard...',
// copiedItems: 'Copy operation complete',
copiedItems: 'Copy operation complete',
copiedItemsToClipboard: 'Copied to clipboard',
removedItems: 'Sent to trash',
selectAllLabel: 'Select all',
Expand Down
Loading