Skip to content

Commit b20a4d8

Browse files
committed
Make imported type not editable
1 parent 21db483 commit b20a4d8

File tree

1 file changed

+38
-9
lines changed
  • workspaces/ballerina/type-diagram/src/components/entity-relationship/EntityNode/EntityHead

1 file changed

+38
-9
lines changed

workspaces/ballerina/type-diagram/src/components/entity-relationship/EntityNode/EntityHead/EntityHead.tsx

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { EntityHead, EntityName } from '../styles';
2424
import { CtrlClickGo2Source } from '../../../common/CtrlClickHandler/CtrlClickGo2Source';
2525
import { DiagramContext } from '../../../common';
2626
import styled from '@emotion/styled';
27-
import { Button, Item, Menu, MenuItem, Popover } from '@wso2/ui-toolkit';
27+
import { Button, Item, Menu, MenuItem, Popover, ThemeColors } from '@wso2/ui-toolkit';
2828
import { MoreVertIcon } from '../../../../resources';
2929
import { GraphQLIcon } from '../../../../resources/assets/icons/GraphqlIcon';
3030

@@ -68,11 +68,25 @@ const HeaderWrapper = styled.div`
6868
width: 100%;
6969
`;
7070

71+
const ImportedLabel = styled.span`
72+
background-color: ${ThemeColors.SURFACE_CONTAINER};
73+
border-radius: 3px;
74+
color: ${ThemeColors.ON_SURFACE_VARIANT};
75+
font-family: GilmerRegular;
76+
font-size: 10px;
77+
height: 20px;
78+
line-height: 20px;
79+
padding: 0 6px;
80+
margin-left: 8px;
81+
white-space: nowrap;
82+
`;
83+
7184
export function EntityHeadWidget(props: ServiceHeadProps) {
7285
const { engine, node, isSelected } = props;
7386
const { setFocusedNodeId, onEditNode, goToSource } = useContext(DiagramContext);
7487

7588
const displayName: string = node.getID()?.slice(node.getID()?.lastIndexOf(':') + 1);
89+
const isImported = !node?.entityObject?.editable;
7690

7791
const [anchorEl, setAnchorEl] = useState<HTMLElement | SVGSVGElement>(null);
7892
const isMenuOpen = Boolean(anchorEl);
@@ -82,7 +96,7 @@ export function EntityHeadWidget(props: ServiceHeadProps) {
8296
};
8397

8498
const onNodeEdit = () => {
85-
if (onEditNode) {
99+
if (onEditNode && node?.entityObject?.editable) {
86100
if (node.isGraphqlRoot) {
87101
onEditNode(node.getID(), true);
88102
} else {
@@ -103,13 +117,23 @@ export function EntityHeadWidget(props: ServiceHeadProps) {
103117
}
104118

105119
const menuItems: Item[] = [
120+
...(node?.entityObject?.editable ? [
121+
{
122+
id: "edit",
123+
label: "Edit",
124+
onClick: () => onNodeEdit(),
125+
},
126+
{
127+
id: "goToSource",
128+
label: "Source",
129+
onClick: () => onGoToSource()
130+
}
131+
] : []),
106132
{
107-
id: "edit",
108-
label: "Edit",
109-
onClick: () => onNodeEdit(),
110-
},
111-
{ id: "goToSource", label: "Source", onClick: () => onGoToSource() },
112-
{ id: "focusView", label: "Focused View", onClick: () => onFocusedView() }
133+
id: "focusView",
134+
label: "Focused View",
135+
onClick: () => onFocusedView()
136+
}
113137
];
114138

115139
const isClickable = true;
@@ -133,12 +157,17 @@ export function EntityHeadWidget(props: ServiceHeadProps) {
133157
</div>
134158
)}
135159
<EntityName
136-
isClickable={isClickable}
160+
isClickable={isClickable && !isImported}
137161
onClick={onNodeEdit}
138162
onDoubleClick={onFocusedView}
139163
>
140164
{displayName}
141165
</EntityName>
166+
{isImported && (
167+
<ImportedLabel>
168+
Imported Type
169+
</ImportedLabel>
170+
)}
142171
</EntityNameContainer>
143172
<HeaderButtonsContainer>
144173
{/* {selectedNodeId === node.getID() && (

0 commit comments

Comments
 (0)