forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Drag & Drop Across Axis Functionality to Vis Builder (opensearch-…
…project#7107) * Add Drag Across Axis Functionality to Vis Builder Signed-off-by: Suchit Sahoo <suchsah@amazon.com> * Changeset file for PR opensearch-project#7107 created/updated --------- Signed-off-by: Suchit Sahoo <suchsah@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
60ecd36
commit 27669cf
Showing
20 changed files
with
855 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- Enhance Drag & Drop functionality in Vis Builder ([#7107](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7107)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/plugins/vis_builder/public/application/components/data_tab/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
67 changes: 67 additions & 0 deletions
67
...is_builder/public/application/components/data_tab/drag_drop/add_field_to_configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
const destinationSchemaName = destination?.droppableId; | ||
const destinationSchema = schemas.all.find((schema) => schema.name === destinationSchemaName); | ||
|
||
const newFieldToAdd = draggableId; | ||
|
||
if (!destinationSchema || !destinationSchemaName) { | ||
// Invalid drop target selected | ||
return; | ||
} | ||
|
||
const destinationFields = activeSchemaFields[destinationSchemaName]; | ||
|
||
if (!combine && destination && destinationFields.length > destinationSchema?.max) { | ||
// Can't Add additional Fields | ||
return; | ||
} | ||
|
||
// Adding the new field | ||
createNewAggConfig({ | ||
fieldName: newFieldToAdd, | ||
sourceGroup: source.droppableId, | ||
destinationSchema, | ||
aggProps, | ||
aggService, | ||
sourceAgg: null, | ||
}); | ||
|
||
const updatedAggConfigs = aggProps.aggConfigs?.aggs; | ||
|
||
if (updatedAggConfigs) { | ||
dispatch(updateAggConfigParams(updatedAggConfigs.map((agg) => agg.serialize()))); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...is_builder/public/application/components/data_tab/drag_drop/move_field_between_schemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
const destinationSchemaName = destination?.droppableId; | ||
if (!destinationSchemaName) { | ||
// Invalid Transition | ||
return; | ||
} | ||
const sourceAggId = draggableId; | ||
|
||
const destinationSchema = schemas.all.find( | ||
(schema) => schema.name === (destination?.droppableId || combine?.droppableId) | ||
); | ||
|
||
if (!destinationSchema) { | ||
// Invalid Transition | ||
return; | ||
} | ||
|
||
const sourceAgg = aggProps.aggConfigs?.aggs.find((agg) => agg.id === sourceAggId); | ||
const sourceFieldName = sourceAgg?.fieldName(); | ||
|
||
const destinationAggFields = activeSchemaFields[destinationSchemaName]; | ||
|
||
const destinationLimit = destinationSchema?.max; | ||
|
||
if (destinationLimit && destinationAggFields.length <= destinationLimit) { | ||
// destination schema has space for more items to be added | ||
// We Need to update sourceAgg | ||
|
||
createNewAggConfig({ | ||
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); | ||
|
||
if (updatedAggConfig?.length) { | ||
dispatch(updateAggConfigParams(updatedAggConfig.map((agg) => agg.serialize()))); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
..._builder/public/application/components/data_tab/drag_drop/reorder_fields_within_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
const destinationSchemaName = destination?.droppableId; | ||
if (!destinationSchemaName) { | ||
// Invalid Transition | ||
return; | ||
} | ||
const destinationAggFields = activeSchemaFields[destinationSchemaName]; | ||
|
||
const sourceAggId = draggableId; | ||
const destinationAggId = destinationAggFields[destination?.index].id; | ||
|
||
const destinationSchema = schemas.all.find((schema) => schema.name === destination?.droppableId); | ||
|
||
if (!destinationSchema) { | ||
// Invalid Transition | ||
return; | ||
} | ||
|
||
dispatch( | ||
reorderAgg({ | ||
sourceId: sourceAggId, | ||
destinationId: destinationAggId, | ||
}) | ||
); | ||
} |
80 changes: 80 additions & 0 deletions
80
...uilder/public/application/components/data_tab/drag_drop/replace_field_in_configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
const destinationSchemaName = combine?.droppableId; | ||
if (!destinationSchemaName) { | ||
return; | ||
} | ||
|
||
const sourceAggId = draggableId; | ||
const destinationAggId = combine?.draggableId; | ||
|
||
const destinationSchema = schemas.all.find((schema) => schema.name === combine?.droppableId); | ||
|
||
if (!destinationSchema) { | ||
// Invalid Transition | ||
return; | ||
} | ||
|
||
const sourceSchema = source.droppableId; | ||
|
||
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({ | ||
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); | ||
|
||
if (updatedAggConfig) { | ||
dispatch(updateAggConfigParams(updatedAggConfig.map((agg) => agg.serialize()))); | ||
} | ||
} else { | ||
// Replacing an existing configuration with another exisiting configuration | ||
|
||
const sourceAgg = aggProps.aggConfigs?.aggs.find((agg) => agg.id === sourceAggId); | ||
const sourceFieldName = sourceAgg?.fieldName(); | ||
|
||
createNewAggConfig({ | ||
fieldName: sourceFieldName, | ||
sourceGroup: source.droppableId, | ||
destinationSchema, | ||
aggProps, | ||
aggService, | ||
sourceAgg, | ||
}); | ||
|
||
// Removing the exisiting destination and source Aggregation | ||
const updatedAggConfig = aggProps.aggConfigs?.aggs.filter( | ||
(agg) => agg.id !== destinationAggId && agg.id !== sourceAggId | ||
); | ||
|
||
if (updatedAggConfig) { | ||
dispatch(updateAggConfigParams(updatedAggConfig.map((agg) => agg.serialize()))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.