Introduce context menu
Summary: Introduced a context menu for DataTable with some default options. Opted to put it under a visible hovered dropdown instead of on right-click, since this better alings with Ant's design guides (we don't have context clicks anywhere else I think), but if it isn't convincing we can still change it. Included some default actions, to set up quick filters, and to copy values. For copying rows, implemented it to by default take the JSON from a row, rather than space separated values like in ManagedTable, as many existing plugins customize the onCopy handler to just do that, so it seemed like a better default since it is a richer format. If there are good use cases for the previous behavior, we'll probably find out after the old release :) Introduced utility to copy text to clipboard in FlipperLib, but decoupled it from Electron. Didn't include multi select yet, that will be done in a next diff. Reviewed By: nikoant Differential Revision: D26513161 fbshipit-source-id: b2b1b20b0a6f4ada9de2566bf6b02171f722c4aa
This commit is contained in:
committed by
Facebook GitHub Bot
parent
11eb19da4c
commit
5c3a8742ef
@@ -43,19 +43,35 @@ export function useDataTableManager<T extends object>(
|
||||
[columns],
|
||||
);
|
||||
|
||||
const addColumnFilter = useCallback((columnId: string, value: string) => {
|
||||
// TODO: fix typings
|
||||
setEffectiveColumns(
|
||||
produce((draft: DataTableColumn<any>[]) => {
|
||||
const column = draft.find((c) => c.key === columnId)!;
|
||||
column.filters!.push({
|
||||
label: value,
|
||||
value: value.toLowerCase(),
|
||||
enabled: true,
|
||||
});
|
||||
}),
|
||||
);
|
||||
}, []);
|
||||
const addColumnFilter = useCallback(
|
||||
(columnId: string, value: string, disableOthers = false) => {
|
||||
// TODO: fix typings
|
||||
setEffectiveColumns(
|
||||
produce((draft: DataTableColumn<any>[]) => {
|
||||
const column = draft.find((c) => c.key === columnId)!;
|
||||
const filterValue = value.toLowerCase();
|
||||
const existing = column.filters!.find((c) => c.value === filterValue);
|
||||
if (existing) {
|
||||
existing.enabled = true;
|
||||
} else {
|
||||
column.filters!.push({
|
||||
label: value,
|
||||
value: filterValue,
|
||||
enabled: true,
|
||||
});
|
||||
}
|
||||
if (disableOthers) {
|
||||
column.filters!.forEach((c) => {
|
||||
if (c.value !== filterValue) {
|
||||
c.enabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const removeColumnFilter = useCallback((columnId: string, index: number) => {
|
||||
// TODO: fix typings
|
||||
|
||||
Reference in New Issue
Block a user