-
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.
Signed-off-by: Junqiu Lei <[email protected]>
- Loading branch information
1 parent
5c18ec7
commit 80069ad
Showing
15 changed files
with
248 additions
and
141 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
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 { | ||
/** Tile of the map */ | ||
title: string; | ||
/** Description of the map */ | ||
description?: string; | ||
/** Map 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; | ||
/** Used to track version differences in saved object mapping */ | ||
version: number; | ||
/** 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
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} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.