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

Add automatic alphabetic sort option to topic tree #4423

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Changes from 1 commit
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 @@ -68,6 +68,11 @@
data-test="duplicate-selected-btn"
@click="duplicateNodes(selected)"
/>
<IconButton
icon="copy"
:text="$tr('')"

Check failure on line 73 in contentcuration/contentcuration/frontend/channelEdit/views/CurrentTopicView.vue

View workflow job for this annotation

GitHub Actions / Frontend linting

Message not defined in $trs: ""
GarvitSinghal47 marked this conversation as resolved.
Show resolved Hide resolved
@click="sortNodes(selected)"
/>
<IconButton
v-if="canEdit"
icon="remove"
Expand Down Expand Up @@ -435,6 +440,44 @@
clearSelections() {
this.selected = [];
},

sortNodes(selected) {
const selectedNodes = selected.map(id => this.getContentNode(id));
const orderedNodes = selectedNodes.sort(this.compareNodeTitles);
GarvitSinghal47 marked this conversation as resolved.
Show resolved Hide resolved

const nodeX = this.findNodeBeforeFirstSelected(orderedNodes);

const targetParent = this.node.id;
const targetPosition = nodeX
? RELATIVE_TREE_POSITIONS.RIGHT
: RELATIVE_TREE_POSITIONS.FIRST_CHILD;

orderedNodes.forEach(node => {
const position =
targetPosition === RELATIVE_TREE_POSITIONS.RIGHT
? targetPosition
: RELATIVE_TREE_POSITIONS.LAST_CHILD;
this.moveContentNodes({
id__in: [String(node.id)],
parent: targetParent,
GarvitSinghal47 marked this conversation as resolved.
Show resolved Hide resolved
position,
});
GarvitSinghal47 marked this conversation as resolved.
Show resolved Hide resolved
});
},

findNodeBeforeFirstSelected(nodes) {
GarvitSinghal47 marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 1; i < nodes.length; i++) {
if (this.compareNodeTitles(nodes[i - 1], nodes[i]) > 0) {
return nodes[i - 1];
}
}
return null;
},
compareNodeTitles(nodeA, nodeB) {
const titleA = nodeA.title.toLowerCase();
const titleB = nodeB.title.toLowerCase();
return titleA.localeCompare(titleB);
},
updateTitleForPage() {
let detailTitle;
const topicTitle = this.getTitle(this.getContentNode(this.topicId));
Expand Down
Loading