Fix filter from selection
Reviewed By: LukeDefeo Differential Revision: D51425090 fbshipit-source-id: 53dda8f65d2e8d17468903c20e88d45038e65be1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bf67b19c4a
commit
b9fa86e77f
@@ -14,7 +14,10 @@ import {DataSourceVirtualizer} from '../../data-source/index';
|
|||||||
import produce, {castDraft, immerable, original} from 'immer';
|
import produce, {castDraft, immerable, original} from 'immer';
|
||||||
import {DataSource, getFlipperLib, _DataSourceView} from 'flipper-plugin-core';
|
import {DataSource, getFlipperLib, _DataSourceView} from 'flipper-plugin-core';
|
||||||
import {SearchExpressionTerm} from '../PowerSearch';
|
import {SearchExpressionTerm} from '../PowerSearch';
|
||||||
import {PowerSearchOperatorProcessorConfig} from './DataTableDefaultPowerSearchOperators';
|
import {
|
||||||
|
dataTablePowerSearchOperators,
|
||||||
|
PowerSearchOperatorProcessorConfig,
|
||||||
|
} from './DataTableDefaultPowerSearchOperators';
|
||||||
import {DataTableManager as DataTableManagerLegacy} from './DataTableManager';
|
import {DataTableManager as DataTableManagerLegacy} from './DataTableManager';
|
||||||
|
|
||||||
export type OnColumnResize = (id: string, size: number | Percentage) => void;
|
export type OnColumnResize = (id: string, size: number | Percentage) => void;
|
||||||
@@ -87,6 +90,7 @@ type DataManagerActions<T> =
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
| Action<'clearSelection', {}>
|
| Action<'clearSelection', {}>
|
||||||
|
| Action<'setSearchExpressionFromSelection', {column: DataTableColumn<T>}>
|
||||||
| Action<'setFilterExceptions', {exceptions: string[] | undefined}>
|
| Action<'setFilterExceptions', {exceptions: string[] | undefined}>
|
||||||
| Action<'appliedInitialScroll'>
|
| Action<'appliedInitialScroll'>
|
||||||
| Action<'toggleAutoScroll'>
|
| Action<'toggleAutoScroll'>
|
||||||
@@ -173,6 +177,34 @@ export const dataTableManagerReducer = produce<
|
|||||||
draft.filterExceptions = undefined;
|
draft.filterExceptions = undefined;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'setSearchExpressionFromSelection': {
|
||||||
|
getFlipperLib().logger.track(
|
||||||
|
'usage',
|
||||||
|
'data-table:filter:power-search-from-selection',
|
||||||
|
);
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
|
const items = getSelectedItems(
|
||||||
|
config.dataView as _DataSourceView<any, any>,
|
||||||
|
draft.selection,
|
||||||
|
);
|
||||||
|
|
||||||
|
const searchExpressionFromSelection: SearchExpressionTerm[] = [
|
||||||
|
{
|
||||||
|
field: {
|
||||||
|
key: action.column.key,
|
||||||
|
label: action.column.title ?? action.column.key,
|
||||||
|
},
|
||||||
|
operator: dataTablePowerSearchOperators.enum_set_is_any_of({}),
|
||||||
|
searchValue: items.map((item) =>
|
||||||
|
getValueAtPath(item, action.column.key),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
draft.searchExpression = searchExpressionFromSelection;
|
||||||
|
draft.filterExceptions = undefined;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'selectItem': {
|
case 'selectItem': {
|
||||||
const {nextIndex, addToSelection, allowUnselect} = action;
|
const {nextIndex, addToSelection, allowUnselect} = action;
|
||||||
draft.selection = castDraft(
|
draft.selection = castDraft(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
getSelectedItems,
|
getSelectedItems,
|
||||||
getValueAtPath,
|
getValueAtPath,
|
||||||
Selection,
|
Selection,
|
||||||
} from './DataTableManager';
|
} from './DataTableWithPowerSearchManager';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
_tryGetFlipperLibImplementation,
|
_tryGetFlipperLibImplementation,
|
||||||
@@ -65,8 +65,8 @@ export function tableContextMenuFactory<T extends object>(
|
|||||||
key={column.key ?? idx}
|
key={column.key ?? idx}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'setColumnFilterFromSelection',
|
type: 'setSearchExpressionFromSelection',
|
||||||
column: column.key,
|
column,
|
||||||
});
|
});
|
||||||
}}>
|
}}>
|
||||||
{friendlyColumnTitle(column)}
|
{friendlyColumnTitle(column)}
|
||||||
|
|||||||
Reference in New Issue
Block a user