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 {DataSource, getFlipperLib, _DataSourceView} from 'flipper-plugin-core';
|
||||
import {SearchExpressionTerm} from '../PowerSearch';
|
||||
import {PowerSearchOperatorProcessorConfig} from './DataTableDefaultPowerSearchOperators';
|
||||
import {
|
||||
dataTablePowerSearchOperators,
|
||||
PowerSearchOperatorProcessorConfig,
|
||||
} from './DataTableDefaultPowerSearchOperators';
|
||||
import {DataTableManager as DataTableManagerLegacy} from './DataTableManager';
|
||||
|
||||
export type OnColumnResize = (id: string, size: number | Percentage) => void;
|
||||
@@ -87,6 +90,7 @@ type DataManagerActions<T> =
|
||||
}
|
||||
>
|
||||
| Action<'clearSelection', {}>
|
||||
| Action<'setSearchExpressionFromSelection', {column: DataTableColumn<T>}>
|
||||
| Action<'setFilterExceptions', {exceptions: string[] | undefined}>
|
||||
| Action<'appliedInitialScroll'>
|
||||
| Action<'toggleAutoScroll'>
|
||||
@@ -173,6 +177,34 @@ export const dataTableManagerReducer = produce<
|
||||
draft.filterExceptions = undefined;
|
||||
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': {
|
||||
const {nextIndex, addToSelection, allowUnselect} = action;
|
||||
draft.selection = castDraft(
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
getSelectedItems,
|
||||
getValueAtPath,
|
||||
Selection,
|
||||
} from './DataTableManager';
|
||||
} from './DataTableWithPowerSearchManager';
|
||||
import React from 'react';
|
||||
import {
|
||||
_tryGetFlipperLibImplementation,
|
||||
@@ -65,8 +65,8 @@ export function tableContextMenuFactory<T extends object>(
|
||||
key={column.key ?? idx}
|
||||
onClick={() => {
|
||||
dispatch({
|
||||
type: 'setColumnFilterFromSelection',
|
||||
column: column.key,
|
||||
type: 'setSearchExpressionFromSelection',
|
||||
column,
|
||||
});
|
||||
}}>
|
||||
{friendlyColumnTitle(column)}
|
||||
|
||||
Reference in New Issue
Block a user