-
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
Signed-off-by: Junqiu Lei <[email protected]>
- Loading branch information
1 parent
c71a068
commit d7270dc
Showing
17 changed files
with
327 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> | ||
); | ||
}; |
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
/* | ||
* 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 { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public'; | ||
import { MapServices } from '../../types'; | ||
|
||
export const getTopNavConfig = () => { | ||
const { | ||
services: { | ||
notifications: { toasts }, | ||
i18n: { Context: I18nContext }, | ||
savedObjects: { client: savedObjectsClient }, | ||
}, | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
} = useOpenSearchDashboards<MapServices>(); | ||
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'; |
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
/* | ||
* 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: { | ||
setHeaderActionMenu, | ||
navigation: { | ||
ui: { TopNavMenu }, | ||
}, | ||
}, | ||
} = useOpenSearchDashboards<MapServices>(); | ||
return ( | ||
<TopNavMenu | ||
appName={PLUGIN_ID} | ||
config={getTopNavConfig()} | ||
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.