Skip to content

Commit

Permalink
add data source in maps page
Browse files Browse the repository at this point in the history
  • Loading branch information
junqiu-lei committed Mar 13, 2024
1 parent 996474a commit c5da9b6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
32 changes: 30 additions & 2 deletions public/components/map_page/map_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { MapState } from '../../model/mapState';
import { GeoShapeFilterMeta, ShapeFilter } from '../../../../../src/plugins/data/common';
import { buildGeoShapeFilterMeta } from '../../model/geo/filter';
import { FilterBar } from '../filter_bar/filter_bar';
import { getDataLayers } from '../../model/layersFunctions';

export interface DashboardProps {
timeRange?: TimeRange;
Expand All @@ -49,15 +50,20 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon
const { services } = useOpenSearchDashboards<MapServices>();
const {
savedObjects: { client: savedObjectsClient },
dataSourceManagement,
setActionMenu,
notifications,
} = services;
const [layers, setLayers] = useState<MapLayerSpecification[]>([]);
const [savedMapObject, setSavedMapObject] =
useState<SimpleSavedObject<MapSavedObjectAttributes> | null>();
const [savedMapObject, setSavedMapObject] = useState<SimpleSavedObject<
MapSavedObjectAttributes
> | null>();
const [layersIndexPatterns, setLayersIndexPatterns] = useState<IndexPattern[]>([]);
const maplibreRef = useRef<Maplibre | null>(null);
const [mapState, setMapState] = useState<MapState>(getInitialMapState());
const [isUpdatingLayerRender, setIsUpdatingLayerRender] = useState(true);
const isReadOnlyMode = !!dashboardProps;
const [indexPatternIds, setIndexPatternIds] = useState<string[]>([]);

useEffect(() => {
if (mapIdFromSavedObject) {
Expand All @@ -75,6 +81,10 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon
savedIndexPatterns.push(indexPattern);
}
});
const ipIds: string[] = Array.from(
new Set(getDataLayers(layers).map((layer) => layer.source.indexPatternId))
);
setIndexPatternIds(ipIds);
setLayersIndexPatterns(savedIndexPatterns);
});
} else {
Expand Down Expand Up @@ -112,6 +122,10 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon
'globalFilterGroup__wrapper-isVisible': !!mapState.spatialMetaFilters?.length,
});

const dataSourceManagementEnabled: boolean = !!dataSourceManagement;

console.log(indexPatternIds, 'Print-----indexPatternIds-----MapComponent');

return (
<div className="map-page">
{isReadOnlyMode ? null : (
Expand All @@ -126,6 +140,20 @@ export const MapComponent = ({ mapIdFromSavedObject, dashboardProps }: MapCompon
setIsUpdatingLayerRender={setIsUpdatingLayerRender}
/>
)}
{dataSourceManagementEnabled && (
// @ts-ignore
<dataSourceManagement.ui.DataSourceMenu
setMenuMountPoint={setActionMenu}
showDataSourceAggregatedView={true}
activeDatasourceIds={indexPatternIds}
savedObjects={savedObjectsClient}
notifications={notifications}
appName={'mapsPageDataSourceMenu'}
hideLocalCluster={false}
fullWidth={true}
displayAllCompatibleDataSources={true}
/>
)}
{!isReadOnlyMode && !!mapState.spatialMetaFilters?.length && (
<div id="SpatiallFilterGroup" className="globalQueryBar">
<div className={filterGroupClasses}>
Expand Down
3 changes: 1 addition & 2 deletions public/components/maps_list/maps_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const MapsList = () => {
/>
);
const dataSourceManagementEnabled: boolean = !!dataSourceManagement;
console.log('test: ', setActionMenu);
// Render the map list DOM.
return (
<I18nProvider>
Expand All @@ -130,7 +129,7 @@ export const MapsList = () => {
showDataSourceAggregatedView={true}
savedObjects={savedObjectsClient}
notifications={notifications}
appName={'mapsListTestDataSourceMenu'}
appName={'mapsListDataSourceMenu'}
hideLocalCluster={false}
fullWidth={true}
displayAllCompatibleDataSources={true}
Expand Down

0 comments on commit c5da9b6

Please sign in to comment.