Skip to content

Commit ca3cf53

Browse files
committed
fix: qp fit in view & text mode rendering
1 parent 55244e0 commit ca3cf53

3 files changed

Lines changed: 48 additions & 23 deletions

File tree

packages/libraries/laboratory/src/components/flow.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,10 @@ export const Flow = (props: {
239239

240240
const { width: containerWidth, height: containerHeight } = container.getBoundingClientRect();
241241

242-
console.log({
243-
width,
244-
height,
245-
containerWidth,
246-
containerHeight,
247-
});
248-
249-
const scale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, containerWidth / width));
242+
const scale = Math.min(
243+
MAX_SCALE,
244+
Math.max(MIN_SCALE, Math.min(containerWidth / width, containerHeight / height)),
245+
);
250246

251247
setView(prev => ({
252248
...prev,

packages/libraries/laboratory/src/components/laboratory/laboratory.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ const LaboratoryContent = () => {
250250
}
251251

252252
return (
253-
<Empty className="w-full px-0!">
253+
<Empty className="px-0! w-full">
254254
<EmptyHeader>
255255
<EmptyMedia variant="icon">
256256
<FileIcon className="text-muted-foreground size-6" />
@@ -344,7 +344,7 @@ const LaboratoryContent = () => {
344344
</Tooltip>
345345
<div
346346
className={cn(
347-
'relative z-100 mt-auto flex aspect-square h-12 w-full items-center justify-center border-l-2 border-transparent',
347+
'z-100 relative mt-auto flex aspect-square h-12 w-full items-center justify-center border-l-2 border-transparent',
348348
{
349349
'border-primary': activePanel === 'settings',
350350
},

packages/libraries/laboratory/src/lib/query-plan/utils.tsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ export function renderSelectionSet(
102102

103103
for (const item of selectionSet) {
104104
if (item.kind === 'InlineFragment') {
105-
lines.push(`${indent(depth)}... on ${item.typeCondition}`);
105+
lines.push(`${indent(depth)}... on ${item.typeCondition} {`);
106106

107107
for (const property of item.selections ?? []) {
108108
lines.push(`${indent(depth + 1)}${property.name}`);
109109
}
110+
111+
lines.push(`${indent(depth)}}`);
110112
}
111113
}
112114

@@ -169,7 +171,23 @@ export function renderFetchNode(node: FetchNodePlan, depth = 0): string {
169171
lines.push(`${indent(depth + 1)}} =>`);
170172
}
171173

172-
lines.push(renderMultilineBlock(print(parse(node.operation)), depth + 2), `${indent(depth)}}`);
174+
const slice = node.operation.includes('_entities') ? 2 : 1;
175+
176+
try {
177+
lines.push(
178+
`${indent(depth + 1)}{`,
179+
renderMultilineBlock(
180+
print(parse(node.operation))
181+
.split('\n')
182+
.slice(slice, slice * -1)
183+
.join('\n'),
184+
depth + 1,
185+
),
186+
`${indent(depth + 1)}}`,
187+
);
188+
} catch {
189+
lines.push(`${indent(depth + 1)}${node.operation}`);
190+
}
173191

174192
return lines.join('\n');
175193
}
@@ -178,31 +196,41 @@ export function renderBatchFetchNode(node: BatchFetchNodePlan, depth = 0): strin
178196
const lines: string[] = [];
179197
lines.push(`${indent(depth)}BatchFetch(service: "${node.serviceName}") {`);
180198

181-
for (const alias of node.entityBatch.aliases) {
199+
for (let i = 0; i < node.entityBatch.aliases.length; i++) {
200+
const alias = node.entityBatch.aliases[i];
201+
182202
lines.push(
183203
`${indent(depth + 1)}${alias.alias} {`,
184-
`${indent(depth + 2)}paths [`,
185-
...alias.paths.map(
186-
(path, index) =>
187-
`${indent(depth + 3)}${renderFlattenPath(path)}${index < alias.paths.length - 1 ? ',' : ''}`,
188-
),
204+
`${indent(depth + 2)}paths: [`,
205+
...alias.paths.map(path => `${indent(depth + 3)}"${renderFlattenPath(path)}"`),
189206
`${indent(depth + 2)}]`,
190-
`${indent(depth + 2)}{`,
191207
);
208+
192209
const requires = renderSelectionSet(alias.requires, depth + 3);
193-
if (requires) lines.push(requires);
210+
211+
if (requires) {
212+
lines.push(`${indent(depth + 2)}{`, requires, `${indent(depth + 2)}}`);
213+
}
214+
215+
if (i < node.entityBatch.aliases.length - 1) {
216+
lines.push(`${indent(depth + 1)}}`);
217+
}
218+
}
219+
220+
try {
194221
lines.push(
195-
`${indent(depth + 2)}}`,
196222
`${indent(depth + 1)}}`,
197223
`${indent(depth + 1)}{`,
198224
renderMultilineBlock(
199225
print(parse(node.operation)).split('\n').slice(1, -1).join('\n'),
200226
depth + 1,
201227
),
202228
`${indent(depth + 1)}}`,
229+
`${indent(depth)}}`,
203230
);
231+
} catch {
232+
lines.push(`${indent(depth + 1)}${node.operation}`);
204233
}
205-
lines.push(`${indent(depth)}}`);
206234

207235
return lines.join('\n');
208236
}
@@ -597,7 +625,7 @@ function visitNode(
597625
);
598626
break;
599627

600-
case 'Sequence':
628+
case 'Sequence': {
601629
result = null;
602630

603631
let prevChild: QueryPlanNode | null = null;
@@ -619,6 +647,7 @@ function visitNode(
619647
}
620648

621649
break;
650+
}
622651

623652
case 'Parallel':
624653
result.children = [];

0 commit comments

Comments
 (0)