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

feat: add clear button to selection column #590

Merged
merged 1 commit into from
Aug 2, 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
2 changes: 1 addition & 1 deletion src/model/SelectionColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export declare function filterChanged_SEC(previous: Set<number> | null, current:
* a checkbox column for selections
*/
@SupportType()
@toolbar('sort', 'sortBy', 'group', 'groupBy', 'invertSelection', 'filterSelection')
@toolbar('sort', 'sortBy', 'group', 'groupBy', 'clearSelection', 'invertSelection', 'filterSelection')
@Category('support')
export default class SelectionColumn extends ValueColumn<boolean> {
static readonly EVENT_FILTER_CHANGED = 'filterChanged';
Expand Down
4 changes: 4 additions & 0 deletions src/styles/header/_toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
content: $lu_icon_toggle_left;
}

.#{$lu_css_prefix}-action-clear-selection::before {
content: $lu_icon_times;
}

.#{$lu_css_prefix}-action-invert-selection::before {
content: $lu_icon_check_square_o;
}
Expand Down
3 changes: 2 additions & 1 deletion src/styles/panel/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
}
}

.#{$lu_css_prefix}-stats-reset {
.#{$lu_css_prefix}-stats-reset,
.#{$lu_css_prefix}-stats-clear-selection {
padding: 2px;
font-style: normal;
display: unset;
Expand Down
30 changes: 22 additions & 8 deletions src/ui/panel/SidePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,18 @@ export default class SidePanel {
}
const stats = this.node.querySelector<HTMLElement>(`.${cssClass('stats')}`);
const s = this.data.getSelection();
const clearSelection =
s.length === 0
? ''
: `<i class="${cssClass('action')} ${cssClass('action-clear-selection')} ${cssClass(
'stats-clear-selection'
)}" title="Clear selection"><span class="${cssClass('aria')}" aria-hidden="true">Clear Selection</span></i>`;
const r = this.data.getFirstRanking();
const f = format(',d');
const visible = r ? r.getGroups().reduce((a, b) => a + b.order.length, 0) : 0;
const total = this.data.getTotalNumberOfRows();
stats.innerHTML = `Showing <strong>${f(visible)}</strong> of ${f(total)} items${
s.length > 0 ? `; <span>${f(s.length)} selected</span>` : ''
s.length > 0 ? `; <span>${f(s.length)} selected ${clearSelection}</span>` : ''
}${
visible < total
? ` <i class="${cssClass('action')} ${cssClass('action-filter')} ${cssClass(
Expand All @@ -370,14 +376,22 @@ export default class SidePanel {
}`;

const resetButton = stats.querySelector<HTMLElement>(`.${cssClass('stats-reset')}`);
if (!resetButton) {
return;
if (resetButton) {
resetButton.onclick = (evt) => {
evt.preventDefault();
evt.stopPropagation();
this.data.clearFilters();
};
}

const clearButton = stats.querySelector<HTMLElement>(`.${cssClass('stats-clear-selection')}`);
if (clearButton) {
clearButton.onclick = (evt) => {
evt.preventDefault();
evt.stopPropagation();
this.data.setSelection([]);
};
}
resetButton.onclick = (evt) => {
evt.preventDefault();
evt.stopPropagation();
this.data.clearFilters();
};
}

destroy() {
Expand Down
14 changes: 13 additions & 1 deletion src/ui/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export const toolbarActions: { [key: string]: IToolbarAction } = {
featureLevel: 'basic',
}),
filterSelection: uiDialog('Filter …', SelectionFilterDialog, (ctx) => [ctx], {
order: 8,
mode: 'menu+shortcut',
featureCategory: 'ranking',
featureLevel: 'basic',
Expand Down Expand Up @@ -357,6 +358,17 @@ export const toolbarActions: { [key: string]: IToolbarAction } = {
},
{ featureCategory: 'model', featureLevel: 'advanced' }
),
clearSelection: ui(
'Clear Selection',
(_col, _evt, ctx, level) => {
ctx.dialogManager.removeAboveLevel(level - 1); // close itself
const s = ctx.provider.getSelection();
if (s.length > 0) {
ctx.provider.setSelection([]);
}
},
{ featureCategory: 'model', featureLevel: 'advanced', order: 11 }
),
invertSelection: ui(
'Invert Selection',
(col, _evt, ctx, level) => {
Expand All @@ -371,7 +383,7 @@ export const toolbarActions: { [key: string]: IToolbarAction } = {
const others = order.filter((d) => !ss.has(d));
ctx.provider.setSelection(others);
},
{ featureCategory: 'model', featureLevel: 'advanced' }
{ featureCategory: 'model', featureLevel: 'advanced', order: 10 }
),
};

Expand Down