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

Shortcuts sorting needs a test #16079

Closed
krassowski opened this issue Apr 1, 2024 · 3 comments
Closed

Shortcuts sorting needs a test #16079

krassowski opened this issue Apr 1, 2024 · 3 comments

Comments

@krassowski
Copy link
Member

A test for sorting of shortcuts in the shortcuts table UI:

image

could be added in:

it would be good to test sorting by each of the sortable columns (category, column, source, selectors).

@krassowski
Copy link
Member Author

The test would be for sortShortcuts function, after :

/**
* Sort shortcut list using current sort property.
*/
sortShortcuts(): void {
const shortcuts: IShortcutTarget[] = this.state.filteredShortcutList;
let sortCriteria = this.state.currentSort;
if (sortCriteria === 'command') {
sortCriteria = 'label';
}
const getValue = (target: IShortcutTarget): string => {
if (sortCriteria === 'source') {
return target.keybindings.every(k => k.isDefault) ? 'default' : 'other';
}
return target[sortCriteria] ?? '';
};
shortcuts.sort((a: IShortcutTarget, b: IShortcutTarget) => {
const compareA: string = getValue(a);
const compareB: string = getValue(b);
if (compareA < compareB) {
return -1;
} else if (compareA > compareB) {
return 1;
} else {
const aLabel = a['label'] ?? '';
const bLabel = b['label'] ?? '';
return aLabel < bLabel ? -1 : aLabel > bLabel ? 1 : 0;
}
});
this.setState({ filteredShortcutList: shortcuts });
}

and should verify that filteredShortcutList is in expected order. It will need to call the updateSort method to configure by which column the table should be sorted.

/**
* Set the sort order for the shortcuts listing.
*/
updateSort = (value: IShortcutUI.ColumnId): void => {
if (value !== this.state.currentSort) {
this.setState({ currentSort: value }, this.sortShortcuts);
}
};

@JasonWeill JasonWeill changed the title Shortcuts sorting is needs a test Shortcuts sorting needs a test Apr 2, 2024
@JasonWeill JasonWeill removed the status:Needs Triage Applied to new issues that need triage label Apr 2, 2024
@milinm
Copy link
Contributor

milinm commented Apr 3, 2024

Hello, I am a student looking to contribute to my first open source project. May I have this issue assigned to me?

@krassowski
Copy link
Member Author

Closing as solved by #16098.

@milinm if you would like to work on other good first issues feel welcome to just open a draft PR, or comment with your plan and self-assign (you can assign yourself after leaving a comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants