@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
|
@@ -1,95 +1,86 @@
|
|
|
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 { useEntityInfiniteQuery } from "@/hooks/useEntityInfiniteQuery";
|
|
5
3
|
import { listWorkflowExecutions } from "@/api/workflow";
|
|
6
|
-
import type {
|
|
7
|
-
import { buildQueryKey,
|
|
4
|
+
import type { FetchEntitiesProps, ListCache } from "@/types/entityQuery";
|
|
5
|
+
import { buildQueryKey, missingWorkspaceError } from "@/api/entityQuery";
|
|
8
6
|
import type { WorkflowExecution, WorkflowExecutionListResponse } from "@/types/workflow";
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type InfiniteOptions<TData> = Omit<UseInfiniteQueryOptions<WorkflowExecutionListResponse, Error, TData, QueryKey, PageToken>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
|
|
8
|
+
/** The query cache of `useFetchWorkflowExecutions`, for typing `setQueryData`. */
|
|
9
|
+
export type WorkflowExecutionsCache = ListCache<WorkflowExecutionListResponse>;
|
|
13
10
|
|
|
14
|
-
export type
|
|
11
|
+
export type FetchWorkflowExecutionsProps<TData = WorkflowExecution[]> = FetchEntitiesProps<
|
|
12
|
+
WorkflowExecution,
|
|
13
|
+
TData,
|
|
14
|
+
WorkflowExecutionListResponse
|
|
15
|
+
> & {
|
|
15
16
|
workflowId: string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
staleTime: 0,
|
|
22
|
-
gcTime: 0,
|
|
17
|
+
workspace: string;
|
|
18
|
+
/** Only the executions this worker took part in. */
|
|
19
|
+
workerId?: string;
|
|
20
|
+
/** Include each execution's `resume`, the per-worker summary. */
|
|
21
|
+
withResume?: boolean;
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* useFetchWorkflowExecutions
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* Automatically flattens all pages into a single `WorkflowExecution[]` via `select`.
|
|
32
|
-
*
|
|
33
|
-
* Note: `query.data` returns a flat `WorkflowExecution[]` with all fetched items merged across pages.
|
|
34
|
-
*
|
|
35
|
-
* @param workflowId - Workflow identifier whose executions to fetch (required).
|
|
36
|
-
* @param filters - Filters applied to every page request. Must include a `workspace` filter.
|
|
37
|
-
* @param order - Sorting applied to every page request.
|
|
38
|
-
* @param projection - Single field to project: `"field"` returns only that field (others come
|
|
39
|
-
* back null), `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
|
|
40
|
-
* @param pageSize - Number of executions to fetch per page. Defaults to `10`.
|
|
41
|
-
* @param queryOptions - TanStack Query options passed through to `useInfiniteQuery`.
|
|
27
|
+
* Lists the executions of one workflow, newest first, with cursor pagination; `query.data` is
|
|
28
|
+
* every loaded page merged, or whatever `select` makes of it. `select`, `fetchAllPages` and the
|
|
29
|
+
* missing-workspace error behave as in `useFetchDatastores`. Idle while `workflowId` is empty.
|
|
42
30
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
31
|
+
* The endpoint takes no filters, order or projection: only a worker id and `withResume`. It used
|
|
32
|
+
* to accept them as props and send them in a JSON query the endpoint ignores, along with the
|
|
33
|
+
* cursor, so every "next page" was the first one.
|
|
46
34
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* const { query } = useFetchWorkflowExecutions({
|
|
50
|
-
* workflowId: "wf-123",
|
|
51
|
-
* filters: [{ field: "workspace", value: "main" }],
|
|
52
|
-
* pageSize: 20,
|
|
53
|
-
* });
|
|
35
|
+
* The key starts with `["workflow_executions", workflowId]`, which is what apps invalidate to
|
|
36
|
+
* refresh the list after running a workflow.
|
|
54
37
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
38
|
+
* @param {FetchWorkflowExecutionsProps} props - Workflow id, workspace, worker id,
|
|
39
|
+
* `withResume`, page size, `select`, `fetchAllPages`, `queryOptions`.
|
|
40
|
+
* @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
|
|
58
41
|
*/
|
|
59
|
-
export function useFetchWorkflowExecutions
|
|
42
|
+
export function useFetchWorkflowExecutions<TData = WorkflowExecution[]>({
|
|
43
|
+
workflowId,
|
|
44
|
+
workspace,
|
|
45
|
+
workerId,
|
|
46
|
+
withResume,
|
|
47
|
+
pageSize = 10,
|
|
48
|
+
select,
|
|
49
|
+
fetchAllPages = false,
|
|
50
|
+
queryOptions,
|
|
51
|
+
}: FetchWorkflowExecutionsProps<TData>) {
|
|
60
52
|
const { api } = useAxios();
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
...
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
// The endpoint's two filters go in the key as filters, so a list per worker gets its own entry.
|
|
55
|
+
const filters = [
|
|
56
|
+
...(workerId ? [{ field: "worker_id", value: workerId }] : []),
|
|
57
|
+
...(withResume !== undefined ? [{ field: "with_resume", value: withResume }] : []),
|
|
58
|
+
];
|
|
59
|
+
const queryKey = buildQueryKey(["workflow_executions", workflowId, workspace], filters, {
|
|
60
|
+
pageSize,
|
|
61
|
+
fetchAllPages,
|
|
62
|
+
});
|
|
68
63
|
|
|
69
|
-
const query =
|
|
64
|
+
const query = useEntityInfiniteQuery<
|
|
65
|
+
WorkflowExecutionListResponse,
|
|
66
|
+
"workflow_executions",
|
|
67
|
+
TData
|
|
68
|
+
>({
|
|
70
69
|
queryKey,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
select: (data) => data.pages.flatMap((p) => p.workflow_executions),
|
|
87
|
-
|
|
88
|
-
...mergedQueryOptions,
|
|
70
|
+
itemsKey: "workflow_executions",
|
|
71
|
+
fetchPage: (pageToken, signal) =>
|
|
72
|
+
listWorkflowExecutions(
|
|
73
|
+
api,
|
|
74
|
+
workflowId,
|
|
75
|
+
{ workspace, pageSize, pageToken: pageToken ?? undefined, workerId, withResume },
|
|
76
|
+
signal,
|
|
77
|
+
),
|
|
78
|
+
select,
|
|
79
|
+
fetchAllPages,
|
|
80
|
+
enabled: Boolean(workflowId),
|
|
81
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflowExecutions"),
|
|
82
|
+
queryOptions,
|
|
89
83
|
});
|
|
90
84
|
|
|
91
|
-
return {
|
|
92
|
-
query,
|
|
93
|
-
queryKey,
|
|
94
|
-
};
|
|
85
|
+
return { query, queryKey };
|
|
95
86
|
}
|
|
@@ -1,84 +1,68 @@
|
|
|
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 { useEntityInfiniteQuery } from "@/hooks/useEntityInfiniteQuery";
|
|
5
3
|
import { listWorkflows } from "@/api/workflow";
|
|
4
|
+
import { buildQueryKey, missingWorkspaceError } from "@/api/entityQuery";
|
|
6
5
|
import type { Workflow, WorkflowListResponse } from "@/types/workflow";
|
|
6
|
+
import type { FetchEntitiesProps, ListCache } from "@/types/entityQuery";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type InfiniteOptions<TData> = Omit<UseInfiniteQueryOptions<WorkflowListResponse, Error, TData, QueryKey, PageToken>,"queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
|
|
11
|
-
|
|
12
|
-
export type FetchInfiniteWorkflowProps = {
|
|
13
|
-
workspace?: string;
|
|
14
|
-
pageSize?: number;
|
|
15
|
-
queryOptions?: InfiniteOptions<Workflow[]>;
|
|
16
|
-
};
|
|
8
|
+
/** The query cache of `useFetchWorkflows`, for typing `setQueryData`. */
|
|
9
|
+
export type WorkflowsCache = ListCache<WorkflowListResponse>;
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
export type FetchWorkflowsProps<TData = Workflow[]> = FetchEntitiesProps<
|
|
12
|
+
Workflow,
|
|
13
|
+
TData,
|
|
14
|
+
WorkflowListResponse
|
|
15
|
+
> & {
|
|
16
|
+
/** Workspace to list. Required: without one the API reads `main`, not the account. */
|
|
17
|
+
workspace: string;
|
|
18
|
+
/** A name prefix, an id, `#tag #tag` (every tag), or `&link_uid`. */
|
|
19
|
+
search?: string;
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
23
|
* useFetchWorkflows
|
|
26
24
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* Note: `query.data` returns a flat `Workflow[]` with all fetched items merged across pages.
|
|
33
|
-
*
|
|
34
|
-
* @param {string} [workspace]
|
|
35
|
-
* Current workspace name. Sent as a query param via the legacy method, required by some API configurations.
|
|
36
|
-
*
|
|
37
|
-
* @param {number} [pageSize=10]
|
|
38
|
-
* Number of workflows to fetch per page.
|
|
25
|
+
* Lists workflows with cursor pagination; `query.data` is every loaded page merged, or
|
|
26
|
+
* whatever `select` makes of it. `select` and `fetchAllPages` behave as in
|
|
27
|
+
* `useFetchDatastores`. This endpoint takes a workspace and a text `search` rather than
|
|
28
|
+
* filters.
|
|
39
29
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* (e.g., enabled, staleTime, gcTime, etc.).
|
|
30
|
+
* A missing workspace fails loudly, without a request, as in every other hook. This hook used to
|
|
31
|
+
* allow one, documented as listing the account's workflows; the API reads `main` instead.
|
|
43
32
|
*
|
|
44
|
-
* @
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const { query } = useFetchWorkflows({ workspace: "ws-1", pageSize: 20 });
|
|
51
|
-
*
|
|
52
|
-
* // Flat list of all fetched workflows
|
|
53
|
-
* const workflows = query.data ?? [];
|
|
54
|
-
* ```
|
|
33
|
+
* @param {FetchWorkflowsProps} props - Workspace, search, page size, `select`,
|
|
34
|
+
* `fetchAllPages` and TanStack `queryOptions`.
|
|
35
|
+
* @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
|
|
55
36
|
*/
|
|
56
|
-
export function useFetchWorkflows
|
|
37
|
+
export function useFetchWorkflows<TData = Workflow[]>({
|
|
38
|
+
workspace,
|
|
39
|
+
search,
|
|
40
|
+
pageSize = 10,
|
|
41
|
+
select,
|
|
42
|
+
fetchAllPages = false,
|
|
43
|
+
queryOptions,
|
|
44
|
+
}: FetchWorkflowsProps<TData>) {
|
|
57
45
|
const { api } = useAxios();
|
|
58
46
|
|
|
59
|
-
const queryKey
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
...(queryOptions ?? {}),
|
|
64
|
-
}), [queryOptions]);
|
|
47
|
+
const queryKey = buildQueryKey(["workflows", workspace, search ?? null], [], {
|
|
48
|
+
pageSize,
|
|
49
|
+
fetchAllPages,
|
|
50
|
+
});
|
|
65
51
|
|
|
66
|
-
const query =
|
|
52
|
+
const query = useEntityInfiniteQuery<WorkflowListResponse, "workflows", TData>({
|
|
67
53
|
queryKey,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
select
|
|
76
|
-
|
|
77
|
-
|
|
54
|
+
itemsKey: "workflows",
|
|
55
|
+
fetchPage: (pageToken, signal) =>
|
|
56
|
+
listWorkflows(
|
|
57
|
+
api,
|
|
58
|
+
{ workspace, search, pageSize, pageToken: pageToken ?? undefined },
|
|
59
|
+
signal,
|
|
60
|
+
),
|
|
61
|
+
select,
|
|
62
|
+
fetchAllPages,
|
|
63
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflows"),
|
|
64
|
+
queryOptions,
|
|
78
65
|
});
|
|
79
66
|
|
|
80
|
-
return {
|
|
81
|
-
query,
|
|
82
|
-
queryKey,
|
|
83
|
-
};
|
|
67
|
+
return { query, queryKey };
|
|
84
68
|
}
|
|
@@ -1,62 +1,108 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
1
2
|
import { useMutation } from "@tanstack/react-query";
|
|
2
3
|
|
|
3
4
|
import { useAxios } from "@/hooks/useAxios";
|
|
4
5
|
import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
|
|
6
|
+
import { useWebSocket } from "@/contexts/webSocketContext/hooks/useWebSocket";
|
|
7
|
+
import {
|
|
8
|
+
getWorkerExecution,
|
|
9
|
+
getWorkflowExecution,
|
|
10
|
+
runWorkflow,
|
|
11
|
+
terminalRunStatusOf,
|
|
12
|
+
} from "@/api/workflow";
|
|
13
|
+
import { anySignal, unlessAborted } from "@/lib/abort";
|
|
14
|
+
import {
|
|
15
|
+
RUN_FAILED_MESSAGE,
|
|
16
|
+
WorkflowRunAbortedError,
|
|
17
|
+
runWorkflowToEnd,
|
|
18
|
+
type WorkflowWaitOptions,
|
|
19
|
+
} from "@/lib/workflowRun";
|
|
5
20
|
import type { AnyRecord } from "@/types/anyRecord";
|
|
6
|
-
import type {
|
|
7
|
-
import { runWorkflow, runWorkflowAndGetResult } from "@/api/workflow";
|
|
21
|
+
import type { WorkflowResult } from "@/types/workflow";
|
|
8
22
|
|
|
9
23
|
type RunWorkflowProps = {
|
|
10
24
|
id: string;
|
|
11
25
|
workspace: string;
|
|
12
26
|
parameters: AnyRecord;
|
|
13
|
-
|
|
27
|
+
/** How the run is waited for; see `WorkflowWaitOptions`. */
|
|
28
|
+
waitOptions?: WorkflowWaitOptions;
|
|
14
29
|
};
|
|
15
30
|
|
|
16
|
-
const getErrorMessage = (err: unknown, fallback: string) =>
|
|
17
|
-
err instanceof Error && err.message ? err.message : fallback;
|
|
18
|
-
|
|
19
31
|
/**
|
|
20
32
|
* useRunWorkflow
|
|
21
33
|
*
|
|
22
|
-
* TanStack Query
|
|
23
|
-
*
|
|
24
|
-
*
|
|
34
|
+
* A TanStack Query mutation that starts a workflow run, waits for it to end, then reads the
|
|
35
|
+
* Ender's worker execution. Resolves with `{ execution, workerExecution, result }` (`result` is
|
|
36
|
+
* `null` when the run has no output), and fails unless the run ended `SUCCEEDED`.
|
|
37
|
+
*
|
|
38
|
+
* It waits over the websocket (see `runWorkflowToEnd`), not by polling: the backend announces
|
|
39
|
+
* each worker and the run's end on the app's channel, and the end itself is then read from the
|
|
40
|
+
* API. So it requires `WebSocketProvider`, and throws on render without it. To start a run
|
|
41
|
+
* without waiting, and without a websocket, use `useTriggerWorkflow`.
|
|
25
42
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
43
|
+
* Leaving the screen stops it — listening, reads in flight and the result read — and so does
|
|
44
|
+
* `waitOptions.signal`. Neither is alerted: there is no screen left, or the app asked for it. Both
|
|
45
|
+
* fail the mutation with a `WorkflowRunAbortedError`, the signal's reason as the cause. The run itself goes
|
|
46
|
+
* on on the server. `waitOptions.timeoutMs` bounds only the wait for the end; the result read
|
|
47
|
+
* after it is a single request that the timeout does not cover. Any other failure is shown as an
|
|
48
|
+
* error alert through `useAppAlert`, and logged with its cause, which says why a wait timed out.
|
|
31
49
|
*
|
|
32
|
-
*
|
|
33
|
-
* and
|
|
50
|
+
* @returns {UseMutationResult} The mutation; `mutate({ id, workspace, parameters, waitOptions })`
|
|
51
|
+
* starts a run and waits for it.
|
|
34
52
|
*/
|
|
35
53
|
export const useRunWorkflow = () => {
|
|
36
54
|
const { api } = useAxios();
|
|
37
55
|
const { showAlert } = useAppAlert();
|
|
56
|
+
const socket = useWebSocket();
|
|
57
|
+
const unmounted = useRef<AbortSignal | undefined>(undefined);
|
|
38
58
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const controller = new AbortController();
|
|
61
|
+
unmounted.current = controller.signal;
|
|
62
|
+
return () => controller.abort();
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
return useMutation({
|
|
66
|
+
mutationFn: async ({
|
|
67
|
+
id,
|
|
68
|
+
workspace,
|
|
69
|
+
parameters,
|
|
70
|
+
waitOptions,
|
|
71
|
+
}: RunWorkflowProps): Promise<WorkflowResult> => {
|
|
72
|
+
const { signal, dispose } = anySignal([waitOptions?.signal, unmounted.current]);
|
|
73
|
+
try {
|
|
74
|
+
const execution = await runWorkflowToEnd({
|
|
75
|
+
startRun: () => runWorkflow(api, id, workspace, parameters),
|
|
76
|
+
getExecution: (workflowExecutionId, readSignal) =>
|
|
77
|
+
getWorkflowExecution(api, id, workflowExecutionId, workspace, readSignal),
|
|
78
|
+
subscribeToEvents: socket.subscribe,
|
|
79
|
+
subscribeToStatus: socket.subscribeStatus,
|
|
80
|
+
...waitOptions,
|
|
81
|
+
signal,
|
|
82
|
+
});
|
|
49
83
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
84
|
+
const runStatus = terminalRunStatusOf(execution.run_status);
|
|
85
|
+
if (runStatus !== "SUCCEEDED")
|
|
86
|
+
throw new Error(`Workflow execution ${runStatus?.toLowerCase()}`);
|
|
87
|
+
|
|
88
|
+
const enderId = execution.ender_worker_execution_id;
|
|
89
|
+
if (!enderId) return { execution, workerExecution: null, result: null };
|
|
90
|
+
|
|
91
|
+
const workerExecution = await unlessAborted(
|
|
92
|
+
getWorkerExecution(api, id, enderId, workspace, signal),
|
|
93
|
+
signal,
|
|
94
|
+
).catch((error: unknown) => {
|
|
95
|
+
throw signal.aborted ? new WorkflowRunAbortedError(signal.reason) : error;
|
|
96
|
+
});
|
|
97
|
+
return { execution, workerExecution, result: workerExecution.result ?? null };
|
|
98
|
+
} finally {
|
|
99
|
+
dispose();
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
onError: (error) => {
|
|
103
|
+
if (error instanceof WorkflowRunAbortedError || unmounted.current?.aborted) return;
|
|
104
|
+
console.error("Workflow run failed:", error);
|
|
105
|
+
showAlert({ severity: "error", message: error.message || RUN_FAILED_MESSAGE });
|
|
58
106
|
},
|
|
59
107
|
});
|
|
60
|
-
|
|
61
|
-
return { runAsync, runAndGetResult };
|
|
62
108
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
|
|
3
|
+
import { useAxios } from "@/hooks/useAxios";
|
|
4
|
+
import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
|
|
5
|
+
import { runWorkflow } from "@/api/workflow";
|
|
6
|
+
import { RUN_FAILED_MESSAGE } from "@/lib/workflowRun";
|
|
7
|
+
import type { AnyRecord } from "@/types/anyRecord";
|
|
8
|
+
|
|
9
|
+
type TriggerWorkflowProps = {
|
|
10
|
+
id: string;
|
|
11
|
+
workspace: string;
|
|
12
|
+
parameters: AnyRecord;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* useTriggerWorkflow
|
|
17
|
+
*
|
|
18
|
+
* A TanStack Query mutation that starts a workflow run and resolves with the execution it started,
|
|
19
|
+
* still `RUNNING`. Fire-and-forget, for when nothing waits for the output; it needs no websocket.
|
|
20
|
+
* To wait for the run and read its result, use `useRunWorkflow`.
|
|
21
|
+
*
|
|
22
|
+
* A failure is shown as an error alert through `useAppAlert`.
|
|
23
|
+
*
|
|
24
|
+
* @returns {UseMutationResult} The mutation; `mutate({ id, workspace, parameters })` starts a run.
|
|
25
|
+
*/
|
|
26
|
+
export const useTriggerWorkflow = () => {
|
|
27
|
+
const { api } = useAxios();
|
|
28
|
+
const { showAlert } = useAppAlert();
|
|
29
|
+
|
|
30
|
+
return useMutation({
|
|
31
|
+
mutationFn: ({ id, workspace, parameters }: TriggerWorkflowProps) =>
|
|
32
|
+
runWorkflow(api, id, workspace, parameters),
|
|
33
|
+
onError: (error) =>
|
|
34
|
+
showAlert({ severity: "error", message: error.message || RUN_FAILED_MESSAGE }),
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -1,78 +1,45 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
1
|
import { useAxios } from "@/hooks/useAxios";
|
|
6
|
-
import {
|
|
7
|
-
import type { Workspace } from "@/types/workspace";
|
|
2
|
+
import { useEntityQuery } from "@/hooks/useEntityQuery";
|
|
8
3
|
import { getWorkspace } from "@/api/workspace";
|
|
9
|
-
import type {
|
|
4
|
+
import type { Workspace } from "@/types/workspace";
|
|
5
|
+
import type { FetchEntityProps } from "@/types/entityQuery";
|
|
10
6
|
|
|
11
|
-
export type FetchWorkspaceProps<TData = Workspace, TSelected = TData> =
|
|
7
|
+
export type FetchWorkspaceProps<TData = Workspace, TSelected = TData> = FetchEntityProps<
|
|
8
|
+
TData,
|
|
9
|
+
TSelected
|
|
10
|
+
> & {
|
|
12
11
|
name: string;
|
|
13
|
-
queryOptions?: EntityQueryOptions<TData, TSelected>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const defaultQueryOptions: EntityQueryOptions<Workspace> = {
|
|
17
|
-
refetchOnMount: "always",
|
|
18
|
-
staleTime: 0,
|
|
19
|
-
gcTime: 0,
|
|
20
12
|
};
|
|
21
13
|
|
|
22
14
|
/**
|
|
23
15
|
* useFetchWorkspace
|
|
24
16
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* It also:
|
|
28
|
-
* - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
|
|
29
|
-
* - triggers an error alert via `useAppAlert` whenever `query.error` is present
|
|
17
|
+
* Fetches one workspace by name; `data` is the workspace, or whatever `select` makes of it.
|
|
30
18
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
19
|
+
* A workspace is identified by its name — the API's `GET /workspaces/:id` takes the name, its
|
|
20
|
+
* UID — so `name` is this hook's id, and like the other hooks' id it usually comes from a
|
|
21
|
+
* selection the user has not made yet: while it is empty the hook stays idle, rather than fail
|
|
22
|
+
* as a misconfigured app. A failure is shown as an error alert.
|
|
34
23
|
*
|
|
35
|
-
* @param queryOptions
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* Returns:
|
|
39
|
-
* @returns {object}
|
|
40
|
-
* TanStack Query's `query` object extended with:
|
|
41
|
-
* - `queryKey`: the cache key used by React Query
|
|
42
|
-
*
|
|
43
|
-
* Example:
|
|
44
|
-
* ```ts
|
|
45
|
-
* const { data, isLoading } = useFetchWorkspace({ name: "main" });
|
|
46
|
-
* // data -> Workspace
|
|
47
|
-
* ```
|
|
24
|
+
* @param {FetchWorkspaceProps} props - `name`, `select` and TanStack `queryOptions`.
|
|
25
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
48
26
|
*/
|
|
49
|
-
export const useFetchWorkspace =
|
|
50
|
-
|
|
27
|
+
export const useFetchWorkspace = <TSelected = Workspace>({
|
|
28
|
+
name,
|
|
29
|
+
select,
|
|
30
|
+
queryOptions,
|
|
31
|
+
}: FetchWorkspaceProps<Workspace, TSelected>) => {
|
|
51
32
|
const { api } = useAxios();
|
|
52
|
-
const { showAlert } = useAppAlert();
|
|
53
33
|
|
|
54
34
|
const queryKey = ["workspace", name];
|
|
55
35
|
|
|
56
|
-
const query =
|
|
36
|
+
const query = useEntityQuery<Workspace, TSelected>({
|
|
57
37
|
queryKey,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...queryOptions ?? {}
|
|
38
|
+
fetchEntity: (signal) => getWorkspace(api, name, signal),
|
|
39
|
+
select,
|
|
40
|
+
enabled: Boolean(name),
|
|
41
|
+
queryOptions,
|
|
63
42
|
});
|
|
64
43
|
|
|
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
|
-
};
|
|
44
|
+
return { ...query, queryKey };
|
|
78
45
|
};
|