mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
parent
3eb9b6c392
commit
5c55734ca0
2 changed files with 26 additions and 14 deletions
|
@ -5,9 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { DatasourceDimensionDropProps } from '../../types';
|
||||
import memoizeOne from 'memoize-one';
|
||||
import { DatasourceDimensionDropProps, OperationMetadata } from '../../types';
|
||||
import { OperationType } from '../indexpattern';
|
||||
import { memoizedGetAvailableOperationsByMetadata } from '../operations';
|
||||
import { memoizedGetAvailableOperationsByMetadata, OperationFieldTuple } from '../operations';
|
||||
import { IndexPatternPrivateState } from '../types';
|
||||
|
||||
export interface OperationSupportMatrix {
|
||||
|
@ -21,17 +22,16 @@ type Props = Pick<
|
|||
'layerId' | 'columnId' | 'state' | 'filterOperations'
|
||||
>;
|
||||
|
||||
// TODO: the support matrix should be available outside of the dimension panel
|
||||
|
||||
// TODO: This code has historically been memoized, as a potentially performance
|
||||
// sensitive task. If we can add memoization without breaking the behavior, we should.
|
||||
export const getOperationSupportMatrix = (props: Props): OperationSupportMatrix => {
|
||||
const layerId = props.layerId;
|
||||
const currentIndexPattern = props.state.indexPatterns[props.state.layers[layerId].indexPatternId];
|
||||
|
||||
const filteredOperationsByMetadata = memoizedGetAvailableOperationsByMetadata(
|
||||
currentIndexPattern
|
||||
).filter((operation) => props.filterOperations(operation.operationMetaData));
|
||||
function computeOperationMatrix(
|
||||
operationsByMetadata: Array<{
|
||||
operationMetaData: OperationMetadata;
|
||||
operations: OperationFieldTuple[];
|
||||
}>,
|
||||
filterOperations: (operation: OperationMetadata) => boolean
|
||||
) {
|
||||
const filteredOperationsByMetadata = operationsByMetadata.filter((operation) =>
|
||||
filterOperations(operation.operationMetaData)
|
||||
);
|
||||
|
||||
const supportedOperationsByField: Partial<Record<string, Set<OperationType>>> = {};
|
||||
const supportedOperationsWithoutField: Set<OperationType> = new Set();
|
||||
|
@ -59,4 +59,16 @@ export const getOperationSupportMatrix = (props: Props): OperationSupportMatrix
|
|||
operationWithoutField: supportedOperationsWithoutField,
|
||||
fieldByOperation: supportedFieldsByOperation,
|
||||
};
|
||||
}
|
||||
|
||||
// memoize based on latest execution. It supports multiple args
|
||||
const memoizedComputeOperationsMatrix = memoizeOne(computeOperationMatrix);
|
||||
|
||||
// TODO: the support matrix should be available outside of the dimension panel
|
||||
export const getOperationSupportMatrix = (props: Props): OperationSupportMatrix => {
|
||||
const layerId = props.layerId;
|
||||
const currentIndexPattern = props.state.indexPatterns[props.state.layers[layerId].indexPatternId];
|
||||
|
||||
const operationsByMetadata = memoizedGetAvailableOperationsByMetadata(currentIndexPattern);
|
||||
return memoizedComputeOperationsMatrix(operationsByMetadata, props.filterOperations);
|
||||
};
|
||||
|
|
|
@ -93,7 +93,7 @@ export function isDocumentOperation(type: string) {
|
|||
return documentOperations.has(type);
|
||||
}
|
||||
|
||||
type OperationFieldTuple =
|
||||
export type OperationFieldTuple =
|
||||
| {
|
||||
type: 'field';
|
||||
operationType: OperationType;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue