@everysk/apps-sdk 0.1.0 → 0.3.0-beta-20261016180126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +395 -8
- package/dist/EveryskApp.d.ts +34 -2
- package/dist/EveryskApp.d.ts.map +1 -1
- package/dist/EveryskApp.js +35 -2
- package/dist/EveryskApp.js.map +1 -1
- package/dist/agGrid/handleRowsScrollEnd.d.ts +53 -0
- package/dist/agGrid/handleRowsScrollEnd.d.ts.map +1 -0
- package/dist/agGrid/handleRowsScrollEnd.js +47 -0
- package/dist/agGrid/handleRowsScrollEnd.js.map +1 -0
- package/dist/agGrid/index.d.ts +2 -0
- package/dist/agGrid/index.d.ts.map +1 -1
- package/dist/agGrid/index.js +2 -1
- package/dist/api/datastore.d.ts +10 -8
- package/dist/api/datastore.d.ts.map +1 -1
- package/dist/api/datastore.js +24 -55
- package/dist/api/datastore.js.map +1 -1
- package/dist/api/entityQuery.d.ts +46 -41
- package/dist/api/entityQuery.d.ts.map +1 -1
- package/dist/api/entityQuery.js +55 -14
- package/dist/api/entityQuery.js.map +1 -1
- package/dist/api/file.d.ts +26 -9
- package/dist/api/file.d.ts.map +1 -1
- package/dist/api/file.js +45 -55
- package/dist/api/file.js.map +1 -1
- package/dist/api/portfolio.d.ts +11 -8
- package/dist/api/portfolio.d.ts.map +1 -1
- package/dist/api/portfolio.js +24 -55
- package/dist/api/portfolio.js.map +1 -1
- package/dist/api/profile.d.ts +3 -2
- package/dist/api/profile.d.ts.map +1 -1
- package/dist/api/profile.js +4 -9
- package/dist/api/profile.js.map +1 -1
- package/dist/api/request.d.ts +106 -0
- package/dist/api/request.d.ts.map +1 -0
- package/dist/api/request.js +132 -0
- package/dist/api/request.js.map +1 -0
- package/dist/api/websocketsConfig.d.ts +7 -2
- package/dist/api/websocketsConfig.d.ts.map +1 -1
- package/dist/api/websocketsConfig.js +2 -10
- package/dist/api/websocketsConfig.js.map +1 -1
- package/dist/api/workflow.d.ts +84 -89
- package/dist/api/workflow.d.ts.map +1 -1
- package/dist/api/workflow.js +121 -208
- package/dist/api/workflow.js.map +1 -1
- package/dist/api/workspace.d.ts +18 -8
- package/dist/api/workspace.d.ts.map +1 -1
- package/dist/api/workspace.js +21 -26
- package/dist/api/workspace.js.map +1 -1
- package/dist/components/ui/Footer/index.d.ts.map +1 -1
- package/dist/components/ui/Footer/index.js.map +1 -1
- package/dist/components/ui/GlobalLoading/index.d.ts.map +1 -1
- package/dist/components/ui/GlobalLoading/index.js.map +1 -1
- package/dist/components/ui/PageContainer/index.d.ts +1 -1
- package/dist/components/ui/PageContainer/index.d.ts.map +1 -1
- package/dist/components/ui/PageContainer/index.js.map +1 -1
- package/dist/components/ui/Toolbar/index.d.ts +40 -3
- package/dist/components/ui/Toolbar/index.d.ts.map +1 -1
- package/dist/components/ui/Toolbar/index.js +42 -15
- package/dist/components/ui/Toolbar/index.js.map +1 -1
- package/dist/contexts/appAlertContext/provider.js.map +1 -1
- package/dist/contexts/appAlertContext/types.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/index.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/index.js.map +1 -1
- package/dist/contexts/appConfigContext/provider.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/provider.js.map +1 -1
- package/dist/contexts/webSocketContext/handler.d.ts +3 -2
- package/dist/contexts/webSocketContext/handler.d.ts.map +1 -1
- package/dist/contexts/webSocketContext/handler.js.map +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.d.ts +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js.map +1 -1
- package/dist/contexts/webSocketContext/provider.d.ts +6 -3
- package/dist/contexts/webSocketContext/provider.d.ts.map +1 -1
- package/dist/contexts/webSocketContext/provider.js +42 -7
- package/dist/contexts/webSocketContext/provider.js.map +1 -1
- package/dist/contexts/webSocketContext/types.d.ts +7 -5
- package/dist/contexts/webSocketContext/types.d.ts.map +1 -1
- package/dist/file/index.d.ts +2 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/hooks/datastore/useDatastoreMutations.d.ts +4 -4
- package/dist/hooks/datastore/useDatastoreMutations.d.ts.map +1 -1
- package/dist/hooks/datastore/useDatastoreMutations.js +17 -55
- package/dist/hooks/datastore/useDatastoreMutations.js.map +1 -1
- package/dist/hooks/datastore/useFetchDatastore.d.ts +30 -41
- package/dist/hooks/datastore/useFetchDatastore.d.ts.map +1 -1
- package/dist/hooks/datastore/useFetchDatastore.js +25 -59
- package/dist/hooks/datastore/useFetchDatastore.js.map +1 -1
- package/dist/hooks/datastore/useFetchDatastores.d.ts +47 -52
- package/dist/hooks/datastore/useFetchDatastores.d.ts.map +1 -1
- package/dist/hooks/datastore/useFetchDatastores.js +55 -70
- package/dist/hooks/datastore/useFetchDatastores.js.map +1 -1
- package/dist/hooks/file/fileData.d.ts +17 -0
- package/dist/hooks/file/fileData.d.ts.map +1 -0
- package/dist/hooks/file/fileData.js +10 -0
- package/dist/hooks/file/fileData.js.map +1 -0
- package/dist/hooks/file/useFetchFile.d.ts +38 -58
- package/dist/hooks/file/useFetchFile.d.ts.map +1 -1
- package/dist/hooks/file/useFetchFile.js +26 -66
- package/dist/hooks/file/useFetchFile.js.map +1 -1
- package/dist/hooks/file/useFetchFiles.d.ts +18 -52
- package/dist/hooks/file/useFetchFiles.d.ts.map +1 -1
- package/dist/hooks/file/useFetchFiles.js +53 -69
- package/dist/hooks/file/useFetchFiles.js.map +1 -1
- package/dist/hooks/file/useFileMutations.d.ts +9 -8
- package/dist/hooks/file/useFileMutations.d.ts.map +1 -1
- package/dist/hooks/file/useFileMutations.js +23 -60
- package/dist/hooks/file/useFileMutations.js.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolio.d.ts +16 -50
- package/dist/hooks/portfolio/useFetchPortfolio.d.ts.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolio.js +15 -63
- package/dist/hooks/portfolio/useFetchPortfolio.js.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolios.d.ts +13 -52
- package/dist/hooks/portfolio/useFetchPortfolios.d.ts.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolios.js +29 -71
- package/dist/hooks/portfolio/useFetchPortfolios.js.map +1 -1
- package/dist/hooks/portfolio/usePortfolioMutations.d.ts +8 -8
- package/dist/hooks/portfolio/usePortfolioMutations.d.ts.map +1 -1
- package/dist/hooks/portfolio/usePortfolioMutations.js +20 -58
- package/dist/hooks/portfolio/usePortfolioMutations.js.map +1 -1
- package/dist/hooks/profile/useFetchProfile.d.ts +18 -44
- package/dist/hooks/profile/useFetchProfile.d.ts.map +1 -1
- package/dist/hooks/profile/useFetchProfile.js +16 -48
- package/dist/hooks/profile/useFetchProfile.js.map +1 -1
- package/dist/hooks/useAxios.js.map +1 -1
- package/dist/hooks/useEntityInfiniteQuery.d.ts +88 -0
- package/dist/hooks/useEntityInfiniteQuery.d.ts.map +1 -0
- package/dist/hooks/useEntityInfiniteQuery.js +111 -0
- package/dist/hooks/useEntityInfiniteQuery.js.map +1 -0
- package/dist/hooks/useEntityMutation.d.ts +47 -0
- package/dist/hooks/useEntityMutation.d.ts.map +1 -0
- package/dist/hooks/useEntityMutation.js +58 -0
- package/dist/hooks/useEntityMutation.js.map +1 -0
- package/dist/hooks/useEntityQuery.d.ts +68 -0
- package/dist/hooks/useEntityQuery.d.ts.map +1 -0
- package/dist/hooks/useEntityQuery.js +75 -0
- package/dist/hooks/useEntityQuery.js.map +1 -0
- package/dist/hooks/workflow/useFetchWorkerExecution.d.ts +17 -34
- package/dist/hooks/workflow/useFetchWorkerExecution.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecution.js +16 -46
- package/dist/hooks/workflow/useFetchWorkerExecution.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts +179 -41
- package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecutions.js +29 -62
- package/dist/hooks/workflow/useFetchWorkerExecutions.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflow.d.ts +16 -35
- package/dist/hooks/workflow/useFetchWorkflow.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflow.js +15 -48
- package/dist/hooks/workflow/useFetchWorkflow.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts +17 -34
- package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecution.js +16 -46
- package/dist/hooks/workflow/useFetchWorkflowExecution.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts +22 -36
- package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecutions.js +43 -56
- package/dist/hooks/workflow/useFetchWorkflowExecutions.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflows.d.ts +20 -37
- package/dist/hooks/workflow/useFetchWorkflows.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflows.js +32 -47
- package/dist/hooks/workflow/useFetchWorkflows.js.map +1 -1
- package/dist/hooks/workflow/useRunWorkflow.d.ts +21 -16
- package/dist/hooks/workflow/useRunWorkflow.d.ts.map +1 -1
- package/dist/hooks/workflow/useRunWorkflow.js +66 -29
- package/dist/hooks/workflow/useRunWorkflow.js.map +1 -1
- package/dist/hooks/workflow/useTriggerWorkflow.d.ts +20 -0
- package/dist/hooks/workflow/useTriggerWorkflow.d.ts.map +1 -0
- package/dist/hooks/workflow/useTriggerWorkflow.js +32 -0
- package/dist/hooks/workflow/useTriggerWorkflow.js.map +1 -0
- package/dist/hooks/workspace/useFetchWorkspace.d.ts +19 -34
- package/dist/hooks/workspace/useFetchWorkspace.d.ts.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspace.js +16 -46
- package/dist/hooks/workspace/useFetchWorkspace.js.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspaces.d.ts +17 -37
- package/dist/hooks/workspace/useFetchWorkspaces.d.ts.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspaces.js +25 -47
- package/dist/hooks/workspace/useFetchWorkspaces.js.map +1 -1
- package/dist/index.d.ts +13 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -11
- package/dist/lib/abort.d.ts +58 -0
- package/dist/lib/abort.d.ts.map +1 -0
- package/dist/lib/abort.js +112 -0
- package/dist/lib/abort.js.map +1 -0
- package/dist/lib/datastoreTable.d.ts +59 -54
- package/dist/lib/datastoreTable.d.ts.map +1 -1
- package/dist/lib/datastoreTable.js +58 -62
- package/dist/lib/datastoreTable.js.map +1 -1
- package/dist/lib/file.d.ts +34 -0
- package/dist/lib/file.d.ts.map +1 -0
- package/dist/lib/file.js +63 -0
- package/dist/lib/file.js.map +1 -0
- package/dist/lib/queryClient.d.ts.map +1 -1
- package/dist/lib/queryClient.js.map +1 -1
- package/dist/lib/workflowRun.d.ts +91 -0
- package/dist/lib/workflowRun.d.ts.map +1 -0
- package/dist/lib/workflowRun.js +224 -0
- package/dist/lib/workflowRun.js.map +1 -0
- package/dist/socket/index.d.ts +1 -3
- package/dist/socket/index.d.ts.map +1 -1
- package/dist/socket/index.js +3 -5
- package/dist/test/mocks/index.d.ts +1 -1
- package/dist/test/mocks/index.d.ts.map +1 -1
- package/dist/test/renderWithProviders.d.ts +2 -2
- package/dist/test/renderWithProviders.d.ts.map +1 -1
- package/dist/test/renderWithProviders.js.map +1 -1
- package/dist/test/setup.js.map +1 -1
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/overrides/index.d.ts +4 -2
- package/dist/theme/overrides/index.d.ts.map +1 -1
- package/dist/theme/overrides/index.js +5 -3
- package/dist/theme/overrides/index.js.map +1 -1
- package/dist/theme/overrides/muiButton.d.ts +2 -2
- package/dist/theme/overrides/muiButton.js.map +1 -1
- package/dist/theme/overrides/muiCssBaseline.d.ts.map +1 -1
- package/dist/theme/overrides/muiCssBaseline.js.map +1 -1
- package/dist/theme/overrides/muiDatePicker.js.map +1 -1
- package/dist/theme/overrides/muiFormControl.js.map +1 -1
- package/dist/theme/overrides/muiIconButton.d.ts +2 -2
- package/dist/theme/overrides/muiIconButton.js.map +1 -1
- package/dist/theme/overrides/muiSelect.d.ts.map +1 -1
- package/dist/theme/overrides/muiSelect.js.map +1 -1
- package/dist/theme/overrides/muiSvgIcon.d.ts.map +1 -1
- package/dist/theme/overrides/muiSvgIcon.js.map +1 -1
- package/dist/theme/overrides/muiTextField.js.map +1 -1
- package/dist/theme/overrides/muiToggleButton.d.ts +2 -2
- package/dist/theme/overrides/muiToggleButton.js.map +1 -1
- package/dist/theme/overrides/muiToggleButtonGroup.d.ts +2 -2
- package/dist/theme/overrides/muiToggleButtonGroup.js.map +1 -1
- package/dist/theme/themes/DefaultDark.js +2 -2
- package/dist/theme/themes/DefaultDark.js.map +1 -1
- package/dist/theme/themes/DefaultLight.js +2 -2
- package/dist/theme/themes/DefaultLight.js.map +1 -1
- package/dist/theme/themes/EveryskDark.js +2 -2
- package/dist/theme/themes/EveryskDark.js.map +1 -1
- package/dist/theme/themes/EveryskLight.js +2 -2
- package/dist/theme/themes/EveryskLight.js.map +1 -1
- package/dist/theme/themes/MidnightEmber.js +2 -2
- package/dist/theme/themes/MidnightEmber.js.map +1 -1
- package/dist/types/anyRecord.d.ts.map +1 -1
- package/dist/types/datastore.d.ts +35 -5
- package/dist/types/datastore.d.ts.map +1 -1
- package/dist/types/datastoreDataFormat.d.ts +13 -0
- package/dist/types/datastoreDataFormat.d.ts.map +1 -0
- package/dist/types/entityQuery.d.ts +86 -16
- package/dist/types/entityQuery.d.ts.map +1 -1
- package/dist/types/file.d.ts +7 -3
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/portfolio.d.ts +1 -3
- package/dist/types/portfolio.d.ts.map +1 -1
- package/dist/types/profile.d.ts +0 -10
- package/dist/types/profile.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +35 -6
- package/dist/types/workflow.d.ts.map +1 -1
- package/dist/types/workspace.d.ts +1 -2
- package/dist/types/workspace.d.ts.map +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/workflow/index.d.ts +2 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/EveryskApp.tsx +53 -2
- package/src/agGrid/handleRowsScrollEnd.ts +71 -0
- package/src/agGrid/index.ts +5 -1
- package/src/api/datastore.ts +79 -107
- package/src/api/entityQuery.ts +86 -17
- package/src/api/file.ts +110 -103
- package/src/api/portfolio.ts +82 -125
- package/src/api/profile.ts +25 -18
- package/src/api/request.ts +168 -0
- package/src/api/websocketsConfig.ts +11 -19
- package/src/api/workflow.ts +232 -334
- package/src/api/workspace.ts +43 -43
- package/src/components/ui/Footer/index.tsx +8 -7
- package/src/components/ui/GlobalLoading/index.tsx +13 -3
- package/src/components/ui/PageContainer/index.tsx +9 -2
- package/src/components/ui/Toolbar/index.tsx +105 -30
- package/src/contexts/appAlertContext/provider.tsx +1 -1
- package/src/contexts/appAlertContext/types.ts +3 -3
- package/src/contexts/appConfigContext/index.tsx +1 -1
- package/src/contexts/appConfigContext/provider.tsx +1 -5
- package/src/contexts/webSocketContext/handler.ts +8 -2
- package/src/contexts/webSocketContext/hooks/useWebSocket/index.ts +1 -1
- package/src/contexts/webSocketContext/provider.tsx +64 -14
- package/src/contexts/webSocketContext/types.ts +7 -6
- package/src/file/index.ts +2 -0
- package/src/hooks/datastore/useDatastoreMutations.ts +19 -60
- package/src/hooks/datastore/useFetchDatastore.ts +45 -73
- package/src/hooks/datastore/useFetchDatastores.ts +106 -131
- package/src/hooks/file/fileData.ts +19 -0
- package/src/hooks/file/useFetchFile.ts +41 -76
- package/src/hooks/file/useFetchFiles.ts +92 -87
- package/src/hooks/file/useFileMutations.ts +23 -73
- package/src/hooks/portfolio/useFetchPortfolio.ts +26 -78
- package/src/hooks/portfolio/useFetchPortfolios.ts +50 -93
- package/src/hooks/portfolio/usePortfolioMutations.ts +22 -72
- package/src/hooks/profile/useFetchProfile.ts +24 -65
- package/src/hooks/useAxios.ts +5 -5
- package/src/hooks/useEntityInfiniteQuery.ts +193 -0
- package/src/hooks/useEntityMutation.ts +70 -0
- package/src/hooks/useEntityQuery.ts +117 -0
- package/src/hooks/workflow/useFetchWorkerExecution.ts +27 -56
- package/src/hooks/workflow/useFetchWorkerExecutions.ts +54 -79
- package/src/hooks/workflow/useFetchWorkflow.ts +24 -58
- package/src/hooks/workflow/useFetchWorkflowExecution.ts +27 -57
- package/src/hooks/workflow/useFetchWorkflowExecutions.ts +64 -73
- package/src/hooks/workflow/useFetchWorkflows.ts +48 -64
- package/src/hooks/workflow/useRunWorkflow.ts +82 -36
- package/src/hooks/workflow/useTriggerWorkflow.ts +36 -0
- package/src/hooks/workspace/useFetchWorkspace.ts +25 -58
- package/src/hooks/workspace/useFetchWorkspaces.ts +38 -69
- package/src/index.ts +34 -19
- package/src/lib/abort.ts +131 -0
- package/src/lib/datastoreTable.ts +127 -74
- package/src/lib/file.ts +67 -0
- package/src/lib/queryClient.ts +11 -13
- package/src/lib/workflowRun.ts +329 -0
- package/src/socket/index.ts +1 -3
- package/src/test/mocks/index.ts +1 -5
- package/src/test/renderWithProviders.tsx +8 -3
- package/src/test/setup.ts +16 -16
- package/src/theme/index.ts +1 -1
- package/src/theme/overrides/index.ts +5 -3
- package/src/theme/overrides/muiButton.ts +3 -3
- package/src/theme/overrides/muiCssBaseline.ts +11 -12
- package/src/theme/overrides/muiDatePicker.ts +2 -2
- package/src/theme/overrides/muiFormControl.ts +2 -2
- package/src/theme/overrides/muiIconButton.ts +3 -3
- package/src/theme/overrides/muiSelect.ts +2 -2
- package/src/theme/overrides/muiSvgIcon.ts +2 -2
- package/src/theme/overrides/muiTextField.ts +1 -1
- package/src/theme/overrides/muiToggleButton.ts +4 -4
- package/src/theme/overrides/muiToggleButtonGroup.ts +4 -4
- package/src/theme/themes/DefaultDark.ts +2 -2
- package/src/theme/themes/DefaultLight.ts +2 -2
- package/src/theme/themes/EveryskDark.ts +2 -2
- package/src/theme/themes/EveryskLight.ts +2 -2
- package/src/theme/themes/MidnightEmber.ts +15 -15
- package/src/types/anyRecord.ts +2 -2
- package/src/types/datastore.ts +56 -22
- package/src/types/datastoreDataFormat.ts +12 -0
- package/src/types/entityQuery.ts +122 -38
- package/src/types/file.ts +8 -6
- package/src/types/portfolio.ts +70 -74
- package/src/types/profile.ts +0 -11
- package/src/types/workflow.ts +38 -9
- package/src/types/workspace.ts +2 -4
- package/src/ui/index.ts +1 -1
- package/src/workflow/index.ts +5 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useMutation, useQueryClient, type QueryKey } from "@tanstack/react-query";
|
|
2
|
+
|
|
3
|
+
import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
|
|
4
|
+
|
|
5
|
+
export type EntityMutationProps<TVariables, TResult> = {
|
|
6
|
+
/** Sends the write. Receives the variables passed to `mutate`, and only those. */
|
|
7
|
+
mutationFn: (variables: TVariables) => Promise<TResult>;
|
|
8
|
+
/**
|
|
9
|
+
* Invalidated after a success, so the screens reading it refetch. Pass the `queryKey` a fetch
|
|
10
|
+
* hook returned, or a prefix of it (`["datastores"]`) to refresh every list of that entity.
|
|
11
|
+
*/
|
|
12
|
+
queryKey?: QueryKey;
|
|
13
|
+
/** Shown as a success alert. */
|
|
14
|
+
successMessage: string;
|
|
15
|
+
/** Shown as an error alert when the failure carries no message of its own. */
|
|
16
|
+
errorMessage: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* useEntityMutation
|
|
21
|
+
*
|
|
22
|
+
* The write hook every SDK mutation is built on, and the one to build on for an endpoint the SDK
|
|
23
|
+
* does not cover — the counterpart of `useEntityQuery`. A hook says how to send the write and
|
|
24
|
+
* what to tell the user; this owns the cache invalidation and the alerts.
|
|
25
|
+
*
|
|
26
|
+
* It replaced nine copies of the same `useMutation` call across `useDatastoreMutations`,
|
|
27
|
+
* `useFileMutations` and `usePortfolioMutations`, which had already drifted apart in wording.
|
|
28
|
+
*
|
|
29
|
+
* The invalidation is awaited before the mutation resolves, so code after `mutateAsync` sees the
|
|
30
|
+
* refetched data rather than racing it.
|
|
31
|
+
*
|
|
32
|
+
* @returns {UseMutationResult} The `useMutation` result.
|
|
33
|
+
*
|
|
34
|
+
* Example:
|
|
35
|
+
* ```ts
|
|
36
|
+
* export const useReportMutations = ({ queryKey }: { queryKey?: QueryKey }) => {
|
|
37
|
+
* const { api } = useAxios();
|
|
38
|
+
*
|
|
39
|
+
* const share = useEntityMutation({
|
|
40
|
+
* mutationFn: ({ id, workspace }: ShareReportProps) => shareReport(api, id, workspace),
|
|
41
|
+
* queryKey,
|
|
42
|
+
* successMessage: "Report shared successfully.",
|
|
43
|
+
* errorMessage: "Unable to share the report. Please try again.",
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* return { share };
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function useEntityMutation<TVariables, TResult>({
|
|
51
|
+
mutationFn,
|
|
52
|
+
queryKey,
|
|
53
|
+
successMessage,
|
|
54
|
+
errorMessage,
|
|
55
|
+
}: EntityMutationProps<TVariables, TResult>) {
|
|
56
|
+
const { showAlert } = useAppAlert();
|
|
57
|
+
const queryClient = useQueryClient();
|
|
58
|
+
|
|
59
|
+
return useMutation<TResult, Error, TVariables>({
|
|
60
|
+
// TanStack passes a context as a second argument; the request gets the variables alone.
|
|
61
|
+
mutationFn: (variables) => mutationFn(variables),
|
|
62
|
+
onSuccess: async () => {
|
|
63
|
+
if (queryKey?.length) await queryClient.invalidateQueries({ queryKey });
|
|
64
|
+
showAlert({ severity: "success", message: successMessage });
|
|
65
|
+
},
|
|
66
|
+
onError: (error) => {
|
|
67
|
+
showAlert({ severity: "error", message: error.message || errorMessage });
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useQuery, type QueryKey } from "@tanstack/react-query";
|
|
3
|
+
|
|
4
|
+
import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
|
|
5
|
+
import { failWithConfigError } from "@/hooks/useEntityInfiniteQuery";
|
|
6
|
+
import type { EntityQueryOptions } from "@/types/entityQuery";
|
|
7
|
+
|
|
8
|
+
export type EntityQueryProps<TEntity, TData> = {
|
|
9
|
+
/** Must describe everything that changes the response: the entity's ids and workspace. */
|
|
10
|
+
queryKey: QueryKey;
|
|
11
|
+
/**
|
|
12
|
+
* Requests the entity. `signal` aborts when no screen wants it any more — pass it to the
|
|
13
|
+
* request (`api.get(url, { signal })`) to cancel it in flight.
|
|
14
|
+
*/
|
|
15
|
+
fetchEntity: (signal: AbortSignal) => Promise<TEntity>;
|
|
16
|
+
select?: (entity: TEntity) => TData;
|
|
17
|
+
/**
|
|
18
|
+
* Your hook's own precondition for something legitimately not there yet — an id from a
|
|
19
|
+
* selection the user has not made — ANDed with the caller's `queryOptions.enabled`. Unmet,
|
|
20
|
+
* the query stays idle rather than send an empty id, which reaches another endpoint entirely.
|
|
21
|
+
*/
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Why the request cannot be right, when it cannot — `missingWorkspaceError(hookName)` in the
|
|
25
|
+
* SDK's hooks. Set, the query fails at once with it, without a request or a retry, logs it once
|
|
26
|
+
* with `console.error` and shows it as the error alert. See `useEntityInfiniteQuery`.
|
|
27
|
+
* It is reported even while `enabled` is unmet, so an empty id cannot hide a misconfigured
|
|
28
|
+
* workspace; only the caller's `queryOptions.enabled: false` holds it back.
|
|
29
|
+
*/
|
|
30
|
+
configError?: string;
|
|
31
|
+
/** Replaces the SDK's defaults for this hook, as the profile does. */
|
|
32
|
+
defaultQueryOptions?: EntityQueryOptions<TEntity, TData>;
|
|
33
|
+
queryOptions?: EntityQueryOptions<TEntity, TData>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The entity hooks read data the platform keeps changing, so by default nothing is cached:
|
|
38
|
+
* refetched on every mount, dropped as soon as no screen reads it.
|
|
39
|
+
*/
|
|
40
|
+
const sdkDefaultQueryOptions = {
|
|
41
|
+
refetchOnMount: "always",
|
|
42
|
+
staleTime: 0,
|
|
43
|
+
gcTime: 0,
|
|
44
|
+
} as const;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* useEntityQuery
|
|
48
|
+
*
|
|
49
|
+
* The single-entity hook every SDK single-entity hook is built on, and the one to build on for
|
|
50
|
+
* an endpoint the SDK does not cover — the counterpart of `useEntityInfiniteQuery`. A hook says
|
|
51
|
+
* how to request the entity; this owns the defaults, the idle precondition, `select` and the
|
|
52
|
+
* error alert.
|
|
53
|
+
*
|
|
54
|
+
* It replaced eight copies of the same `useQuery` call, which is how one defect had reached all
|
|
55
|
+
* eight: each declared `queryOptions = defaultQueryOptions`, so passing any option replaced the
|
|
56
|
+
* defaults and the query fell back to TanStack's own (a 5-minute cache instead of none). Here
|
|
57
|
+
* the caller's options are merged over the defaults.
|
|
58
|
+
*
|
|
59
|
+
* A failure is shown through `useAppAlert`, as the entity hooks always have.
|
|
60
|
+
*
|
|
61
|
+
* @returns {UseQueryResult} The `useQuery` result; `data` is the entity, or what `select` makes
|
|
62
|
+
* of it. The SDK's hooks spread it and add `queryKey`.
|
|
63
|
+
*
|
|
64
|
+
* Example:
|
|
65
|
+
* ```ts
|
|
66
|
+
* export const useFetchReport = <TData = Report>({ id, workspace, select, queryOptions }: Props<TData>) => {
|
|
67
|
+
* const { api } = useAxios();
|
|
68
|
+
* const queryKey = ["report", id, workspace];
|
|
69
|
+
*
|
|
70
|
+
* const query = useEntityQuery<Report, TData>({
|
|
71
|
+
* queryKey,
|
|
72
|
+
* fetchEntity: (signal) => getReport(api, id, workspace, signal),
|
|
73
|
+
* select,
|
|
74
|
+
* enabled: Boolean(id),
|
|
75
|
+
* configError: workspace ? undefined : missingWorkspaceError("useFetchReport"),
|
|
76
|
+
* queryOptions,
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* return { ...query, queryKey };
|
|
80
|
+
* };
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function useEntityQuery<TEntity, TData = TEntity>({
|
|
84
|
+
queryKey,
|
|
85
|
+
fetchEntity,
|
|
86
|
+
select,
|
|
87
|
+
enabled = true,
|
|
88
|
+
configError,
|
|
89
|
+
defaultQueryOptions = sdkDefaultQueryOptions,
|
|
90
|
+
queryOptions,
|
|
91
|
+
}: EntityQueryProps<TEntity, TData>) {
|
|
92
|
+
const { showAlert } = useAppAlert();
|
|
93
|
+
|
|
94
|
+
const query = useQuery<TEntity, Error, TData>({
|
|
95
|
+
...defaultQueryOptions,
|
|
96
|
+
...queryOptions,
|
|
97
|
+
|
|
98
|
+
queryKey,
|
|
99
|
+
queryFn: async ({ signal }) =>
|
|
100
|
+
configError ? failWithConfigError(configError) : fetchEntity(signal),
|
|
101
|
+
// A retry would rerun the same check and delay an error that cannot resolve itself.
|
|
102
|
+
...(configError ? { retry: false } : {}),
|
|
103
|
+
select,
|
|
104
|
+
// A config error runs past the hook's own precondition, so that an empty id cannot hide a
|
|
105
|
+
// misconfigured workspace; the caller's `enabled` still wins. Kept as the caller wrote it,
|
|
106
|
+
// so a function still works.
|
|
107
|
+
enabled: configError || enabled ? (queryOptions?.enabled ?? true) : false,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!query.error) return;
|
|
112
|
+
|
|
113
|
+
showAlert({ severity: "error", message: query.error.message });
|
|
114
|
+
}, [query.error, showAlert]);
|
|
115
|
+
|
|
116
|
+
return query;
|
|
117
|
+
}
|
|
@@ -1,78 +1,49 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
1
|
import { useAxios } from "@/hooks/useAxios";
|
|
6
|
-
import {
|
|
2
|
+
import { useEntityQuery } from "@/hooks/useEntityQuery";
|
|
3
|
+
import { missingWorkspaceError } from "@/api/entityQuery";
|
|
7
4
|
import { getWorkerExecution } from "@/api/workflow";
|
|
8
5
|
import type { WorkerExecution } from "@/types/workflow";
|
|
9
|
-
import type {
|
|
6
|
+
import type { FetchEntityProps } from "@/types/entityQuery";
|
|
10
7
|
|
|
11
|
-
export type FetchWorkerExecutionProps<
|
|
8
|
+
export type FetchWorkerExecutionProps<
|
|
9
|
+
TData = WorkerExecution,
|
|
10
|
+
TSelected = TData,
|
|
11
|
+
> = FetchEntityProps<TData, TSelected> & {
|
|
12
12
|
workflowId: string;
|
|
13
13
|
workerExecutionId: string;
|
|
14
14
|
workspace: string;
|
|
15
|
-
queryOptions?: EntityQueryOptions<TData, TSelected>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const defaultQueryOptions: EntityQueryOptions<WorkerExecution> = {
|
|
19
|
-
refetchOnMount: "always",
|
|
20
|
-
staleTime: 0,
|
|
21
|
-
gcTime: 0,
|
|
22
15
|
};
|
|
23
16
|
|
|
24
17
|
/**
|
|
25
18
|
* useFetchWorkerExecution
|
|
26
19
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* It also:
|
|
30
|
-
* - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
|
|
31
|
-
* - triggers an error alert via `useAppAlert` whenever `query.error` is present
|
|
32
|
-
*
|
|
33
|
-
* @param workflowId - Workflow identifier the worker execution belongs to (required).
|
|
34
|
-
* @param workerExecutionId - Worker execution identifier (required).
|
|
35
|
-
* @param workspace - Workspace the workflow belongs to (required).
|
|
36
|
-
* @param queryOptions - TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
|
|
20
|
+
* Fetches one worker execution; `data` is the execution, or whatever `select` makes of it. Idle
|
|
21
|
+
* while an id is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
|
|
37
22
|
*
|
|
38
|
-
* @
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* const { data, isLoading } = useFetchWorkerExecution({
|
|
43
|
-
* workflowId: "wf-123",
|
|
44
|
-
* workerExecutionId: "wkex-456",
|
|
45
|
-
* workspace: "main",
|
|
46
|
-
* });
|
|
47
|
-
* // data -> WorkerExecution
|
|
48
|
-
* ```
|
|
23
|
+
* @param {FetchWorkerExecutionProps} props - `workflowId`, `workerExecutionId`, `workspace`,
|
|
24
|
+
* `select` and TanStack `queryOptions`.
|
|
25
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
49
26
|
*/
|
|
50
|
-
export const useFetchWorkerExecution =
|
|
51
|
-
|
|
27
|
+
export const useFetchWorkerExecution = <TSelected = WorkerExecution>({
|
|
28
|
+
workflowId,
|
|
29
|
+
workerExecutionId,
|
|
30
|
+
workspace,
|
|
31
|
+
select,
|
|
32
|
+
queryOptions,
|
|
33
|
+
}: FetchWorkerExecutionProps<WorkerExecution, TSelected>) => {
|
|
52
34
|
const { api } = useAxios();
|
|
53
|
-
const { showAlert } = useAppAlert();
|
|
54
35
|
|
|
55
36
|
const queryKey = ["worker_execution", workflowId, workerExecutionId, workspace];
|
|
56
37
|
|
|
57
|
-
const query =
|
|
38
|
+
const query = useEntityQuery<WorkerExecution, TSelected>({
|
|
58
39
|
queryKey,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
40
|
+
fetchEntity: (signal) =>
|
|
41
|
+
getWorkerExecution(api, workflowId, workerExecutionId, workspace, signal),
|
|
42
|
+
select,
|
|
43
|
+
enabled: Boolean(workflowId) && Boolean(workerExecutionId),
|
|
44
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchWorkerExecution"),
|
|
45
|
+
queryOptions,
|
|
63
46
|
});
|
|
64
47
|
|
|
65
|
-
|
|
66
|
-
if (!query.error) return;
|
|
67
|
-
|
|
68
|
-
showAlert({
|
|
69
|
-
severity: "error",
|
|
70
|
-
message: query.error.message,
|
|
71
|
-
});
|
|
72
|
-
}, [query.error, showAlert]);
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
...query,
|
|
76
|
-
queryKey,
|
|
77
|
-
};
|
|
48
|
+
return { ...query, queryKey };
|
|
78
49
|
};
|
|
@@ -1,98 +1,73 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { useInfiniteQuery, type UseInfiniteQueryOptions, type QueryKey } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
1
|
import { useAxios } from "@/hooks/useAxios";
|
|
2
|
+
import { useEntityQuery } from "@/hooks/useEntityQuery";
|
|
5
3
|
import { listWorkerExecutions } from "@/api/workflow";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import type {
|
|
9
|
-
|
|
10
|
-
type PageToken = string | null;
|
|
4
|
+
import { missingWorkspaceError } from "@/api/entityQuery";
|
|
5
|
+
import type { FetchEntityProps } from "@/types/entityQuery";
|
|
6
|
+
import type { WorkerExecutionGroup } from "@/types/workflow";
|
|
11
7
|
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export type FetchWorkerExecutionsProps<
|
|
9
|
+
TData = WorkerExecutionGroup[],
|
|
10
|
+
TSelected = TData,
|
|
11
|
+
> = FetchEntityProps<TData, TSelected> & {
|
|
15
12
|
workflowId: string;
|
|
16
13
|
workflowExecutionId: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const defaultQueryOptions: InfiniteOptions<WorkerExecution[]> = {
|
|
21
|
-
refetchOnMount: "always",
|
|
22
|
-
staleTime: 0,
|
|
23
|
-
gcTime: 0,
|
|
14
|
+
workspace: string;
|
|
15
|
+
/** Include each run's `result` and `input_params`. The API leaves them out by default. */
|
|
16
|
+
withResult?: boolean;
|
|
24
17
|
};
|
|
25
18
|
|
|
26
19
|
/**
|
|
27
20
|
* useFetchWorkerExecutions
|
|
28
21
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* Note: `query.data` returns a flat `WorkerExecution[]` with all fetched items merged across pages.
|
|
35
|
-
*
|
|
36
|
-
* @param workflowId - Workflow identifier whose worker executions to fetch (required).
|
|
37
|
-
* @param workflowExecutionId - Workflow execution identifier to filter worker executions (required).
|
|
38
|
-
* @param filters - Filters applied to every page request. Must include a `workspace` filter.
|
|
39
|
-
* @param order - Sorting applied to every page request.
|
|
40
|
-
* @param projection - Single field to project: `"field"` returns only that field (others come
|
|
41
|
-
* back null), `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
|
|
42
|
-
* @param pageSize - Number of executions to fetch per page. Defaults to `10`.
|
|
43
|
-
* @param queryOptions - TanStack Query options passed through to `useInfiniteQuery`.
|
|
22
|
+
* Fetches every worker execution of one workflow execution, grouped by worker; `data` is the
|
|
23
|
+
* groups, or whatever `select` makes of them. Narrow a group on `is_parallel_execution`: a
|
|
24
|
+
* worker that ran in parallel carries every run under `executions`, any other one its run as
|
|
25
|
+
* `execution`. Idle while an id is empty; fails loudly, without a request, while `workspace` is.
|
|
26
|
+
* A failure is shown as an error alert.
|
|
44
27
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
28
|
+
* A plain query, not an infinite one, and so shaped like the single-entity hooks: the endpoint
|
|
29
|
+
* returns the whole set at once, with no cursor to page by. It used to be paged, over a JSON
|
|
30
|
+
* query the endpoint ignores, and typed as a flat list of worker executions.
|
|
48
31
|
*
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* workflowId: "wf-123",
|
|
53
|
-
* workflowExecutionId: "wfex-456",
|
|
54
|
-
* filters: [{ field: "workspace", value: "main" }],
|
|
55
|
-
* pageSize: 20,
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* // Flat list of all fetched worker executions
|
|
59
|
-
* const workerExecutions = query.data ?? [];
|
|
60
|
-
* ```
|
|
32
|
+
* @param {FetchWorkerExecutionsProps} props - Workflow and execution ids, workspace,
|
|
33
|
+
* `withResult`, `select` and TanStack `queryOptions`.
|
|
34
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
61
35
|
*/
|
|
62
|
-
export
|
|
36
|
+
export const useFetchWorkerExecutions = <TSelected = WorkerExecutionGroup[]>({
|
|
37
|
+
workflowId,
|
|
38
|
+
workflowExecutionId,
|
|
39
|
+
workspace,
|
|
40
|
+
withResult,
|
|
41
|
+
select,
|
|
42
|
+
queryOptions,
|
|
43
|
+
}: FetchWorkerExecutionsProps<WorkerExecutionGroup[], TSelected>) => {
|
|
63
44
|
const { api } = useAxios();
|
|
64
45
|
|
|
65
|
-
const queryKey =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
const queryKey = [
|
|
47
|
+
"worker_executions",
|
|
48
|
+
workflowId,
|
|
49
|
+
workflowExecutionId,
|
|
50
|
+
workspace,
|
|
51
|
+
withResult ?? null,
|
|
52
|
+
];
|
|
71
53
|
|
|
72
|
-
const query =
|
|
54
|
+
const query = useEntityQuery<WorkerExecutionGroup[], TSelected>({
|
|
73
55
|
queryKey,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
select: (data) => data.pages.flatMap((p) => p.worker_executions),
|
|
90
|
-
|
|
91
|
-
...mergedQueryOptions,
|
|
56
|
+
fetchEntity: async (signal) =>
|
|
57
|
+
(
|
|
58
|
+
await listWorkerExecutions(
|
|
59
|
+
api,
|
|
60
|
+
workflowId,
|
|
61
|
+
workflowExecutionId,
|
|
62
|
+
{ workspace, withResult },
|
|
63
|
+
signal,
|
|
64
|
+
)
|
|
65
|
+
).worker_executions,
|
|
66
|
+
select,
|
|
67
|
+
enabled: Boolean(workflowId) && Boolean(workflowExecutionId),
|
|
68
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchWorkerExecutions"),
|
|
69
|
+
queryOptions,
|
|
92
70
|
});
|
|
93
71
|
|
|
94
|
-
return {
|
|
95
|
-
|
|
96
|
-
queryKey,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
72
|
+
return { ...query, queryKey };
|
|
73
|
+
};
|
|
@@ -1,76 +1,42 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
1
|
import { useAxios } from "@/hooks/useAxios";
|
|
6
|
-
import {
|
|
2
|
+
import { useEntityQuery } from "@/hooks/useEntityQuery";
|
|
3
|
+
import { missingWorkspaceError } from "@/api/entityQuery";
|
|
7
4
|
import { getWorkflow } from "@/api/workflow";
|
|
8
5
|
import type { Workflow } from "@/types/workflow";
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
export type FetchWorkflowProps<TData = Workflow, TSelected = TData> = FetchEntityParams<TData, TSelected>;
|
|
6
|
+
import type { FetchEntityByIdProps } from "@/types/entityQuery";
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
8
|
+
export type FetchWorkflowProps<TData = Workflow, TSelected = TData> = FetchEntityByIdProps<
|
|
9
|
+
TData,
|
|
10
|
+
TSelected
|
|
11
|
+
>;
|
|
18
12
|
|
|
19
13
|
/**
|
|
20
14
|
* useFetchWorkflow
|
|
21
15
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* It also:
|
|
25
|
-
* - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
|
|
26
|
-
* - triggers an error alert via `useAppAlert` whenever `query.error` is present
|
|
27
|
-
*
|
|
28
|
-
* @param id - Workflow identifier (required).
|
|
29
|
-
* @param workspace - Workspace the workflow belongs to (required).
|
|
30
|
-
* @param queryOptions - TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
|
|
31
|
-
*
|
|
32
|
-
* @returns TanStack Query result extended with `queryKey`.
|
|
16
|
+
* Fetches one workflow; `data` is the workflow, or whatever `select` makes of it. Idle while
|
|
17
|
+
* `id` is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
|
|
33
18
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* const fetch = useFetchWorkflow({ id: "wf-123", workspace: "main" });
|
|
38
|
-
* useWorkflowMutations({ queryKey: fetch.queryKey });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* Example:
|
|
42
|
-
* ```ts
|
|
43
|
-
* const { data, isLoading } = useFetchWorkflow({ id: "wf-123", workspace: "main" });
|
|
44
|
-
* // data -> Workflow
|
|
45
|
-
* ```
|
|
19
|
+
* @param {FetchWorkflowProps} props - `id`, `workspace`, `select` and TanStack `queryOptions`.
|
|
20
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
46
21
|
*/
|
|
47
|
-
export const useFetchWorkflow =
|
|
48
|
-
|
|
22
|
+
export const useFetchWorkflow = <TSelected = Workflow>({
|
|
23
|
+
id,
|
|
24
|
+
workspace,
|
|
25
|
+
select,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: FetchWorkflowProps<Workflow, TSelected>) => {
|
|
49
28
|
const { api } = useAxios();
|
|
50
|
-
const { showAlert } = useAppAlert();
|
|
51
29
|
|
|
52
30
|
const queryKey = ["workflow", id, workspace];
|
|
53
31
|
|
|
54
|
-
const query =
|
|
32
|
+
const query = useEntityQuery<Workflow, TSelected>({
|
|
55
33
|
queryKey,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
34
|
+
fetchEntity: (signal) => getWorkflow(api, id, workspace, signal),
|
|
35
|
+
select,
|
|
36
|
+
enabled: Boolean(id),
|
|
37
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflow"),
|
|
38
|
+
queryOptions,
|
|
61
39
|
});
|
|
62
40
|
|
|
63
|
-
|
|
64
|
-
if (!query.error) return;
|
|
65
|
-
|
|
66
|
-
showAlert({
|
|
67
|
-
severity: "error",
|
|
68
|
-
message: query.error.message,
|
|
69
|
-
});
|
|
70
|
-
}, [query.error, showAlert]);
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
...query,
|
|
74
|
-
queryKey,
|
|
75
|
-
};
|
|
41
|
+
return { ...query, queryKey };
|
|
76
42
|
};
|
|
@@ -1,79 +1,49 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
1
|
import { useAxios } from "@/hooks/useAxios";
|
|
6
|
-
import {
|
|
2
|
+
import { useEntityQuery } from "@/hooks/useEntityQuery";
|
|
3
|
+
import { missingWorkspaceError } from "@/api/entityQuery";
|
|
7
4
|
import { getWorkflowExecution } from "@/api/workflow";
|
|
8
5
|
import type { WorkflowExecution } from "@/types/workflow";
|
|
9
|
-
import type {
|
|
6
|
+
import type { FetchEntityProps } from "@/types/entityQuery";
|
|
10
7
|
|
|
11
|
-
export type FetchWorkflowExecutionProps<
|
|
8
|
+
export type FetchWorkflowExecutionProps<
|
|
9
|
+
TData = WorkflowExecution,
|
|
10
|
+
TSelected = TData,
|
|
11
|
+
> = FetchEntityProps<TData, TSelected> & {
|
|
12
12
|
workflowId: string;
|
|
13
13
|
workflowExecutionId: string;
|
|
14
14
|
workspace: string;
|
|
15
|
-
queryOptions?: EntityQueryOptions<TData, TSelected>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const defaultQueryOptions: EntityQueryOptions<WorkflowExecution> = {
|
|
19
|
-
refetchOnMount: "always",
|
|
20
|
-
staleTime: 0,
|
|
21
|
-
gcTime: 0,
|
|
22
15
|
};
|
|
23
16
|
|
|
24
17
|
/**
|
|
25
18
|
* useFetchWorkflowExecution
|
|
26
19
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* It also:
|
|
30
|
-
* - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
|
|
31
|
-
* - triggers an error alert via `useAppAlert` whenever `query.error` is present
|
|
32
|
-
*
|
|
33
|
-
* @param workflowId - Workflow identifier the execution belongs to (required).
|
|
34
|
-
* @param workflowExecutionId - Workflow execution identifier (required).
|
|
35
|
-
* @param workspace - Workspace the workflow belongs to (required).
|
|
36
|
-
* @param queryOptions - TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
|
|
20
|
+
* Fetches one execution of a workflow; `data` is the execution, or whatever `select` makes of
|
|
21
|
+
* it. Idle while an id is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
|
|
37
22
|
*
|
|
38
|
-
* @
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* const { data, isLoading } = useFetchWorkflowExecution({
|
|
43
|
-
* workflowId: "wf-123",
|
|
44
|
-
* workflowExecutionId: "exec-456",
|
|
45
|
-
* workspace: "main",
|
|
46
|
-
* });
|
|
47
|
-
* // data -> WorkflowExecution
|
|
48
|
-
* ```
|
|
23
|
+
* @param {FetchWorkflowExecutionProps} props - `workflowId`, `workflowExecutionId`, `workspace`,
|
|
24
|
+
* `select` and TanStack `queryOptions`.
|
|
25
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
49
26
|
*/
|
|
50
|
-
export const useFetchWorkflowExecution =
|
|
51
|
-
|
|
27
|
+
export const useFetchWorkflowExecution = <TSelected = WorkflowExecution>({
|
|
28
|
+
workflowId,
|
|
29
|
+
workflowExecutionId,
|
|
30
|
+
workspace,
|
|
31
|
+
select,
|
|
32
|
+
queryOptions,
|
|
33
|
+
}: FetchWorkflowExecutionProps<WorkflowExecution, TSelected>) => {
|
|
52
34
|
const { api } = useAxios();
|
|
53
|
-
const { showAlert } = useAppAlert();
|
|
54
35
|
|
|
55
36
|
const queryKey = ["workflow_execution", workflowId, workflowExecutionId, workspace];
|
|
56
37
|
|
|
57
|
-
const query =
|
|
38
|
+
const query = useEntityQuery<WorkflowExecution, TSelected>({
|
|
58
39
|
queryKey,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
fetchEntity: (signal) =>
|
|
41
|
+
getWorkflowExecution(api, workflowId, workflowExecutionId, workspace, signal),
|
|
42
|
+
select,
|
|
43
|
+
enabled: Boolean(workflowId) && Boolean(workflowExecutionId),
|
|
44
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflowExecution"),
|
|
45
|
+
queryOptions,
|
|
64
46
|
});
|
|
65
47
|
|
|
66
|
-
|
|
67
|
-
if (!query.error) return;
|
|
68
|
-
|
|
69
|
-
showAlert({
|
|
70
|
-
severity: "error",
|
|
71
|
-
message: query.error.message,
|
|
72
|
-
});
|
|
73
|
-
}, [query.error, showAlert]);
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
...query,
|
|
77
|
-
queryKey,
|
|
78
|
-
};
|
|
48
|
+
return { ...query, queryKey };
|
|
79
49
|
};
|