Skip to content

Commit

Permalink
Deprecate maps multi data source display (#651)
Browse files Browse the repository at this point in the history
Signed-off-by: Junqiu Lei <junqiu@amazon.com>
  • Loading branch information
junqiu-lei committed Aug 5, 2024
1 parent 7e742dc commit a433766
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 162 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Infrastructure
### Documentation
### Maintenance
* Deprecated maps multi data source display [#651](https://github.com/opensearch-project/dashboards-maps/pull/651)
### Refactoring
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"server": true,
"ui": true,
"requiredPlugins": ["regionMap", "opensearchDashboardsReact", "opensearchDashboardsUtils", "navigation", "savedObjects", "data", "embeddable", "visualizations"],
"optionalPlugins": ["home", "dataSource", "dataSourceManagement"]
"optionalPlugins": ["home"]
}
33 changes: 1 addition & 32 deletions public/components/layer_control_panel/layer_control_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { IndexPattern } from '../../../../../src/plugins/data/public';
import { AddLayerPanel } from '../add_layer_panel';
import { LayerConfigPanel } from '../layer_config';
import { MapLayerSpecification } from '../../model/mapLayerType';
import { DASHBOARDS_MAPS_LAYER_TYPE, LAYER_ICON_TYPE_MAP } from '../../../common';
import { LAYER_ICON_TYPE_MAP } from '../../../common';
import { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public';
import { MapServices } from '../../types';
import { MapState } from '../../model/mapState';
Expand All @@ -49,22 +49,18 @@ interface Props {
selectedLayerConfig: MapLayerSpecification | undefined;
setSelectedLayerConfig: (layerConfig: MapLayerSpecification | undefined) => void;
setIsUpdatingLayerRender: (isUpdatingLayerRender: boolean) => void;
setDataSourceRefIds: (dataSourceRefIds: string[]) => void;
}

export const LayerControlPanel = memo(
({
maplibreRef,
setLayers,
layers,
layersIndexPatterns,
setLayersIndexPatterns,
zoom,
isReadOnlyMode,
selectedLayerConfig,
setSelectedLayerConfig,
setIsUpdatingLayerRender,
setDataSourceRefIds,
}: Props) => {
const { services } = useOpenSearchDashboards<MapServices>();

Expand Down Expand Up @@ -209,39 +205,12 @@ export const LayerControlPanel = memo(
setIsDeleteLayerModalVisible(true);
};

const removeDataLayerDataSource = (layer: MapLayerSpecification) => {
if (layer.type === DASHBOARDS_MAPS_LAYER_TYPE.DOCUMENTS) {
const indexPatternId = layer.source.indexPatternId;
const indexPattern = layersIndexPatterns.find((idp) => idp.id === indexPatternId);
if (indexPattern) {
const indexPatternClone = [...layersIndexPatterns];
const index = indexPatternClone.findIndex((idp) => idp.id === indexPatternId);
if (index > -1) {
indexPatternClone.splice(index, 1);
setLayersIndexPatterns(indexPatternClone);
}
// remove duplicate dataSourceRefIds
const updatedDataSourceRefIds : string[] = [];
indexPatternClone.forEach((ip) => {
if (ip.dataSourceRef && !updatedDataSourceRefIds.includes(ip.dataSourceRef.id)) {
updatedDataSourceRefIds.push(ip.dataSourceRef.id);
} else if (!ip.dataSourceRef && !updatedDataSourceRefIds.includes('')) {
updatedDataSourceRefIds.push('');
}
});

setDataSourceRefIds(updatedDataSourceRefIds);
}
}
};

const onDeleteLayerConfirm = () => {
if (selectedDeleteLayer) {
removeLayers(maplibreRef.current!, selectedDeleteLayer.id, true);
removeLayer(selectedDeleteLayer.id);
setIsDeleteLayerModalVisible(false);
setSelectedDeleteLayer(undefined);
removeDataLayerDataSource(selectedDeleteLayer);
}
};

Expand Down
14 changes: 0 additions & 14 deletions public/components/map_container/map_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ interface MapContainerProps {
isUpdatingLayerRender: boolean;
setIsUpdatingLayerRender: (isUpdatingLayerRender: boolean) => void;
addSpatialFilter: (shape: ShapeFilter, label: string | null, relation: GeoShapeRelation) => void;
dataSourceRefIds: string[];
setDataSourceRefIds: (refIds: string[]) => void;
}

export class MapsServiceError extends Error {
Expand All @@ -69,7 +67,6 @@ export const MapContainer = ({
isUpdatingLayerRender,
setIsUpdatingLayerRender,
addSpatialFilter,
setDataSourceRefIds,
}: MapContainerProps) => {
const { services } = useOpenSearchDashboards<MapServices>();

Expand Down Expand Up @@ -248,16 +245,6 @@ export const MapContainer = ({
);
const cloneLayersIndexPatterns = [...layersIndexPatterns, newIndexPattern];
setLayersIndexPatterns(cloneLayersIndexPatterns);
const updatedDataSourceRefIds: string[] = [];
cloneLayersIndexPatterns.forEach((ip) => {
if (ip.dataSourceRef && !updatedDataSourceRefIds.includes(ip.dataSourceRef.id)) {
updatedDataSourceRefIds.push(ip.dataSourceRef.id);
} else if (!ip.dataSourceRef && !updatedDataSourceRefIds.includes('')) {
// If index pattern of the layer doesn't have reference to a data source, it is using local cluster
updatedDataSourceRefIds.push('');
}
});
setDataSourceRefIds(updatedDataSourceRefIds);
}
};

Expand All @@ -284,7 +271,6 @@ export const MapContainer = ({
selectedLayerConfig={selectedLayerConfig}
setSelectedLayerConfig={setSelectedLayerConfig}
setIsUpdatingLayerRender={setIsUpdatingLayerRender}
setDataSourceRefIds={setDataSourceRefIds}
/>
)}
{mounted && tooltipState === TOOLTIP_STATE.DISPLAY_FEATURES && maplibreRef.current && (
Expand Down
67 changes: 21 additions & 46 deletions public/components/map_page/map_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon
const [mapState, setMapState] = useState<MapState>(getInitialMapState());
const [isUpdatingLayerRender, setIsUpdatingLayerRender] = useState(true);
const isReadOnlyMode = !!dashboardProps;
const [dataSourceRefIds, setDataSourceRefIds] = useState<string[]>([]);
const [dataLoadReady, setDataLoadReady] = useState(false);

useEffect(() => {
if (mapIdFromSavedObject) {
Expand All @@ -71,39 +69,21 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon
setMapState(savedMapState);
setLayers(layerList);
const savedIndexPatterns: IndexPattern[] = [];
const remoteDataSourceIds: string[] = [];

const fetchDataLayer = async () => {
const requests = layerList
.filter((layer) => layer.type === DASHBOARDS_MAPS_LAYER_TYPE.DOCUMENTS)
.map((layer) => services.data.indexPatterns.get(layer.source.indexPatternId));

const resp = await Promise.all(requests);
resp.forEach((response: IndexPattern) => {
savedIndexPatterns.push(response);
if (response.dataSourceRef && !dataSourceRefIds.includes(response.dataSourceRef.id)) {
remoteDataSourceIds.push(response.dataSourceRef.id);
} else if (!response.dataSourceRef && !remoteDataSourceIds.includes('')) {
// If index pattern of the layer doesn't have reference to a data source, it is using local cluster
remoteDataSourceIds.push('');
}
});

setLayers(layerList);
setLayersIndexPatterns(savedIndexPatterns);
setDataSourceRefIds(remoteDataSourceIds);
setDataLoadReady(true);
};

fetchDataLayer();
layerList.forEach(async (layer: MapLayerSpecification) => {
if (layer.type === DASHBOARDS_MAPS_LAYER_TYPE.DOCUMENTS) {
const indexPatternId = layer.source.indexPatternId;
const indexPattern = await services.data.indexPatterns.get(indexPatternId);
savedIndexPatterns.push(indexPattern);
}
});
setLayersIndexPatterns(savedIndexPatterns);
});
} else {
const initialDefaultLayer: MapLayerSpecification = getLayerConfigMap()[
OPENSEARCH_MAP_LAYER.type
] as MapLayerSpecification;
] as MapLayerSpecification;
initialDefaultLayer.name = MAP_LAYER_DEFAULT_NAME;
setLayers([initialDefaultLayer]);
setDataLoadReady(true);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down Expand Up @@ -135,21 +115,18 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon

return (
<div className="map-page">
{isReadOnlyMode
? null
: dataLoadReady && (
<MapTopNavMenu
mapIdFromUrl={mapIdFromSavedObject}
savedMapObject={savedMapObject}
layers={layers}
layersIndexPatterns={layersIndexPatterns}
maplibreRef={maplibreRef}
mapState={mapState}
setMapState={setMapState}
setIsUpdatingLayerRender={setIsUpdatingLayerRender}
dataSourceRefIds={dataSourceRefIds}
/>
)}
{isReadOnlyMode ? null : (
<MapTopNavMenu
mapIdFromUrl={mapIdFromSavedObject}
savedMapObject={savedMapObject}
layers={layers}
layersIndexPatterns={layersIndexPatterns}
maplibreRef={maplibreRef}
mapState={mapState}
setMapState={setMapState}
setIsUpdatingLayerRender={setIsUpdatingLayerRender}
/>
)}
{!isReadOnlyMode && !!mapState.spatialMetaFilters?.length && (
<div id="SpatiallFilterGroup" className="globalQueryBar">
<div className={filterGroupClasses}>
Expand All @@ -173,8 +150,6 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon
isUpdatingLayerRender={isUpdatingLayerRender}
setIsUpdatingLayerRender={setIsUpdatingLayerRender}
addSpatialFilter={addSpatialFilter}
dataSourceRefIds={dataSourceRefIds}
setDataSourceRefIds={setDataSourceRefIds}
/>
</div>
);
Expand Down
60 changes: 20 additions & 40 deletions public/components/map_top_nav/top_nav_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ interface MapTopNavMenuProps {
setMapState: (mapState: MapState) => void;
originatingApp?: string;
setIsUpdatingLayerRender: (isUpdatingLayerRender: boolean) => void;
dataSourceRefIds: string[];
}

export const MapTopNavMenu = ({
Expand All @@ -38,7 +37,6 @@ export const MapTopNavMenu = ({
mapState,
setMapState,
setIsUpdatingLayerRender,
dataSourceRefIds,
}: MapTopNavMenuProps) => {
const { services } = useOpenSearchDashboards<MapServices>();
const {
Expand All @@ -50,9 +48,6 @@ export const MapTopNavMenu = ({
application: { navigateToApp },
embeddable,
scopedHistory,
dataSourceManagement,
savedObjects: { client: savedObjectsClient },
notifications,
} = services;

const [title, setTitle] = useState<string>('');
Expand Down Expand Up @@ -137,42 +132,27 @@ export const MapTopNavMenu = ({
});
}, [services, mapIdFromUrl, layers, title, description, mapState, originatingApp]);

const dataSourceManagementEnabled: boolean = !!dataSourceManagement;

return (
// @ts-ignore
<>
<TopNavMenu
appName={MAPS_APP_ID}
config={config}
setMenuMountPoint={setHeaderActionMenu}
indexPatterns={layersIndexPatterns || []}
showSearchBar={true}
showFilterBar={false}
showDatePicker={true}
showQueryBar={true}
showSaveQuery={true}
showQueryInput={true}
onQuerySubmit={handleQuerySubmit}
dateRangeFrom={dateFrom}
dateRangeTo={dateTo}
query={queryConfig}
isRefreshPaused={isRefreshPaused}
refreshInterval={refreshIntervalValue}
onRefresh={refreshDataLayerRender}
onRefreshChange={onRefreshChange}
showDataSourceMenu={dataSourceManagementEnabled}
dataSourceMenuConfig={{
componentType: 'DataSourceAggregatedView',
componentConfig: {
activeDataSourceIds: dataSourceRefIds,
savedObjects: savedObjectsClient,
notifications,
fullWidth: true,
displayAllCompatibleDataSources: false,
},
}}
/>
</>
<TopNavMenu
appName={MAPS_APP_ID}
config={config}
setMenuMountPoint={setHeaderActionMenu}
indexPatterns={layersIndexPatterns || []}
showSearchBar={true}
showFilterBar={false}
showDatePicker={true}
showQueryBar={true}
showSaveQuery={true}
showQueryInput={true}
onQuerySubmit={handleQuerySubmit}
dateRangeFrom={dateFrom}
dateRangeTo={dateTo}
query={queryConfig}
isRefreshPaused={isRefreshPaused}
refreshInterval={refreshIntervalValue}
onRefresh={refreshDataLayerRender}
onRefreshChange={onRefreshChange}
/>
);
};
19 changes: 0 additions & 19 deletions public/components/maps_list/maps_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { MapSavedObjectAttributes } from '../../../common/map_saved_object_attri
import { MapServices } from '../../types';
import { getMapsLandingBreadcrumbs } from '../../utils/breadcrumbs';
import { APP_PATH, MAPS_APP_ID } from '../../../common';
import { DataSourceAggregatedViewConfig } from '../../../../../src/plugins/data_source_management/public';

export const MapsList = () => {
const {
Expand All @@ -31,8 +30,6 @@ export const MapsList = () => {
savedObjects: { client: savedObjectsClient },
application: { navigateToApp },
chrome: { docTitle, setBreadcrumbs },
dataSourceManagement,
setActionMenu,
},
} = useOpenSearchDashboards<MapServices>();

Expand Down Expand Up @@ -116,29 +113,13 @@ export const MapsList = () => {
]}
/>
);
const dataSourceManagementEnabled: boolean = !!dataSourceManagement;

return (
<I18nProvider>
<>
<EuiPage restrictWidth="1000px">
<EuiPageBody component="main" data-test-subj="mapListingPage">
<EuiPageContentBody>
{dataSourceManagementEnabled && (() => {
const DataSourcesMenu = dataSourceManagement.ui.getDataSourceMenu<DataSourceAggregatedViewConfig>();
return (
<DataSourcesMenu
setMenuMountPoint={setActionMenu}
componentType={'DataSourceAggregatedView'}
componentConfig={{
savedObjects: savedObjectsClient,
notifications,
fullWidth: true,
displayAllCompatibleDataSources: true,
}}
/>
);
})()}
<TableListView
headingId="mapsListingHeading"
createItem={navigateToCreateMapPage}
Expand Down
7 changes: 2 additions & 5 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ export class CustomImportMapPlugin
}
public setup(
core: CoreSetup,
{ regionMap, embeddable, visualizations, dataSourceManagement }: AppPluginSetupDependencies
{ regionMap, embeddable, visualizations }: AppPluginSetupDependencies
): CustomImportMapPluginSetup {
const mapConfig: ConfigSchema = {
...this._initializerContext.config.get<ConfigSchema>(),
};
const dataSourceManagentEnabled: boolean = !!dataSourceManagement;
// Register an application into the side navigation menu
core.application.register({
id: MAPS_APP_ID,
Expand Down Expand Up @@ -93,12 +92,10 @@ export class CustomImportMapPlugin
scopedHistory: params.history,
uiSettings: coreStart.uiSettings,
mapConfig,
dataSourceManagement,
setActionMenu: params.setHeaderActionMenu,
};
params.element.classList.add('mapAppContainer');
// Render the application
return renderApp(params, services, dataSourceManagentEnabled);
return renderApp(params, services);
},
});

Expand Down
Loading

0 comments on commit a433766

Please sign in to comment.