mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
column manager search box, hide all, show all
This commit is contained in:
parent
49a0a16c25
commit
d64ae4b688
@ -1,4 +1,3 @@
|
|||||||
|
export interface GridConfig {
|
||||||
export default interface GridConfig {
|
hiddenColumns: string[];
|
||||||
hiddenColumns: string[];
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import GridConfig from './GridConfig';
|
import { GridConfig } from './GridConfig';
|
||||||
import { ForeignKeyInfo } from '@dbgate/types';
|
import { ForeignKeyInfo } from '@dbgate/types';
|
||||||
|
|
||||||
export interface DisplayColumn {
|
export interface DisplayColumn {
|
||||||
@ -14,7 +14,7 @@ export interface DisplayColumn {
|
|||||||
isChecked: boolean;
|
isChecked: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default abstract class GridDisplay {
|
export abstract class GridDisplay {
|
||||||
constructor(public config: GridConfig, protected setConfig: (config: GridConfig) => void) {}
|
constructor(public config: GridConfig, protected setConfig: (config: GridConfig) => void) {}
|
||||||
abstract getPageQuery(offset: number, count: number): string;
|
abstract getPageQuery(offset: number, count: number): string;
|
||||||
columns: DisplayColumn[];
|
columns: DisplayColumn[];
|
||||||
@ -32,6 +32,20 @@ export default abstract class GridDisplay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showAllColumns() {
|
||||||
|
this.setConfig({
|
||||||
|
...this.config,
|
||||||
|
hiddenColumns: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
hideAllColumns() {
|
||||||
|
this.setConfig({
|
||||||
|
...this.config,
|
||||||
|
hiddenColumns: this.columns.map(x => x.uniqueName),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
get hiddenColumnIndexes() {
|
get hiddenColumnIndexes() {
|
||||||
return (this.config.hiddenColumns || []).map(x => _.findIndex(this.columns, y => y.uniqueName == x));
|
return (this.config.hiddenColumns || []).map(x => _.findIndex(this.columns, y => y.uniqueName == x));
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import GridDisplay from './GridDisplay';
|
import { GridDisplay } from './GridDisplay';
|
||||||
import { Select, treeToSql, dumpSqlSelect } from '@dbgate/sqltree';
|
import { Select, treeToSql, dumpSqlSelect } from '@dbgate/sqltree';
|
||||||
import { TableInfo, EngineDriver } from '@dbgate/types';
|
import { TableInfo, EngineDriver } from '@dbgate/types';
|
||||||
import GridConfig from './GridConfig';
|
import { GridConfig } from './GridConfig';
|
||||||
|
|
||||||
export default class TableGridDisplay extends GridDisplay {
|
export class TableGridDisplay extends GridDisplay {
|
||||||
constructor(
|
constructor(
|
||||||
public table: TableInfo,
|
public table: TableInfo,
|
||||||
public driver: EngineDriver,
|
public driver: EngineDriver,
|
||||||
|
5
packages/datalib/src/filterName.ts
Normal file
5
packages/datalib/src/filterName.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export function filterName(filter: string, name: string) {
|
||||||
|
if (!filter) return true;
|
||||||
|
if (!name) return false;
|
||||||
|
return name.toUpperCase().includes(filter.toUpperCase());
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
export { default as GridDisplay, DisplayColumn } from "./GridDisplay";
|
export * from "./GridDisplay";
|
||||||
export { default as TableGridDisplay } from "./TableGridDisplay";
|
export * from "./TableGridDisplay";
|
||||||
|
export * from "./filterName";
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import ColumnLabel from './ColumnLabel';
|
import ColumnLabel from './ColumnLabel';
|
||||||
|
import { filterName } from '@dbgate/datalib';
|
||||||
|
|
||||||
|
const Wrapper = styled.div``;
|
||||||
|
|
||||||
const Row = styled.div`
|
const Row = styled.div`
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
@ -11,21 +14,43 @@ const Row = styled.div`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const SearchBoxWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Button = styled.button`
|
||||||
|
width: 50px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Input = styled.input`
|
||||||
|
flex: 1;
|
||||||
|
width: 80px;
|
||||||
|
`;
|
||||||
|
|
||||||
/** @param props {import('./types').DataGridProps} */
|
/** @param props {import('./types').DataGridProps} */
|
||||||
export default function ColumnManager(props) {
|
export default function ColumnManager(props) {
|
||||||
const { display } = props;
|
const { display } = props;
|
||||||
|
const [columnFilter, setColumnFilter] = React.useState('');
|
||||||
return (
|
return (
|
||||||
<div>
|
<Wrapper>
|
||||||
{display.columns.map(item => (
|
<SearchBoxWrapper>
|
||||||
<Row key={item.columnName}>
|
<Input type="text" placeholder="Search" value={columnFilter} onChange={e => setColumnFilter(e.target.value)} />
|
||||||
<input
|
<Button onClick={() => display.hideAllColumns()}>Hide</Button>
|
||||||
type="checkbox"
|
<Button onClick={() => display.showAllColumns()}>Show</Button>
|
||||||
checked={item.isChecked}
|
</SearchBoxWrapper>
|
||||||
onChange={() => display.setColumnVisibility(item.uniqueName, !item.isChecked)}
|
{display.columns
|
||||||
></input>
|
.filter(col => filterName(columnFilter, col.columnName))
|
||||||
<ColumnLabel {...item} />
|
.map(col => (
|
||||||
</Row>
|
<Row key={col.columnName}>
|
||||||
))}
|
<input
|
||||||
</div>
|
type="checkbox"
|
||||||
|
checked={col.isChecked}
|
||||||
|
onChange={() => display.setColumnVisibility(col.uniqueName, !col.isChecked)}
|
||||||
|
></input>
|
||||||
|
<ColumnLabel {...col} />
|
||||||
|
</Row>
|
||||||
|
))}
|
||||||
|
</Wrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ const MainContainer = styled.div`
|
|||||||
|
|
||||||
const ColumnManagerContainer = styled.div`
|
const ColumnManagerContainer = styled.div`
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding-top: 5px;
|
overflow-y: scroll;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const DataGridContainer = styled.div`
|
const DataGridContainer = styled.div`
|
||||||
|
Loading…
Reference in New Issue
Block a user