@everysk/apps-sdk 0.2.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 +298 -12
- 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 +1 -1
- 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,93 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
1
|
+
import { useCallback } from "react";
|
|
4
2
|
|
|
5
3
|
import { useAxios } from "@/hooks/useAxios";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
4
|
+
import { useEntityQuery } from "@/hooks/useEntityQuery";
|
|
5
|
+
import { missingWorkspaceError } from "@/api/entityQuery";
|
|
8
6
|
import { getFile } from "@/api/file";
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import type { EveryskFile } from "@/types/file";
|
|
8
|
+
import type { FetchEntityByIdProps } from "@/types/entityQuery";
|
|
9
|
+
import { withoutData, type FileDataProps } from "./fileData";
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
export type FetchFileProps<TData = EveryskFile, TSelected = TData> = FetchEntityByIdProps<
|
|
12
|
+
TData,
|
|
13
|
+
TSelected
|
|
14
|
+
> &
|
|
15
|
+
FileDataProps;
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* useFetchFile
|
|
21
19
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* - triggers an error alert via `useAppAlert` whenever `query.error` is present
|
|
27
|
-
*
|
|
28
|
-
* Important notes:
|
|
29
|
-
* - Always returns a single `EveryskFile` object.
|
|
30
|
-
* - `EveryskFile.data` represents the file content and is expected to be a Base64-encoded string
|
|
31
|
-
* when provided by the API (or when sending content through mutations).
|
|
32
|
-
*
|
|
33
|
-
* Parameters (FetchFileProps):
|
|
34
|
-
* @param {string} id
|
|
35
|
-
* EveryskFile identifier (required).
|
|
36
|
-
*
|
|
37
|
-
* @param {string} workspace
|
|
38
|
-
* Workspace the file belongs to (required by `getFile`).
|
|
39
|
-
*
|
|
40
|
-
* @param {EntityQueryOptions<any>} [queryOptions=defaultQueryOptions]
|
|
41
|
-
* TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
|
|
20
|
+
* Fetches one file; `data` is the file, or whatever `select` makes of it. Idle while `id` is
|
|
21
|
+
* empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error
|
|
22
|
+
* alert. The file comes without its content unless `withData` asks for it: show or download it
|
|
23
|
+
* through its `url`.
|
|
42
24
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* - `queryKey`: the cache key used by React Query
|
|
47
|
-
*
|
|
48
|
-
* Tip:
|
|
49
|
-
* - The returned `queryKey` can be reused by mutation hooks for cache invalidation:
|
|
50
|
-
* ```ts
|
|
51
|
-
* const fetch = useFetchFile({ id: "file-123", workspace: "ws-1" });
|
|
52
|
-
* useFileMutations({ queryKey: fetch.queryKey });
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* Example:
|
|
56
|
-
* ```ts
|
|
57
|
-
* const { data, isLoading } = useFetchFile({
|
|
58
|
-
* id: "file-123",
|
|
59
|
-
* workspace: "ws-1",
|
|
60
|
-
* });
|
|
61
|
-
* // data -> EveryskFile
|
|
62
|
-
* ```
|
|
25
|
+
* @param {FetchFileProps} props - `id`, `workspace`, `withData`, `select` and TanStack
|
|
26
|
+
* `queryOptions`.
|
|
27
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
63
28
|
*/
|
|
64
|
-
export const useFetchFile =
|
|
65
|
-
|
|
29
|
+
export const useFetchFile = <TSelected = EveryskFile>({
|
|
30
|
+
id,
|
|
31
|
+
workspace,
|
|
32
|
+
select,
|
|
33
|
+
queryOptions,
|
|
34
|
+
withData = false,
|
|
35
|
+
}: FetchFileProps<EveryskFile, TSelected>) => {
|
|
66
36
|
const { api } = useAxios();
|
|
67
|
-
const { showAlert } = useAppAlert();
|
|
68
37
|
|
|
69
|
-
const queryKey = ["file", id, workspace];
|
|
38
|
+
const queryKey = ["file", id, workspace, { withData }];
|
|
70
39
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return file;
|
|
40
|
+
const selectFile = useCallback(
|
|
41
|
+
(file: EveryskFile): TSelected => {
|
|
42
|
+
const visible = withData ? file : withoutData(file);
|
|
43
|
+
return select ? select(visible) : (visible as TSelected);
|
|
76
44
|
},
|
|
77
|
-
|
|
78
|
-
|
|
45
|
+
[withData, select],
|
|
46
|
+
);
|
|
79
47
|
|
|
80
|
-
|
|
81
|
-
if (!query.error) return;
|
|
82
|
-
|
|
83
|
-
showAlert({
|
|
84
|
-
severity: "error",
|
|
85
|
-
message: query.error.message,
|
|
86
|
-
});
|
|
87
|
-
}, [query.error, showAlert]);
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
...query,
|
|
48
|
+
const query = useEntityQuery<EveryskFile, TSelected>({
|
|
91
49
|
queryKey,
|
|
92
|
-
|
|
50
|
+
fetchEntity: (signal) => getFile(api, id, workspace, { withData }, signal),
|
|
51
|
+
select: selectFile,
|
|
52
|
+
enabled: Boolean(id),
|
|
53
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchFile"),
|
|
54
|
+
queryOptions,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return { ...query, queryKey };
|
|
93
58
|
};
|
|
@@ -1,109 +1,114 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useInfiniteQuery, type UseInfiniteQueryOptions, type QueryKey } from "@tanstack/react-query";
|
|
1
|
+
import { useCallback } from "react";
|
|
3
2
|
|
|
4
3
|
import { useAxios } from "@/hooks/useAxios";
|
|
4
|
+
import { useEntityInfiniteQuery } from "@/hooks/useEntityInfiniteQuery";
|
|
5
5
|
import { listFiles } from "@/api/file";
|
|
6
6
|
import type { EveryskFile, FileListResponse } from "@/types/file";
|
|
7
|
-
import type {
|
|
8
|
-
|
|
7
|
+
import type {
|
|
8
|
+
FetchEntitiesProps,
|
|
9
|
+
ListQueryProps,
|
|
10
|
+
ListCache,
|
|
11
|
+
Projection,
|
|
12
|
+
} from "@/types/entityQuery";
|
|
13
|
+
import {
|
|
14
|
+
buildQueryKey,
|
|
15
|
+
buildQueryObject,
|
|
16
|
+
hasWorkspaceFilter,
|
|
17
|
+
missingWorkspaceError,
|
|
18
|
+
} from "@/api/entityQuery";
|
|
19
|
+
import { withoutData, type FileDataProps } from "./fileData";
|
|
9
20
|
|
|
10
|
-
|
|
21
|
+
/** The query cache of `useFetchFiles`, for typing `setQueryData`. */
|
|
22
|
+
export type FilesCache = ListCache<FileListResponse>;
|
|
11
23
|
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
>;
|
|
24
|
+
export type FetchFilesProps<TData = EveryskFile[]> = ListQueryProps &
|
|
25
|
+
FetchEntitiesProps<EveryskFile, TData, FileListResponse> &
|
|
26
|
+
FileDataProps;
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
/** What leaves the content out of a list: the JSON query returns `data` in full otherwise. */
|
|
29
|
+
const WITHOUT_DATA_PROJECTION = "-data";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The projection a list read sends. The content is left out unless asked for: alone when the app
|
|
33
|
+
* gave no projection, and added to one that only excludes fields. A projection that includes
|
|
34
|
+
* fields is sent as given, since mixing an inclusion with an exclusion is a 500; it then decides
|
|
35
|
+
* itself whether `data` is read.
|
|
36
|
+
*/
|
|
37
|
+
const projectionToSend = (projection: Projection, withData: boolean): Projection => {
|
|
38
|
+
if (withData) return projection;
|
|
20
39
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
const fields = typeof projection === "string" ? [projection].filter(Boolean) : projection;
|
|
41
|
+
if (fields.length === 0) return WITHOUT_DATA_PROJECTION;
|
|
42
|
+
if (!fields.every((field) => field.startsWith("-")) || fields.includes(WITHOUT_DATA_PROJECTION))
|
|
43
|
+
return projection;
|
|
44
|
+
return [...fields, WITHOUT_DATA_PROJECTION];
|
|
25
45
|
};
|
|
26
46
|
|
|
27
47
|
/**
|
|
28
48
|
* useFetchFiles
|
|
29
49
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* - `query.data` returns a flat `EveryskFile[]` (all pages merged).
|
|
38
|
-
*
|
|
39
|
-
* Parameters (FetchInfiniteFileProps):
|
|
40
|
-
* @param {FilterClause[]} [filters=[]]
|
|
41
|
-
* Filters applied to every page request. Must include a `workspace` filter.
|
|
42
|
-
*
|
|
43
|
-
* @param {string[]} [order=[]]
|
|
44
|
-
* Sorting applied to every page request.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} [projection=""]
|
|
47
|
-
* Single field to project: `"field"` returns only that field (others come back null),
|
|
48
|
-
* `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
|
|
49
|
-
*
|
|
50
|
-
* @param {number} [pageSize=10]
|
|
51
|
-
* Number of files to fetch per page.
|
|
52
|
-
*
|
|
53
|
-
* @param {InfiniteOptions<EveryskFile[]>} [queryOptions]
|
|
54
|
-
* TanStack Query options passed through to `useInfiniteQuery`
|
|
55
|
-
* (e.g., enabled, staleTime, gcTime, etc.).
|
|
50
|
+
* Lists files with cursor pagination; `query.data` is every loaded page merged, or whatever
|
|
51
|
+
* `select` makes of it. Paging, `select`, `fetchAllPages` and the missing-workspace error
|
|
52
|
+
* behave as in `useFetchDatastores`. The files come without their content unless `withData`
|
|
53
|
+
* asks for it: show or download each through its `url`. The exclusion of `data` is added to a
|
|
54
|
+
* `projection` of the app's own that only excludes fields; one that includes fields is sent as
|
|
55
|
+
* given (see `projectionToSend`). Either way the content is left out of what the hook returns
|
|
56
|
+
* unless `withData` asks for it.
|
|
56
57
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* - `queryKey`: the cache key used by React Query
|
|
61
|
-
*
|
|
62
|
-
* Example:
|
|
63
|
-
* ```ts
|
|
64
|
-
* const { query } = useFetchFiles({
|
|
65
|
-
* filters: [{ field: "workspace", value: "ws-1" }],
|
|
66
|
-
* pageSize: 20,
|
|
67
|
-
* });
|
|
68
|
-
*
|
|
69
|
-
* // Flat list of all fetched files
|
|
70
|
-
* const files = query.data ?? [];
|
|
71
|
-
* ```
|
|
58
|
+
* @param {FetchFilesProps} props - Filters (one must be `workspace`), order, projection,
|
|
59
|
+
* page size, `withData`, `select`, `fetchAllPages` and TanStack `queryOptions`.
|
|
60
|
+
* @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
|
|
72
61
|
*/
|
|
73
|
-
export function useFetchFiles
|
|
62
|
+
export function useFetchFiles<TData = EveryskFile[]>({
|
|
63
|
+
filters = [],
|
|
64
|
+
order = [],
|
|
65
|
+
projection = "",
|
|
66
|
+
pageSize = 10,
|
|
67
|
+
select,
|
|
68
|
+
fetchAllPages = false,
|
|
69
|
+
queryOptions,
|
|
70
|
+
withData = false,
|
|
71
|
+
}: FetchFilesProps<TData>) {
|
|
74
72
|
const { api } = useAxios();
|
|
73
|
+
const sentProjection = projectionToSend(projection, withData);
|
|
75
74
|
|
|
76
|
-
const queryKey = buildQueryKey(["files"], filters
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
const query = useInfiniteQuery<FileListResponse, Error, EveryskFile[], QueryKey, PageToken>({
|
|
84
|
-
queryKey,
|
|
85
|
-
initialPageParam: null,
|
|
86
|
-
getNextPageParam: (lastPage) => lastPage.next_page_token ?? undefined,
|
|
87
|
-
|
|
88
|
-
queryFn: async ({ pageParam }) => {
|
|
89
|
-
const queryFilter = buildQueryObject({
|
|
90
|
-
filters,
|
|
91
|
-
order,
|
|
92
|
-
projection,
|
|
93
|
-
pageSize,
|
|
94
|
-
pageToken: pageParam ?? undefined,
|
|
95
|
-
});
|
|
75
|
+
const queryKey = buildQueryKey(["files"], filters, {
|
|
76
|
+
order,
|
|
77
|
+
projection: sentProjection,
|
|
78
|
+
pageSize,
|
|
79
|
+
fetchAllPages,
|
|
80
|
+
});
|
|
96
81
|
|
|
97
|
-
|
|
82
|
+
const selectFiles = useCallback(
|
|
83
|
+
(files: EveryskFile[]): TData => {
|
|
84
|
+
const visible = withData ? files : files.map(withoutData);
|
|
85
|
+
return select ? select(visible) : (visible as TData);
|
|
98
86
|
},
|
|
87
|
+
[withData, select],
|
|
88
|
+
);
|
|
99
89
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
const query = useEntityInfiniteQuery<FileListResponse, "files", TData>({
|
|
91
|
+
queryKey,
|
|
92
|
+
itemsKey: "files",
|
|
93
|
+
fetchPage: (pageToken, signal) =>
|
|
94
|
+
listFiles(
|
|
95
|
+
api,
|
|
96
|
+
buildQueryObject({
|
|
97
|
+
filters,
|
|
98
|
+
order,
|
|
99
|
+
projection: sentProjection,
|
|
100
|
+
pageSize,
|
|
101
|
+
pageToken,
|
|
102
|
+
}),
|
|
103
|
+
signal,
|
|
104
|
+
),
|
|
105
|
+
select: selectFiles,
|
|
106
|
+
fetchAllPages,
|
|
107
|
+
configError: hasWorkspaceFilter(filters)
|
|
108
|
+
? undefined
|
|
109
|
+
: missingWorkspaceError("useFetchFiles"),
|
|
110
|
+
queryOptions,
|
|
103
111
|
});
|
|
104
112
|
|
|
105
|
-
return {
|
|
106
|
-
|
|
107
|
-
queryKey,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
113
|
+
return { query, queryKey };
|
|
114
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
-
|
|
3
1
|
import { useAxios } from "@/hooks/useAxios";
|
|
4
|
-
import {
|
|
2
|
+
import { useEntityMutation } from "@/hooks/useEntityMutation";
|
|
5
3
|
import type { EveryskFile } from "@/types/file";
|
|
6
4
|
import { deleteFile, createFile, updateFile } from "@/api/file";
|
|
7
5
|
|
|
@@ -23,9 +21,6 @@ type UseFileMutationsProps = {
|
|
|
23
21
|
queryKey?: unknown[];
|
|
24
22
|
};
|
|
25
23
|
|
|
26
|
-
const getErrorMessage = (err: unknown, fallback: string) =>
|
|
27
|
-
err instanceof Error && err.message ? err.message : fallback;
|
|
28
|
-
|
|
29
24
|
/**
|
|
30
25
|
* useFileMutations
|
|
31
26
|
*
|
|
@@ -44,10 +39,11 @@ const getErrorMessage = (err: unknown, fallback: string) =>
|
|
|
44
39
|
* mutations and show alerts, but it will NOT invalidate any cached queries.
|
|
45
40
|
* - `remove` requires a `workspace` parameter because the underlying API helper `deleteFile(api, id, workspace)`
|
|
46
41
|
* expects it as a query param.
|
|
47
|
-
*
|
|
42
|
+
*
|
|
48
43
|
* - EveryskFile content (`data`):
|
|
49
44
|
* - When creating/updating a file, the file content must be provided in `data` as a Base64-encoded string.
|
|
50
|
-
* - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`)
|
|
45
|
+
* - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`):
|
|
46
|
+
* `fileToBase64(file)` gives it from a `File`, and a data URL is refused before the request
|
|
51
47
|
* - `content_type` should match the file MIME type (e.g., "text/csv", "application/pdf").
|
|
52
48
|
*
|
|
53
49
|
* Parameters (UseFileMutationsProps):
|
|
@@ -64,19 +60,19 @@ const getErrorMessage = (err: unknown, fallback: string) =>
|
|
|
64
60
|
* - `create`:
|
|
65
61
|
* - mutationFn: `createFile(api, data)`
|
|
66
62
|
* - variables: `{ data: Partial<EveryskFile> }`
|
|
67
|
-
* - success message: "
|
|
63
|
+
* - success message: "File created successfully."
|
|
68
64
|
* - error message: "Unable to create the file. Please try again." (fallback)
|
|
69
65
|
*
|
|
70
66
|
* - `update`:
|
|
71
67
|
* - mutationFn: `updateFile(api, id, data)`
|
|
72
68
|
* - variables: `{ id: string; data: Partial<EveryskFile> }`
|
|
73
|
-
* - success message: "
|
|
69
|
+
* - success message: "File updated successfully."
|
|
74
70
|
* - error message: "Unable to update the file. Please try again." (fallback)
|
|
75
71
|
*
|
|
76
72
|
* - `remove`:
|
|
77
73
|
* - mutationFn: `deleteFile(api, id, workspace)`
|
|
78
74
|
* - variables: `{ id: string; workspace: string }`
|
|
79
|
-
* - success message: "
|
|
75
|
+
* - success message: "File deleted successfully."
|
|
80
76
|
* - error message: "Unable to delete the file. Please try again." (fallback)
|
|
81
77
|
*
|
|
82
78
|
* Return value:
|
|
@@ -84,7 +80,7 @@ const getErrorMessage = (err: unknown, fallback: string) =>
|
|
|
84
80
|
* Returns an object with the three TanStack Query mutation results:
|
|
85
81
|
* - `create`: UseMutationResult<EveryskFile, Error, CreateFileProps, unknown>
|
|
86
82
|
* - `update`: UseMutationResult<EveryskFile, Error, UpdateFileProps, unknown>
|
|
87
|
-
* - `remove`: UseMutationResult<
|
|
83
|
+
* - `remove`: UseMutationResult<DeletedEntity, Error, DeleteFileProps, unknown>
|
|
88
84
|
*
|
|
89
85
|
* Each mutation includes standard TanStack Query helpers:
|
|
90
86
|
* - `mutate(variables, options?)`
|
|
@@ -168,72 +164,26 @@ const getErrorMessage = (err: unknown, fallback: string) =>
|
|
|
168
164
|
|
|
169
165
|
export const useFileMutations = ({ queryKey }: UseFileMutationsProps) => {
|
|
170
166
|
const { api } = useAxios();
|
|
171
|
-
const { showAlert } = useAppAlert();
|
|
172
|
-
const queryClient = useQueryClient();
|
|
173
|
-
|
|
174
|
-
const invalidate = async () => {
|
|
175
|
-
if (!queryKey?.length) return;
|
|
176
|
-
await queryClient.invalidateQueries({ queryKey });
|
|
177
|
-
};
|
|
178
167
|
|
|
179
|
-
const create =
|
|
180
|
-
mutationFn:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
severity: "success",
|
|
185
|
-
message: "EveryskFile created successfully.",
|
|
186
|
-
});
|
|
187
|
-
},
|
|
188
|
-
onError: (err: unknown) => {
|
|
189
|
-
showAlert({
|
|
190
|
-
severity: "error",
|
|
191
|
-
message: getErrorMessage(
|
|
192
|
-
err,
|
|
193
|
-
"Unable to create the file. Please try again."
|
|
194
|
-
),
|
|
195
|
-
});
|
|
196
|
-
},
|
|
168
|
+
const create = useEntityMutation({
|
|
169
|
+
mutationFn: ({ data }: CreateFileProps) => createFile(api, data),
|
|
170
|
+
queryKey,
|
|
171
|
+
successMessage: "File created successfully.",
|
|
172
|
+
errorMessage: "Unable to create the file. Please try again.",
|
|
197
173
|
});
|
|
198
174
|
|
|
199
|
-
const update =
|
|
200
|
-
mutationFn:
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
severity: "success",
|
|
205
|
-
message: "EveryskFile updated successfully.",
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
onError: (err: unknown) => {
|
|
209
|
-
showAlert({
|
|
210
|
-
severity: "error",
|
|
211
|
-
message: getErrorMessage(
|
|
212
|
-
err,
|
|
213
|
-
"Unable to update the file. Please try again."
|
|
214
|
-
),
|
|
215
|
-
});
|
|
216
|
-
},
|
|
175
|
+
const update = useEntityMutation({
|
|
176
|
+
mutationFn: ({ id, data }: UpdateFileProps) => updateFile(api, id, data),
|
|
177
|
+
queryKey,
|
|
178
|
+
successMessage: "File updated successfully.",
|
|
179
|
+
errorMessage: "Unable to update the file. Please try again.",
|
|
217
180
|
});
|
|
218
181
|
|
|
219
|
-
const remove =
|
|
220
|
-
mutationFn:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
severity: "success",
|
|
225
|
-
message: "EveryskFile deleted successfully.",
|
|
226
|
-
});
|
|
227
|
-
},
|
|
228
|
-
onError: (err: unknown) => {
|
|
229
|
-
showAlert({
|
|
230
|
-
severity: "error",
|
|
231
|
-
message: getErrorMessage(
|
|
232
|
-
err,
|
|
233
|
-
"Unable to delete the file. Please try again."
|
|
234
|
-
),
|
|
235
|
-
});
|
|
236
|
-
},
|
|
182
|
+
const remove = useEntityMutation({
|
|
183
|
+
mutationFn: ({ id, workspace }: DeleteFileProps) => deleteFile(api, id, workspace),
|
|
184
|
+
queryKey,
|
|
185
|
+
successMessage: "File deleted successfully.",
|
|
186
|
+
errorMessage: "Unable to delete the file. Please try again.",
|
|
237
187
|
});
|
|
238
188
|
|
|
239
189
|
return { create, update, remove };
|
|
@@ -1,94 +1,42 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
1
|
import { useAxios } from "@/hooks/useAxios";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
2
|
+
import { useEntityQuery } from "@/hooks/useEntityQuery";
|
|
3
|
+
import { missingWorkspaceError } from "@/api/entityQuery";
|
|
7
4
|
import { getPortfolio } from "@/api/portfolio";
|
|
8
|
-
import type {
|
|
9
|
-
|
|
10
|
-
export type FetchPortfolioProps<TData = Portfolio, TSelected = TData> = FetchEntityParams<TData, TSelected>;
|
|
5
|
+
import type { Portfolio } from "@/types/portfolio";
|
|
6
|
+
import type { FetchEntityByIdProps } from "@/types/entityQuery";
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
8
|
+
export type FetchPortfolioProps<TData = Portfolio, TSelected = TData> = FetchEntityByIdProps<
|
|
9
|
+
TData,
|
|
10
|
+
TSelected
|
|
11
|
+
>;
|
|
17
12
|
|
|
18
13
|
/**
|
|
19
14
|
* useFetchPortfolio
|
|
20
15
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* It also:
|
|
24
|
-
* - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
|
|
25
|
-
* - triggers an error alert via `useAppAlert` whenever `query.error` is present
|
|
26
|
-
*
|
|
27
|
-
* Important notes:
|
|
28
|
-
* - Always returns a single `Portfolio` object.
|
|
29
|
-
*
|
|
30
|
-
* Parameters (FetchPortfolioProps):
|
|
31
|
-
* @param {string} id
|
|
32
|
-
* Portfolio identifier (required).
|
|
33
|
-
*
|
|
34
|
-
* @param {string} workspace
|
|
35
|
-
* Workspace the portfolio belongs to (required by `getPortfolio`).
|
|
16
|
+
* Fetches one portfolio; `data` is the portfolio, 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.
|
|
36
18
|
*
|
|
37
|
-
* @param {
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* Returns:
|
|
41
|
-
* @returns {object}
|
|
42
|
-
* TanStack Query's `query` object extended with:
|
|
43
|
-
* - `queryKey`: the cache key used by React Query
|
|
44
|
-
*
|
|
45
|
-
* Tip:
|
|
46
|
-
* - The returned `queryKey` can be reused by mutation hooks for cache invalidation:
|
|
47
|
-
* ```ts
|
|
48
|
-
* const fetch = useFetchPortfolio({ id: "pf-123", workspace: "ws-1" });
|
|
49
|
-
* usePortfolioMutations({ queryKey: fetch.queryKey });
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* Example:
|
|
53
|
-
* ```ts
|
|
54
|
-
* const { data, isLoading } = useFetchPortfolio({
|
|
55
|
-
* id: "pf-123",
|
|
56
|
-
* workspace: "ws-1",
|
|
57
|
-
* });
|
|
58
|
-
* // data -> Portfolio
|
|
59
|
-
* ```
|
|
19
|
+
* @param {FetchPortfolioProps} props - `id`, `workspace`, `select` and TanStack `queryOptions`.
|
|
20
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
60
21
|
*/
|
|
61
|
-
export const useFetchPortfolio =
|
|
62
|
-
|
|
22
|
+
export const useFetchPortfolio = <TSelected = Portfolio>({
|
|
23
|
+
id,
|
|
24
|
+
workspace,
|
|
25
|
+
select,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: FetchPortfolioProps<Portfolio, TSelected>) => {
|
|
63
28
|
const { api } = useAxios();
|
|
64
|
-
const { showAlert } = useAppAlert();
|
|
65
29
|
|
|
66
|
-
const queryKey = [
|
|
67
|
-
"portfolio",
|
|
68
|
-
id,
|
|
69
|
-
workspace
|
|
70
|
-
];
|
|
30
|
+
const queryKey = ["portfolio", id, workspace];
|
|
71
31
|
|
|
72
|
-
const query =
|
|
32
|
+
const query = useEntityQuery<Portfolio, TSelected>({
|
|
73
33
|
queryKey,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
34
|
+
fetchEntity: (signal) => getPortfolio(api, id, workspace, signal),
|
|
35
|
+
select,
|
|
36
|
+
enabled: Boolean(id),
|
|
37
|
+
configError: workspace ? undefined : missingWorkspaceError("useFetchPortfolio"),
|
|
38
|
+
queryOptions,
|
|
79
39
|
});
|
|
80
40
|
|
|
81
|
-
|
|
82
|
-
if (!query.error) return;
|
|
83
|
-
|
|
84
|
-
showAlert({
|
|
85
|
-
severity: "error",
|
|
86
|
-
message: query.error.message,
|
|
87
|
-
});
|
|
88
|
-
}, [query.error, showAlert]);
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
...query,
|
|
92
|
-
queryKey,
|
|
93
|
-
};
|
|
41
|
+
return { ...query, queryKey };
|
|
94
42
|
};
|