mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(plugin-data-viewer): CB-665 remove sorting toggle
This commit is contained in:
+37
-14
@@ -50,6 +50,18 @@ export class DataGridContextMenuSortingService {
|
||||
return sorting.getSortMode(columnName);
|
||||
}
|
||||
|
||||
private getSortingConstraints(model: IDatabaseDataModel<any>, resultIndex: number) {
|
||||
const sorting = model.source.getAction(resultIndex, ResultSetSortAction);
|
||||
return sorting.getSortingConstraints();
|
||||
}
|
||||
|
||||
private async removeSortingConstraints(model: IDatabaseDataModel<any>, resultIndex: number) {
|
||||
const sorting = model.source.getAction(resultIndex, ResultSetSortAction);
|
||||
|
||||
sorting.removeSortingConstraints();
|
||||
await model.refresh();
|
||||
}
|
||||
|
||||
register(): void {
|
||||
this.dataGridContextMenuService.add(
|
||||
this.contextMenuService.getRootMenuToken(),
|
||||
@@ -80,10 +92,7 @@ export class DataGridContextMenuSortingService {
|
||||
context.data.model,
|
||||
context.data.resultIndex,
|
||||
context.data.column) === ESortMode.asc,
|
||||
titleGetter: context => {
|
||||
const columnName = this.getColumnName(context.data.model, context.data.resultIndex, context.data.column);
|
||||
return `Order by ${columnName || ''} ASC`;
|
||||
},
|
||||
title: 'ASC',
|
||||
}
|
||||
);
|
||||
this.dataGridContextMenuService.add(
|
||||
@@ -102,27 +111,41 @@ export class DataGridContextMenuSortingService {
|
||||
context.data.model,
|
||||
context.data.resultIndex,
|
||||
context.data.column) === ESortMode.desc,
|
||||
titleGetter: context => {
|
||||
const columnName = this.getColumnName(context.data.model, context.data.resultIndex, context.data.column);
|
||||
return `Order by ${columnName || ''} DESC`;
|
||||
},
|
||||
title: 'DESC',
|
||||
}
|
||||
);
|
||||
this.dataGridContextMenuService.add(
|
||||
this.getMenuSortingToken(),
|
||||
{
|
||||
id: 'toggleSorting',
|
||||
id: 'disableSorting',
|
||||
isPresent(context) {
|
||||
return context.contextType === DataGridContextMenuService.cellContext;
|
||||
},
|
||||
isDisabled: context => context.data.model.isLoading(),
|
||||
onClick: async context => {
|
||||
const nextSortMode = getNextSortMode(
|
||||
this.getSortMode(context.data.model, context.data.resultIndex, context.data.column)
|
||||
);
|
||||
await this.changeSortMode(context.data.model, context.data.resultIndex, context.data.column, nextSortMode);
|
||||
await this.changeSortMode(context.data.model, context.data.resultIndex, context.data.column, null);
|
||||
},
|
||||
title: 'data_grid_table_sorting_toggle',
|
||||
type: 'radio',
|
||||
isChecked: context => this.getSortMode(
|
||||
context.data.model,
|
||||
context.data.resultIndex,
|
||||
context.data.column) === null,
|
||||
title: 'data_grid_table_disable_sorting',
|
||||
}
|
||||
);
|
||||
this.dataGridContextMenuService.add(
|
||||
this.getMenuSortingToken(),
|
||||
{
|
||||
id: 'disableAllSorting',
|
||||
isPresent: context => {
|
||||
const sortingConstraints = this.getSortingConstraints(context.data.model, context.data.resultIndex);
|
||||
return context.contextType === DataGridContextMenuService.cellContext && sortingConstraints.length > 1;
|
||||
},
|
||||
isDisabled: context => context.data.model.isLoading(),
|
||||
onClick: async context => {
|
||||
await this.removeSortingConstraints(context.data.model, context.data.resultIndex);
|
||||
},
|
||||
title: 'data_grid_table_disable_all_sorting',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
+4
-4
@@ -117,17 +117,17 @@ export const TableColumnHeader: React.FC<HeaderRendererProps<any>> = observer(fu
|
||||
|
||||
// TODO we want to get "sortable" property from SqlResultColumn data
|
||||
const sortable = model.source.results.length === 1;
|
||||
const currentSortMode = sorting.getSortMode(columnName);
|
||||
const currentSortMode = sorting.getSortMode(column?.name || '');
|
||||
|
||||
const columnTooltip = columnName + (column?.fullTypeName ? ': ' + column.fullTypeName : '');
|
||||
|
||||
const handleSort = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
e.stopPropagation();
|
||||
if (loading) {
|
||||
if (loading || !column?.name) {
|
||||
return;
|
||||
}
|
||||
const nextSortMode = getNextSortMode(sorting.getSortMode(columnName));
|
||||
sorting.setSortMode(columnName, nextSortMode, e.ctrlKey || e.metaKey);
|
||||
const nextSortMode = getNextSortMode(sorting.getSortMode(column.name));
|
||||
sorting.setSortMode(column.name, nextSortMode, e.ctrlKey || e.metaKey);
|
||||
model.refresh();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export default [
|
||||
['data_grid_table_sorting', 'Sorting'],
|
||||
['data_grid_table_sorting_toggle', 'Toggle sorting'],
|
||||
['data_grid_table_disable_sorting', 'Disabled'],
|
||||
['data_grid_table_disable_all_sorting', 'Disable all'],
|
||||
['data_grid_table_tooltip_column_header_sort', 'Sort by column'],
|
||||
];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export default [
|
||||
['data_grid_table_sorting', 'Сортировка'],
|
||||
['data_grid_table_sorting_toggle', 'Переключить сортировку'],
|
||||
['data_grid_table_disable_sorting', 'Отключена'],
|
||||
['data_grid_table_disable_all_sorting', 'Отключить всю'],
|
||||
['data_grid_table_tooltip_column_header_sort', 'Сортировка по колонке'],
|
||||
];
|
||||
|
||||
+18
@@ -53,6 +53,24 @@ export class ResultSetSortAction extends DatabaseDataAction<IDatabaseDataOptions
|
||||
.map((constaint, idx) => ({ ...constaint, orderPosition: idx }));
|
||||
}
|
||||
|
||||
getSortingConstraints() {
|
||||
if (!this.source.options) {
|
||||
throw new Error('Options must be provided');
|
||||
}
|
||||
|
||||
return this.source.options.constraints
|
||||
.filter(constraint => constraint.orderAsc !== undefined);
|
||||
}
|
||||
|
||||
removeSortingConstraints() {
|
||||
if (!this.source.options) {
|
||||
throw new Error('Options must be provided');
|
||||
}
|
||||
|
||||
this.source.options.constraints = this.source.options.constraints
|
||||
.filter(constaint => constaint.orderAsc === undefined);
|
||||
}
|
||||
|
||||
setSortMode(columnName: string, sortMode: SortMode, multiple: boolean): void {
|
||||
if (!this.source.options) {
|
||||
throw new Error('Options must be provided');
|
||||
|
||||
Reference in New Issue
Block a user