-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
Signed-off-by: Suchit Sahoo <suchsah@amazon.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export enum FIELD_SELECTOR_ID { | ||
COUNT = 'preDefinedCountMetric', | ||
CATEGORICAL = 'categoricalFields', | ||
NUMERICAL = 'numericalFields', | ||
META = 'metaFields', | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DropResult } from '@elastic/eui'; | ||
import { AnyAction } from 'redux'; | ||
import { createNewAggConfig } from '../utils/get_valid_aggregations'; | ||
import { updateAggConfigParams } from '../../../utils/state_management/visualization_slice'; | ||
import { Schemas } from '../../../../../../vis_default_editor/public'; | ||
import { AggProps } from '../config_panel'; | ||
import { SchemaDisplayStates } from '../index'; | ||
import { Dispatch } from '../../../../../../opensearch_dashboards_utils/common/state_containers/types'; | ||
import { AggsStart } from '../../../../../../data/common'; | ||
|
||
export interface DragDropProperties { | ||
dropResult: DropResult; | ||
schemas: Schemas; | ||
aggProps: AggProps; | ||
aggService: AggsStart; | ||
activeSchemaFields: SchemaDisplayStates; | ||
dispatch: Dispatch<AnyAction>; | ||
} | ||
|
||
export function addFieldToConfiguration({ | ||
dropResult, | ||
schemas, | ||
aggProps, | ||
aggService, | ||
activeSchemaFields, | ||
dispatch, | ||
}: DragDropProperties) { | ||
const { source, destination, combine, draggableId } = dropResult; | ||
Check warning on line 33 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L33
|
||
|
||
const destinationSchemaName = destination?.droppableId; | ||
const destinationSchema = schemas.all.find((schema) => schema.name === destinationSchemaName); | ||
Check warning on line 36 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L35-L36
|
||
|
||
const newFieldToAdd = draggableId; | ||
Check warning on line 38 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L38
|
||
|
||
if (!destinationSchema || !destinationSchemaName) { | ||
// Invalid drop target selected | ||
return; | ||
Check warning on line 42 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L42
|
||
} | ||
|
||
const destinationFields = activeSchemaFields[destinationSchemaName]; | ||
Check warning on line 45 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L45
|
||
|
||
if (!combine && destination && destinationFields.length >= destinationSchema?.max) { | ||
// Can't Add additional Fields | ||
return; | ||
Check warning on line 49 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L49
|
||
} | ||
|
||
// Adding the new field | ||
createNewAggConfig({ | ||
Check warning on line 53 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L53
|
||
fieldName: newFieldToAdd, | ||
sourceGroup: source.droppableId, | ||
destinationSchema, | ||
aggProps, | ||
aggService, | ||
sourceAgg: null, | ||
}); | ||
|
||
const updatedAggConfigs = aggProps.aggConfigs?.aggs; | ||
Check warning on line 62 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L62
|
||
|
||
if (updatedAggConfigs) { | ||
dispatch(updateAggConfigParams(updatedAggConfigs.map((agg) => agg.serialize()))); | ||
Check warning on line 65 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts#L65
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { updateAggConfigParams } from '../../../utils/state_management/visualization_slice'; | ||
import { createNewAggConfig } from '../utils/get_valid_aggregations'; | ||
import { DragDropProperties } from './add_field_to_configuration'; | ||
|
||
export function moveFieldBetweenSchemas({ | ||
dropResult, | ||
schemas, | ||
aggProps, | ||
aggService, | ||
activeSchemaFields, | ||
dispatch, | ||
}: DragDropProperties) { | ||
const { source, destination, combine, draggableId } = dropResult; | ||
Check warning on line 18 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L18
|
||
|
||
const destinationSchemaName = destination?.droppableId; | ||
Check warning on line 20 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L20
|
||
if (!destinationSchemaName) { | ||
// Invalid Transition | ||
return; | ||
Check warning on line 23 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L23
|
||
} | ||
const sourceAggId = draggableId; | ||
Check warning on line 25 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L25
|
||
|
||
const destinationSchema = schemas.all.find( | ||
Check warning on line 27 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L27
|
||
(schema) => schema.name === (destination?.droppableId || combine?.droppableId) | ||
); | ||
|
||
if (!destinationSchema) { | ||
// Invalid Transition | ||
return; | ||
Check warning on line 33 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L33
|
||
} | ||
|
||
const sourceAgg = aggProps.aggConfigs?.aggs.find((agg) => agg.id === sourceAggId); | ||
const sourceFieldName = sourceAgg?.fieldName(); | ||
Check warning on line 37 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L36-L37
|
||
|
||
const destinationAggFields = activeSchemaFields[destinationSchemaName]; | ||
Check warning on line 39 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L39
|
||
|
||
const destinationLimit = destinationSchema?.max; | ||
Check warning on line 41 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L41
|
||
|
||
if (destinationLimit && destinationAggFields.length <= destinationLimit) { | ||
// destination schema has space for more items to be added | ||
// We Need to update sourceAgg | ||
|
||
createNewAggConfig({ | ||
Check warning on line 47 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L47
|
||
fieldName: sourceFieldName, | ||
sourceGroup: source.droppableId, | ||
destinationSchema, | ||
aggProps, | ||
aggService, | ||
sourceAgg, | ||
}); | ||
|
||
// Remove the sourceAggConfig from the updated Config | ||
const updatedAggConfig = aggProps.aggConfigs?.aggs.filter((agg) => agg.id !== sourceAggId); | ||
Check warning on line 57 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L57
|
||
|
||
if (updatedAggConfig?.length) { | ||
dispatch(updateAggConfigParams(updatedAggConfig.map((agg) => agg.serialize()))); | ||
Check warning on line 60 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts#L60
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { reorderAgg } from '../../../utils/state_management/visualization_slice'; | ||
import { DragDropProperties } from './add_field_to_configuration'; | ||
|
||
export function reorderFieldsWithinSchema({ | ||
dropResult, | ||
schemas, | ||
activeSchemaFields, | ||
dispatch, | ||
}: DragDropProperties) { | ||
const { destination, draggableId } = dropResult; | ||
Check warning on line 15 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L15
|
||
|
||
const destinationSchemaName = destination?.droppableId; | ||
Check warning on line 17 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L17
|
||
if (!destinationSchemaName) { | ||
// Invalid Transition | ||
return; | ||
Check warning on line 20 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L20
|
||
} | ||
const destinationAggFields = activeSchemaFields[destinationSchemaName]; | ||
Check warning on line 22 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L22
|
||
|
||
const sourceAggId = draggableId; | ||
const destinationAggId = destinationAggFields[destination?.index].id; | ||
Check warning on line 25 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L24-L25
|
||
|
||
const destinationSchema = schemas.all.find((schema) => schema.name === destination?.droppableId); | ||
Check warning on line 27 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L27
|
||
|
||
if (!destinationSchema) { | ||
// Invalid Transition | ||
return; | ||
Check warning on line 31 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L31
|
||
} | ||
|
||
dispatch( | ||
Check warning on line 34 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts#L34
|
||
reorderAgg({ | ||
sourceId: sourceAggId, | ||
destinationId: destinationAggId, | ||
}) | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { updateAggConfigParams } from '../../../utils/state_management/visualization_slice'; | ||
import { FIELD_SELECTOR_ID } from '../constants'; | ||
import { createNewAggConfig } from '../utils/get_valid_aggregations'; | ||
import { DragDropProperties } from './add_field_to_configuration'; | ||
|
||
export function replaceFieldInConfiguration({ | ||
dropResult, | ||
schemas, | ||
aggProps, | ||
aggService, | ||
dispatch, | ||
}: DragDropProperties) { | ||
const { source, combine, draggableId } = dropResult; | ||
Check warning on line 18 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L18
|
||
|
||
const destinationSchemaName = combine?.droppableId; | ||
Check warning on line 20 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L20
|
||
if (!destinationSchemaName) { | ||
return; | ||
Check warning on line 22 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L22
|
||
} | ||
|
||
const sourceAggId = draggableId; | ||
const destinationAggId = combine?.draggableId; | ||
Check warning on line 26 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L25-L26
|
||
|
||
const destinationSchema = schemas.all.find((schema) => schema.name === combine?.droppableId); | ||
Check warning on line 28 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L28
|
||
|
||
if (!destinationSchema) { | ||
// Invalid Transition | ||
return; | ||
Check warning on line 32 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L32
|
||
} | ||
|
||
const sourceSchema = source.droppableId; | ||
Check warning on line 35 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L35
|
||
|
||
if (Object.values(FIELD_SELECTOR_ID).includes(sourceSchema as FIELD_SELECTOR_ID)) { | ||
// Replacing an exisitng configuration with a new field from field selector panel | ||
|
||
const newFieldToAdd = draggableId; | ||
createNewAggConfig({ | ||
Check warning on line 41 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L40-L41
|
||
fieldName: newFieldToAdd, | ||
sourceGroup: source.droppableId, | ||
destinationSchema, | ||
aggProps, | ||
aggService, | ||
sourceAgg: null, | ||
}); | ||
|
||
// Removing the exisiting destination Aggregation | ||
const updatedAggConfig = aggProps.aggConfigs?.aggs.filter((agg) => agg.id !== destinationAggId); | ||
Check warning on line 51 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L51
|
||
|
||
if (updatedAggConfig) { | ||
dispatch(updateAggConfigParams(updatedAggConfig.map((agg) => agg.serialize()))); | ||
Check warning on line 54 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L54
|
||
} | ||
} else { | ||
// Replacing an existing configuration with another exisiting configuration | ||
|
||
const sourceAgg = aggProps.aggConfigs?.aggs.find((agg) => agg.id === sourceAggId); | ||
const sourceFieldName = sourceAgg?.fieldName(); | ||
Check warning on line 60 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L59-L60
|
||
|
||
createNewAggConfig({ | ||
Check warning on line 62 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L62
|
||
fieldName: sourceFieldName, | ||
sourceGroup: source.droppableId, | ||
destinationSchema, | ||
aggProps, | ||
aggService, | ||
sourceAgg, | ||
}); | ||
|
||
// Removing the exisiting destination and source Aggregation | ||
const updatedAggConfig = aggProps.aggConfigs?.aggs.filter( | ||
Check warning on line 72 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L72
|
||
(agg) => agg.id !== destinationAggId && agg.id !== sourceAggId | ||
); | ||
|
||
if (updatedAggConfig) { | ||
dispatch(updateAggConfigParams(updatedAggConfig.map((agg) => agg.serialize()))); | ||
Check warning on line 77 in src/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts Codecov / codecov/patchsrc/plugins/vis_builder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts#L77
|
||
} | ||
} | ||
} |