Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import { ILayerImage } from '../../../../discrete-layer/models/layerImage';
import { LayerRasterRecordModelType } from '../../../../discrete-layer/models';
import { getIconStyle } from '../../../helpers/style';
import { getIconStyle, hasWFSLink } from '../../../helpers/style';
import { TypeIcon } from '../../shared/type-icon';

interface IProductTypeCellRendererParams {
Expand All @@ -18,7 +18,7 @@ export const ProductTypeRenderer: React.FC<IProductTypeCellRendererParams> = ({
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
const rasterData = data as LayerRasterRecordModelType;

if (onClick && rasterData.links?.some((link) => link.protocol === 'WFS')) {
if (onClick && hasWFSLink(rasterData as unknown as Record<string, unknown>)) {
onClick(data, !rasterData.polygonPartsShown);
}
};
Expand Down
18 changes: 10 additions & 8 deletions src/common/helpers/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export const isPolygonPartsShown = (data: Record<string, unknown>): boolean => {
return get(data, POLYGON_PARTS_SHOWN) === true;
};

export const hasWFSLink = (data: Record<string, unknown>): boolean => {
return (
(data.links as Array<Record<string, unknown>> | undefined)?.some(
(link) => link.protocol === 'WFS'
) ?? false
);
};

export const isUnpublishedValue = (value: string): boolean => {
return value === RecordStatus.UNPUBLISHED;
};
Expand Down Expand Up @@ -57,20 +65,14 @@ export const getIconStyle = (
resStyle = { [colorProperty]: UNPUBLISHED_COLOR };
}
if (existPolygonParts(data) && isPolygonPartsShown(data)) {
const hasWFSLink = (data.links as Array<Record<string, unknown>>)?.some(
(link) => link.protocol === 'WFS'
);
if (hasWFSLink) {
if (hasWFSLink(data)) {
resStyle = { [colorProperty]: POLYGON_PARTS_SHOWN_COLOR };
} else {
resStyle = { opacity: 0.5 };
}
}
if (existPolygonParts(data) && !isPolygonPartsShown(data)) {
const hasWFSLink = (data.links as Array<Record<string, unknown>>)?.some(
(link) => link.protocol === 'WFS'
);
if (!hasWFSLink) {
if (!hasWFSLink(data)) {
resStyle = {
...resStyle,
opacity: 0.5,
Expand Down
17 changes: 15 additions & 2 deletions src/common/hooks/mapMenus/useHandleMapMenuTemplates.hook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { useIntl } from 'react-intl';
import _ from 'lodash';
import _, { get } from 'lodash';
import { IContextMenuData } from '@map-colonies/react-components';
import {
DynamicMenuData,
Expand All @@ -20,6 +20,7 @@ import {
ContextActionsTemplates,
} from '../../actions/context.actions';
import CONFIG from '../../config';
import { hasWFSLink } from '../../helpers/style';

export const useHandleMapMenuTemplates = (
menuProperties?: IMapMenuProperties,
Expand Down Expand Up @@ -116,13 +117,25 @@ export const useHandleMapMenuTemplates = (
},
};

const layerHasWFSLink = hasWFSLink(
get(activeLayer, 'meta.layerRecord') as Record<string, unknown>
);

const generatedGroup: MenuItemsGroup = {
...groupTemplateMenuItem,
groupProps: groupProp,
title: groupProp.titleTranslationId,
items: groupTemplateMenuItem.items.map((item) => {
if (!isMenuItemGroup(item)) {
return { ...item, payloadData: activeLayer.meta as Record<string, unknown> };
const itemDisabled =
item.action.action === ContextActions.QUERY_POLYGON_PARTS
? !layerHasWFSLink
: item.disabled;
return {
...item,
disabled: itemDisabled,
payloadData: activeLayer.meta as Record<string, unknown>,
};
}

return item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const ActionsContextMenu: React.FC<IActionsContextMenuProps> = observer((
<Box className="contextMenuFooter">
<Box className="heightContainer">
<Icon className="menuIcon mc-icon-Height-DTM" />
<Typography tag="p">
<Typography tag="div">
{heightsAtCoordinates.isLoadingData ? <CircularProgress /> : getHeightText()}
</Typography>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const ContextMenu: React.FC<PropsWithChildren<IMapContextMenuData>> = ({

return (
<MenuItemWithSeparator
key={`menu_item_${menuItemOrGroup.title}_${idx}`}
separatorKeySuffix={`${idx}`}
separator={menuItemOrGroup.action.separator}
showSeparatorBefore={showSeparatorBefore}
Expand Down Expand Up @@ -196,11 +197,14 @@ export const ContextMenu: React.FC<PropsWithChildren<IMapContextMenuData>> = ({
})}
</TooltippedValue>
);
const groupDisabled = menuItemOrGroup.disabled ?? false;
groupToRender = (
<Submenu
key={`imageryMenuGroupItems_${menuItemOrGroup.groupProps.id}`}
dir={direction}
label={menuTitle}
disabled={groupDisabled}
style={{ pointerEvents: groupDisabled ? 'none' : 'unset' }}
onMouseOver={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
Expand All @@ -217,6 +221,7 @@ export const ContextMenu: React.FC<PropsWithChildren<IMapContextMenuData>> = ({

return (
<MenuItemWithSeparator
key={`menu_group_${menuItemOrGroup.groupProps.id}_${idx}`}
separatorKeySuffix={`${menuItemOrGroup.groupProps.id}`}
separator={menuItemOrGroup.groupProps.separator}
showSeparatorBefore={showSeparatorBefore}
Expand Down
1 change: 1 addition & 0 deletions src/discrete-layer/models/mapMenusManagerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface MenuItemsGroup extends CommonMenuItem {
groupProps: ContextActionGroupProps;
items: MenuItemsList;
icon?: string;
disabled?: boolean;
}


Expand Down
Loading