Skip to content

Commit 0279ccc

Browse files
li-xin-yilihebi
andauthored
Fix: remove output indices and horizontal scroll bar in result blocks (#133)
* Fix: remove output index * use dummy index=0 for graphql query Co-authored-by: Hebi Li <[email protected]>
1 parent bd9201f commit 0279ccc

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

ui/src/components/Canvas.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
7373
const store = useContext(RepoContext);
7474
if (!store) throw new Error("Missing BearContext.Provider in the tree");
7575
const flow = useReactFlow();
76-
const getPod = useStore(store, (state) => state.getPod);
77-
const pod = getPod(id);
7876
const setPodName = useStore(store, (state) => state.setPodName);
7977
const updatePod = useStore(store, (state) => state.updatePod);
8078
const [target, setTarget] = React.useState<any>();
@@ -321,8 +319,8 @@ function ResultBlock({ pod, id }) {
321319
{showOutput ? (
322320
<Box
323321
sx={{ paddingBottom: "2px" }}
324-
overflow="scroll"
325-
maxHeight="145px"
322+
overflow="auto"
323+
maxHeight="140px"
326324
border="1px"
327325
>
328326
{/* <Box bgcolor="lightgray">Error</Box> */}
@@ -424,6 +422,10 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
424422
const role = useStore(store, (state) => state.role);
425423
const width = useStore(store, (state) => state.pods[id]?.width);
426424
const isPodFocused = useStore(store, (state) => state.pods[id]?.focus);
425+
const index = useStore(
426+
store,
427+
(state) => state.pods[id]?.result?.count || " "
428+
);
427429
const inputRef = useRef<HTMLInputElement>(null);
428430

429431
const showResult = useStore(
@@ -550,7 +552,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
550552
}}
551553
></InputBase>
552554
</Box>
553-
<Box sx={styles["pod-index"]}>[{pod.index}]</Box>
555+
<Box sx={styles["pod-index"]}>[{index}]</Box>
554556
<Box
555557
sx={{
556558
display: "flex",
@@ -634,7 +636,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
634636
position: "absolute",
635637
top: isRightLayout ? 0 : "100%",
636638
left: isRightLayout ? "100%" : 0,
637-
maxHeight: "158px",
639+
maxHeight: "160px",
638640
maxWidth: isRightLayout ? "300px" : "100%",
639641
minWidth: isRightLayout ? "150px" : "100%",
640642
boxSizing: "border-box",
@@ -845,7 +847,6 @@ export function Canvas() {
845847
addPod(apolloClient, {
846848
id,
847849
parent: "ROOT",
848-
index: nodesMap.size + 1,
849850
type: type === "code" ? "CODE" : "DECK",
850851
lang: "python",
851852
x: position.x,

ui/src/lib/fetch.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export function normalize(pods) {
9595
y: 0,
9696
width: 0,
9797
height: 0,
98-
index: 0,
9998
},
10099
};
101100

@@ -129,7 +128,7 @@ export function normalize(pods) {
129128
// pod.children = pod.children.map(({ id }) => id);
130129
//
131130
// sort according to index
132-
pod.children.sort((a, b) => res[a.id].index - res[b.id].index);
131+
// pod.children.sort((a, b) => res[a.id].index - res[b.id].index);
133132
// if (pod.type === "WYSIWYG" || pod.type === "CODE") {
134133
// pod.content = JSON.parse(pod.content);
135134
// }
@@ -180,7 +179,6 @@ function serializePodInput(pod) {
180179
column,
181180
lang,
182181
parent,
183-
// index,
184182
children,
185183
result,
186184
stdout,
@@ -223,7 +221,7 @@ function serializePodInput(pod) {
223221
}))(pod);
224222
}
225223

226-
export async function doRemoteAddPod(client, { repoId, parent, index, pod }) {
224+
export async function doRemoteAddPod(client, { repoId, parent, pod }) {
227225
const mutation = gql`
228226
mutation addPod(
229227
$repoId: String
@@ -240,7 +238,7 @@ export async function doRemoteAddPod(client, { repoId, parent, index, pod }) {
240238
variables: {
241239
repoId,
242240
parent,
243-
index,
241+
index: 0,
244242
input: serializePodInput(pod),
245243
},
246244
// FIXME the query is not refetched.

ui/src/lib/store.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export type Pod = {
114114
midports?: {};
115115
isSyncing: boolean;
116116
io: {};
117-
index: number;
118117
x: number;
119118
y: number;
120119
width: number;
@@ -164,7 +163,7 @@ export interface RepoSlice {
164163
setPodContent: ({ id, content }: { id: string; content: string }) => void;
165164
addPod: (
166165
client: ApolloClient<object> | null,
167-
{ parent, index, anchor, shift, id, type, lang, x, y, width, height }: any
166+
{ parent, anchor, shift, id, type, lang, x, y, width, height }: any
168167
) => void;
169168
deletePod: (
170169
client: ApolloClient<object> | null,
@@ -247,14 +246,8 @@ const createRepoSlice: StateCreator<
247246
setCurrentEditor: (id) => set({ currentEditor: id }),
248247
addPod: async (
249248
client,
250-
{ parent, index, anchor, shift, id, type, lang, x, y, width, height }
249+
{ parent, anchor, shift, id, type, lang, x, y, width, height }
251250
) => {
252-
if (index === undefined) {
253-
index = get().pods[parent].children.findIndex(({ id }) => id === anchor);
254-
if (index === -1) throw new Error("Cannot find anchoar pod:", anchor);
255-
index += shift | 0;
256-
}
257-
258251
if (!parent) {
259252
parent = "ROOT";
260253
}
@@ -289,7 +282,6 @@ const createRepoSlice: StateCreator<
289282
focus: false,
290283
// from payload
291284
parent,
292-
index,
293285
id,
294286
type,
295287
x,
@@ -306,7 +298,7 @@ const createRepoSlice: StateCreator<
306298
// TODO the children no longer need to be ordered
307299
// TODO the frontend should handle differently for the children
308300
// state.pods[parent].children.splice(index, 0, id);
309-
state.pods[parent].children.splice(index, 0, { id, type: pod.type });
301+
state.pods[parent].children.push({ id, type: pod.type });
310302
// DEBUG sort-in-place
311303
// TODO I can probably insert
312304
// CAUTION the sort expects -1,0,1, not true/false
@@ -319,7 +311,6 @@ const createRepoSlice: StateCreator<
319311
await doRemoteAddPod(client, {
320312
repoId: get().repoId,
321313
parent,
322-
index,
323314
pod,
324315
});
325316
}
@@ -467,8 +458,10 @@ const createRepoSlice: StateCreator<
467458
set(
468459
produce((state) => {
469460
let pod = state.pods[id];
470-
pod.name = name;
471-
pod.dirty = true;
461+
if (pod) {
462+
pod.name = name;
463+
pod.dirty = true;
464+
}
472465
}),
473466
false,
474467
// @ts-ignore
@@ -707,13 +700,8 @@ const createRepoSlice: StateCreator<
707700
);
708701
},
709702
loadRepo: async (client, id) => {
710-
const {
711-
pods,
712-
name,
713-
error,
714-
userId,
715-
collaboratorIds,
716-
} = await doRemoteLoadRepo({ id, client });
703+
const { pods, name, error, userId, collaboratorIds } =
704+
await doRemoteLoadRepo({ id, client });
717705
set(
718706
produce((state) => {
719707
// TODO the children ordered by index

0 commit comments

Comments
 (0)