-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate saved object plugin into maps plugin (#67)
Signed-off-by: Junqiu Lei <[email protected]>
- Loading branch information
1 parent
c71a068
commit 61933bb
Showing
17 changed files
with
323 additions
and
106 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,25 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectAttributes } from 'opensearch-dashboards/server'; | ||
|
||
export interface MapSavedObjectAttributes extends SavedObjectAttributes { | ||
/** Title of the map */ | ||
title: string; | ||
/** Description of the map */ | ||
description?: string; | ||
/** State of the map, which could include current zoom level, lat, lng etc. */ | ||
mapState?: string; | ||
/** Maps-dashboards layers of the map */ | ||
layerList?: string; | ||
/** UI state of the map */ | ||
uiState?: string; | ||
/** Version is used to track version differences in saved object mapping */ | ||
version: number; | ||
/** SearchSourceFields is used to reference other saved objects */ | ||
searchSourceFields?: { | ||
index?: string; | ||
}; | ||
} |
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
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
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
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,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { MapPage } from './map_page'; |
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,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { MapContainer } from '../map_container'; | ||
import { MapTopNavMenu } from '../map_top_nav'; | ||
|
||
export const MapPage = () => { | ||
return ( | ||
<div> | ||
<MapTopNavMenu /> | ||
<MapContainer /> | ||
</div> | ||
); | ||
}; |
69 changes: 69 additions & 0 deletions
69
maps_dashboards/public/components/map_top_nav/get_top_nav_config.tsx
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,69 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@osd/i18n'; | ||
import { TopNavMenuData } from '../../../../../src/plugins/navigation/public'; | ||
import { | ||
OnSaveProps, | ||
SavedObjectSaveModalOrigin, | ||
showSaveModal, | ||
} from '../../../../../src/plugins/saved_objects/public'; | ||
import { MapServices } from '../../types'; | ||
|
||
export const getTopNavConfig = (services: MapServices) => { | ||
const { | ||
notifications: { toasts }, | ||
i18n: { Context: I18nContext }, | ||
savedObjects: { client: savedObjectsClient }, | ||
} = services; | ||
|
||
const topNavConfig: TopNavMenuData[] = [ | ||
{ | ||
iconType: 'save', | ||
emphasize: true, | ||
id: 'save', | ||
label: i18n.translate('maps.topNav.saveMapButtonLabel', { | ||
defaultMessage: `Save`, | ||
}), | ||
run: (_anchorElement) => { | ||
const onModalSave = async (onSaveProps: OnSaveProps) => { | ||
const savedMap = await savedObjectsClient.create('map', { | ||
title: onSaveProps.newTitle, | ||
description: onSaveProps.newDescription, | ||
// TODO: Integrate other attributes to saved object | ||
}); | ||
const id = savedMap.id; | ||
if (id) { | ||
toasts.addSuccess({ | ||
title: i18n.translate('map.topNavMenu.saveMap.successNotificationText', { | ||
defaultMessage: `Saved ${onSaveProps.newTitle}`, | ||
values: { | ||
visTitle: savedMap.attributes.title, | ||
}, | ||
}), | ||
}); | ||
} | ||
return { id }; | ||
}; | ||
|
||
const documentInfo = { | ||
title: '', | ||
description: '', | ||
}; | ||
const saveModal = ( | ||
<SavedObjectSaveModalOrigin | ||
documentInfo={documentInfo} | ||
onSave={onModalSave} | ||
objectType={'map'} | ||
onClose={() => {}} | ||
/> | ||
); | ||
showSaveModal(saveModal, I18nContext); | ||
}, | ||
}, | ||
]; | ||
return topNavConfig; | ||
}; |
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,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { MapTopNavMenu } from './top_nav_menu'; |
27 changes: 27 additions & 0 deletions
27
maps_dashboards/public/components/map_top_nav/top_nav_menu.tsx
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,27 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { PLUGIN_ID } from '../../../common'; | ||
import { getTopNavConfig } from './get_top_nav_config'; | ||
import { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public'; | ||
import { MapServices } from '../../types'; | ||
|
||
export const MapTopNavMenu = () => { | ||
const { services } = useOpenSearchDashboards<MapServices>(); | ||
const { | ||
setHeaderActionMenu, | ||
navigation: { | ||
ui: { TopNavMenu }, | ||
}, | ||
} = services; | ||
return ( | ||
<TopNavMenu | ||
appName={PLUGIN_ID} | ||
config={getTopNavConfig(services)} | ||
setMenuMountPoint={setHeaderActionMenu} | ||
/> | ||
); | ||
}; |
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
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.