Skip to content

Commit dfe2424

Browse files
committed
Fix controller set types for collection queries
1 parent 156b93e commit dfe2424

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { EndpointInstance } from '@data-client/endpoint';
2-
import { useController, useLoading } from '@data-client/react';
2+
import { Controller, Queryable, SchemaArgs, useController, useLoading } from '@data-client/react';
33

44
export const useMutate = <E extends EndpointInstance>(endpoint: E) => {
55
const controller = useController();
66
return useLoading((...data: Parameters<E['fetch']>) => controller.fetch(endpoint, ...data), [controller, endpoint]);
77
};
8+
9+
// TODO: fix types upstream
10+
export const setQueryChild = <S extends Queryable>(
11+
controller: Controller,
12+
schema: S,
13+
childKey: keyof S,
14+
...rest: readonly [...SchemaArgs<S>, object]
15+
) => controller.set(schema[childKey] as S, ...rest);

packages/client/src/flow/flow.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { PanelResizeHandle } from '@the-dev-tools/ui/resizable-panel';
5454
import { Separator } from '@the-dev-tools/ui/separator';
5555
import { tw } from '@the-dev-tools/ui/tailwind-literal';
5656
import { TextField, useEditableTextState } from '@the-dev-tools/ui/text-field';
57-
import { useMutate } from '~data-client';
57+
import { setQueryChild, useMutate } from '~data-client';
5858
import {
5959
ColumnActionDelete,
6060
columnActions,
@@ -445,7 +445,16 @@ const ActionBar = () => {
445445
);
446446

447447
for await (const { example, node, version } of flowRun({ flowId })) {
448-
if (version) void controller.set(FlowVersionsEndpoint.schema.items.unshift, { flowId }, version);
448+
if (version) {
449+
void setQueryChild(
450+
controller,
451+
FlowVersionsEndpoint.schema.items,
452+
'unshift',
453+
transport,
454+
{ flowId },
455+
version,
456+
);
457+
}
449458

450459
if (example) {
451460
const { exampleId, responseId, versionId } = example;
@@ -455,10 +464,14 @@ const ActionBar = () => {
455464
lastResponseId: responseId,
456465
} satisfies Partial<ExampleEntity>);
457466

458-
void controller.set(ExampleVersionsEndpoint.schema.items.unshift, { exampleId }, {
459-
exampleId: versionId,
460-
lastResponseId: responseId,
461-
} satisfies Partial<ExampleVersionsItemEntity>);
467+
void setQueryChild(
468+
controller,
469+
ExampleVersionsEndpoint.schema.items,
470+
'unshift',
471+
transport,
472+
{ exampleId },
473+
{ exampleId: versionId, lastResponseId: responseId } satisfies Partial<ExampleVersionsItemEntity>,
474+
);
462475
}
463476

464477
if (node) {

0 commit comments

Comments
 (0)