Skip to content

Commit 1d4438e

Browse files
fundonlihebi
andauthored
fix: #98 (#130) use lightblue scope theming
* fix: #98 * chore: fmt Co-authored-by: Hebi Li <[email protected]>
1 parent 1509a3f commit 1d4438e

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

ui/src/components/Canvas.tsx

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
7272
const ref = useRef(null);
7373
const store = useContext(RepoContext);
7474
if (!store) throw new Error("Missing BearContext.Provider in the tree");
75+
const flow = useReactFlow();
7576
const getPod = useStore(store, (state) => state.getPod);
7677
const pod = getPod(id);
7778
const setPodName = useStore(store, (state) => state.setPodName);
@@ -84,6 +85,19 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
8485
const selected = useStore(store, (state) => state.pods[id]?.selected);
8586
const role = useStore(store, (state) => state.role);
8687

88+
const deleteNodeById = useCallback(
89+
(id: string) => {
90+
flow.deleteElements({
91+
nodes: [
92+
{
93+
id,
94+
},
95+
],
96+
});
97+
},
98+
[flow]
99+
);
100+
87101
const onResize = useCallback(({ width, height, offx, offy }) => {
88102
const node = nodesMap.get(id);
89103
if (node) {
@@ -97,6 +111,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
97111
React.useEffect(() => {
98112
setTarget(ref.current);
99113
}, []);
114+
100115
return (
101116
<Box
102117
ref={ref}
@@ -108,6 +123,35 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
108123
}}
109124
className="custom-drag-handle"
110125
>
126+
<Box
127+
sx={{
128+
display: "flex",
129+
marginLeft: "10px",
130+
borderRadius: "4px",
131+
position: "absolute",
132+
border: "solid 1px #d6dee6",
133+
right: "25px",
134+
top: "-15px",
135+
background: "white",
136+
zIndex: 250,
137+
justifyContent: "center",
138+
}}
139+
>
140+
{role !== RoleType.GUEST && (
141+
<Tooltip title="Delete">
142+
<IconButton
143+
size="small"
144+
onClick={(e: any) => {
145+
e.stopPropagation();
146+
e.preventDefault();
147+
deleteNodeById(id);
148+
}}
149+
>
150+
<DeleteIcon fontSize="inherit" />
151+
</IconButton>
152+
</Tooltip>
153+
)}
154+
</Box>
111155
<Handle
112156
type="source"
113157
position={Position.Top}
@@ -181,7 +225,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
181225
renderDirections={["e", "s", "se"]}
182226
edge={false}
183227
zoom={1}
184-
origin={true}
228+
origin={false}
185229
padding={{ left: 0, top: 0, right: 0, bottom: 0 }}
186230
onResizeStart={(e) => {
187231
e.setOrigin(["%", "%"]);
@@ -580,11 +624,11 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
580624
const nodeTypes = { scope: ScopeNode, code: CodeNode };
581625

582626
const level2color = {
583-
0: "rgba(255, 0, 0, 0.2)",
584-
1: "rgba(255, 0, 255, 0.2)",
585-
2: "rgba(0, 255, 255, 0.2)",
586-
3: "rgba(0, 255, 0, 0.2)",
587-
4: "rgba(255, 255, 0, 0.2)",
627+
0: "rgba(187, 222, 251, 0.5)",
628+
1: "rgba(144, 202, 249, 0.5)",
629+
2: "rgba(100, 181, 246, 0.5)",
630+
3: "rgba(66, 165, 245, 0.5)",
631+
4: "rgba(33, 150, 243, 0.5)",
588632
// default: "rgba(255, 255, 255, 0.2)",
589633
default: "rgba(240,240,240,0.25)",
590634
};
@@ -993,16 +1037,16 @@ export function Canvas() {
9931037
<Box>
9941038
<MiniMap
9951039
nodeStrokeColor={(n) => {
996-
if (n.style?.background) return n.style.background as string;
997-
if (n.type === "code") return "#0041d0";
998-
if (n.type === "scope") return "#ff0072";
1040+
if (n.style?.borderColor) return n.style.borderColor;
1041+
if (n.type === "code") return "#d6dee6";
1042+
if (n.type === "scope") return "#f4f6f8";
9991043

1000-
return "#1a192b";
1044+
return "#d6dee6";
10011045
}}
10021046
nodeColor={(n) => {
10031047
if (n.style?.backgroundColor) return n.style.backgroundColor;
10041048

1005-
return "#1a192b";
1049+
return "#f4f6f8";
10061050
}}
10071051
nodeBorderRadius={2}
10081052
/>

ui/src/lib/store.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ export interface RepoSlice {
167167
{ parent, index, anchor, shift, id, type, lang, x, y, width, height }: any
168168
) => void;
169169
deletePod: (
170-
client,
171-
{ id, toDelete }: { id: string; toDelete: any[] }
172-
) => void;
170+
client: ApolloClient<object> | null,
171+
{ id, toDelete }: { id: string; toDelete: string[] }
172+
) => Promise<void>;
173173
setPodResult: ({
174174
id,
175175
content,
@@ -325,13 +325,15 @@ const createRepoSlice: StateCreator<
325325
}
326326
},
327327
deletePod: async (
328-
client,
328+
client: ApolloClient<object> | null,
329329
{ id, toDelete }: { id: string; toDelete: string[] }
330330
) => {
331331
const pods = get().pods;
332+
332333
// get all ids to delete. Gathering them here is easier than on the server
333334

334-
// TOFIX: check pods[id] exists before deleting
335+
if (!pods[id]) return;
336+
335337
const dfs = (id) => {
336338
const pod = pods[id];
337339
if (pod) {
@@ -705,8 +707,13 @@ const createRepoSlice: StateCreator<
705707
);
706708
},
707709
loadRepo: async (client, id) => {
708-
const { pods, name, error, userId, collaboratorIds } =
709-
await doRemoteLoadRepo({ id, client });
710+
const {
711+
pods,
712+
name,
713+
error,
714+
userId,
715+
collaboratorIds,
716+
} = await doRemoteLoadRepo({ id, client });
710717
set(
711718
produce((state) => {
712719
// TODO the children ordered by index

0 commit comments

Comments
 (0)