Skip to content

Commit

Permalink
Use new header to maps vis page
Browse files Browse the repository at this point in the history
Signed-off-by: Junqiu Lei <[email protected]>
  • Loading branch information
junqiu-lei committed Aug 9, 2024
1 parent 0fab5fa commit f68d6c5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
45 changes: 45 additions & 0 deletions public/components/map_top_nav/get_top_nav_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface GetTopNavConfigParams {
setDescription: (description: string) => void;
mapState: MapState;
originatingApp?: string;
showActionsInGroup: boolean;
}

export const getTopNavConfig = (
Expand All @@ -38,6 +39,7 @@ export const getTopNavConfig = (
setDescription,
mapState,
originatingApp,
showActionsInGroup,
}: GetTopNavConfigParams
) => {
const {
Expand All @@ -46,6 +48,49 @@ export const getTopNavConfig = (
scopedHistory,
} = services;
const stateTransfer = embeddable.getStateTransfer(scopedHistory);
if (showActionsInGroup) {
const topNavConfig: TopNavMenuData[] = [
{
tooltip: i18n.translate('maps.topNav.saveMapButtonLabel', {
defaultMessage: `Save`,
}),
ariaLabel: i18n.translate('maps.topNav.saveButtonAriaLabel', {
defaultMessage: 'Save your map',
}),
testId: 'mapSaveButton',
run: (_anchorElement: any) => {
const documentInfo = {
title,
description,
};
const saveModal = (
<SavedObjectSaveModalOrigin
documentInfo={documentInfo}
onSave={onGetSave(
title,
originatingApp,
mapIdFromUrl,
services,
layers,
mapState,
setTitle,
setDescription
)}
objectType={'map'}
onClose={() => {}}
originatingApp={originatingApp}
getAppNameFromId={stateTransfer.getAppNameFromId}
/>
);
showSaveModal(saveModal, I18nContext);
},
iconType: 'save',
controlType: 'icon',
}
];
return topNavConfig;
}

const topNavConfig: TopNavMenuData[] = [
{
iconType: 'save',
Expand Down
18 changes: 17 additions & 1 deletion public/components/map_top_nav/top_nav_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getSavedMapBreadcrumbs } from '../../utils/breadcrumbs';
import { handleDataLayerRender } from '../../model/layerRenderController';
import { MapLayerSpecification } from '../../model/mapLayerType';
import { MapState } from '../../model/mapState';
import { HeaderVariant } from '../../../../../src/core/public';

interface MapTopNavMenuProps {
mapIdFromUrl: string;
Expand Down Expand Up @@ -48,9 +49,10 @@ export const MapTopNavMenu = ({
application: { navigateToApp },
embeddable,
scopedHistory,
uiSettings,
} = services;

const [title, setTitle] = useState<string>('');
const [title, setTitle] = useState<string>('Untitled');
const [description, setDescription] = useState<string>('');
const [dateFrom, setDateFrom] = useState<string>('');
const [dateTo, setDateTo] = useState<string>('');
Expand All @@ -65,6 +67,17 @@ export const MapTopNavMenu = ({
},
[chrome, navigateToApp]
);
const showActionsInGroup = uiSettings.get('home:useNewHomePage');

useEffect(() => {
if (showActionsInGroup) {
chrome.setHeaderVariant?.(HeaderVariant.APPLICATION);
}

return () => {
chrome.setHeaderVariant?.();
};
}, [chrome.setHeaderVariant, showActionsInGroup]);

useEffect(() => {
const { originatingApp: value } =
Expand Down Expand Up @@ -129,6 +142,7 @@ export const MapTopNavMenu = ({
setDescription,
mapState,
originatingApp,
showActionsInGroup,
});
}, [services, mapIdFromUrl, layers, title, description, mapState, originatingApp]);

Expand All @@ -153,6 +167,8 @@ export const MapTopNavMenu = ({
refreshInterval={refreshIntervalValue}
onRefresh={refreshDataLayerRender}
onRefreshChange={onRefreshChange}
groupActions={showActionsInGroup}
screenTitle={title}
/>
);
};

0 comments on commit f68d6c5

Please sign in to comment.