mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 17:55:59 +00:00
refactor
This commit is contained in:
@@ -104,15 +104,21 @@ export abstract class GridDisplay {
|
|||||||
setColumnVisibility(uniquePath: string[], isVisible: boolean) {
|
setColumnVisibility(uniquePath: string[], isVisible: boolean) {
|
||||||
const uniqueName = uniquePath.join('.');
|
const uniqueName = uniquePath.join('.');
|
||||||
if (uniquePath.length == 1) {
|
if (uniquePath.length == 1) {
|
||||||
this.includeInColumnSet('hiddenColumns', uniqueName, !isVisible);
|
this.includeInColumnSet([
|
||||||
|
{ field: 'hiddenColumns', uniqueName, isIncluded: !isVisible },
|
||||||
|
isVisible == false && this.isDynamicStructure && { field: 'addedColumns', uniqueName, isIncluded: false },
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
this.includeInColumnSet('addedColumns', uniqueName, isVisible);
|
this.includeInColumnSet([{ field: 'addedColumns', uniqueName, isIncluded: isVisible }]);
|
||||||
if (!this.isDynamicStructure) this.reload();
|
if (!this.isDynamicStructure) this.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addDynamicColumn(name: string) {
|
addDynamicColumn(name: string) {
|
||||||
this.includeInColumnSet('addedColumns', name, true);
|
this.includeInColumnSet([
|
||||||
|
{ field: 'addedColumns', uniqueName: name, isIncluded: true },
|
||||||
|
{ field: 'hiddenColumns', uniqueName: name, isIncluded: false },
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
focusColumns(uniqueNames: string[]) {
|
focusColumns(uniqueNames: string[]) {
|
||||||
@@ -150,19 +156,30 @@ export abstract class GridDisplay {
|
|||||||
this.setCache(reloadDataCacheFunc);
|
this.setCache(reloadDataCacheFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
includeInColumnSet(field: keyof GridConfigColumns, uniqueName: string, isIncluded: boolean) {
|
includeInColumnSet(
|
||||||
// console.log('includeInColumnSet', field, uniqueName, isIncluded);
|
modifications: ({ field: keyof GridConfigColumns; uniqueName: string; isIncluded: boolean } | null)[]
|
||||||
if (isIncluded) {
|
) {
|
||||||
this.setConfig(cfg => ({
|
this.setConfig(cfg => {
|
||||||
...cfg,
|
let res = cfg;
|
||||||
[field]: [...(cfg[field] || []), uniqueName],
|
for (const modification of modifications) {
|
||||||
}));
|
if (!modification) {
|
||||||
} else {
|
continue;
|
||||||
this.setConfig(cfg => ({
|
}
|
||||||
...cfg,
|
const { field, uniqueName, isIncluded } = modification;
|
||||||
[field]: (cfg[field] || []).filter(x => x != uniqueName),
|
if (isIncluded) {
|
||||||
}));
|
res = {
|
||||||
}
|
...res,
|
||||||
|
[field]: [...(cfg[field] || []), uniqueName],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
res = {
|
||||||
|
...res,
|
||||||
|
[field]: (cfg[field] || []).filter(x => x != uniqueName),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showAllColumns() {
|
showAllColumns() {
|
||||||
@@ -355,7 +372,9 @@ export abstract class GridDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggleExpandedColumn(uniqueName: string, value?: boolean) {
|
toggleExpandedColumn(uniqueName: string, value?: boolean) {
|
||||||
this.includeInColumnSet('expandedColumns', uniqueName, value == null ? !this.isExpandedColumn(uniqueName) : value);
|
this.includeInColumnSet([
|
||||||
|
{ field: 'expandedColumns', uniqueName, isIncluded: value == null ? !this.isExpandedColumn(uniqueName) : value },
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFilter(uniqueName: string) {
|
getFilter(uniqueName: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user