Skip to content

Commit

Permalink
Revert "improve field drag defaults"
Browse files Browse the repository at this point in the history
This reverts commit 6b36c12.
  • Loading branch information
flash1293 committed Sep 6, 2022
1 parent 6b36c12 commit 19fc2f7
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ export function getNewOperation(
field: IndexPatternField | undefined | false,
filterOperations: (meta: OperationMetadata) => boolean,
targetColumn?: GenericIndexPatternColumn,
prioritizedOperation?: GenericIndexPatternColumn['operationType'],
alreadyUsedOperations?: Set<string>
prioritizedOperation?: GenericIndexPatternColumn['operationType']
) {
if (!field) {
return;
}
const newOperations = getOperationTypesForField(field, filterOperations, alreadyUsedOperations);
const newOperations = getOperationTypesForField(field, filterOperations);
if (!newOperations.length) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,56 +146,6 @@ describe('IndexPatternDimensionEditorPanel: onDrop', () => {
},
});
});
it('does not re-use an operation if there is another operation available', () => {
const localState = {
...state,
layers: {
...state.layers,
first: {
...state.layers.first,
columns: {
...state.layers.first.columns,
col1: {
...state.layers.first.columns.col1,
sourceField: mockedDraggedField.field.name,
operationType: 'median',
},
},
},
},
};
onDrop({
...defaultProps,
state: localState,
source: mockedDraggedField,
dropType: 'field_replace',
target: {
...defaultProps.target,
filterOperations: (op: OperationMetadata) => !op.isBucketed,
columnId: 'col2',
},
});

expect(setState).toBeCalledTimes(1);
expect(setState).toHaveBeenCalledWith({
...localState,
layers: {
...localState.layers,
first: {
...localState.layers.first,
columnOrder: ['col1', 'col2'],
columns: {
...localState.layers.first.columns,
col2: expect.objectContaining({
operationType: 'average',
dataType: 'number',
sourceField: mockedDraggedField.field.name,
}),
},
},
},
});
});
it('keeps the operation when dropping a different compatible field', () => {
onDrop({
...defaultProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,9 @@ function onFieldDrop(props: DropHandlerProps<DraggedField>, shouldAddField?: boo
const layer = state.layers[target.layerId];
const indexPattern = indexPatterns[layer.indexPatternId];
const targetColumn = layer.columns[target.columnId];
// discourage already used operations for a field
const alreadyUsedOperations = new Set(
Object.values(layer.columns)
.map((column) =>
'sourceField' in column && column.sourceField === source.field.name
? column.operationType
: undefined
)
.filter(Boolean) as string[]
);

const newOperation = shouldAddField
? targetColumn.operationType
: getNewOperation(
source.field,
target.filterOperations,
targetColumn,
prioritizedOperation,
alreadyUsedOperations
);
: getNewOperation(source.field, target.filterOperations, targetColumn, prioritizedOperation);

if (
!isDraggedField(source) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ export function hasOperationSupportForMultipleFields(
*/
export function getOperationTypesForField(
field: IndexPatternField,
filterOperations?: (operation: OperationMetadata) => boolean,
alreadyUsedOperations?: Set<string>
filterOperations?: (operation: OperationMetadata) => boolean
): OperationType[] {
return operationDefinitions
.filter((operationDefinition) => {
Expand All @@ -125,15 +124,6 @@ export function getOperationTypesForField(
: possibleOperation;
})
.sort(getSortScoreByPriorityForField(field))
.sort((a, b) => {
if (!alreadyUsedOperations) return 0;
// if some operations are used already, order them so the unused operations come first
const aAlreadyUsed = alreadyUsedOperations.has(a.type);
const bAlreadyUsed = alreadyUsedOperations.has(b.type);
if (aAlreadyUsed === bAlreadyUsed) return 0;
if (aAlreadyUsed) return 1;
return -1;
})
.map(({ type }) => type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ export const getMetricVisualization = ({
enableFormatSelector: false,
formatSelectorOptions: formatterOptions,
supportStaticValue: true,
prioritizedOperation: 'max',
required: false,
groupTooltip: i18n.translate('xpack.lens.metric.maxTooltip', {
defaultMessage:
Expand Down

0 comments on commit 19fc2f7

Please sign in to comment.