forked from equinor/webviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
495a341
commit 95c60a3
Showing
6 changed files
with
119 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
frontend/src/modules/InplaceVolumetricsNew/hooks/useRealizationResponses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Body_get_realizations_response_api, EnsembleScalarResponse_api } from "@api"; | ||
import { apiService } from "@framework/ApiService"; | ||
import { EnsembleIdent } from "@framework/EnsembleIdent"; | ||
import { QueriesOptions, UseQueryResult, useQueries } from "@tanstack/react-query"; | ||
|
||
const STALE_TIME = 60 * 1000; | ||
const CACHE_TIME = 60 * 1000; | ||
|
||
export type ResponseData = { | ||
data: Array<{ | ||
ensembleIdent: EnsembleIdent; | ||
tableName: string; | ||
responseName: string; | ||
responses?: EnsembleScalarResponse_api; | ||
}>; | ||
isFetching: boolean; | ||
}; | ||
|
||
export function useRealizationsResponses( | ||
ensembleIdents: EnsembleIdent[], | ||
tableNames: string[], // also known as "source" | ||
responseNames: string[], | ||
filters?: Body_get_realizations_response_api | ||
): ResponseData { | ||
const queries = []; | ||
const metaData: ResponseData["data"] = []; | ||
|
||
for (const ensembleIdent of ensembleIdents) { | ||
for (const responseName of responseNames) { | ||
for (const tableName of tableNames) { | ||
queries.push({ | ||
queryKey: ["getRealizationsResponse", ensembleIdent?.toString(), tableName, responseName], | ||
queryFn: () => { | ||
const caseUuid = ensembleIdent?.getCaseUuid(); | ||
const ensembleName = ensembleIdent?.getEnsembleName(); | ||
return apiService.inplaceVolumetrics.getRealizationsResponse( | ||
caseUuid, | ||
ensembleName, | ||
tableName, | ||
responseName, | ||
filters | ||
); | ||
}, | ||
staleTime: STALE_TIME, | ||
gcTime: CACHE_TIME, | ||
enabled: Boolean(ensembleIdent && tableName && responseName), | ||
}); | ||
metaData.push({ | ||
ensembleIdent, | ||
tableName, | ||
responseName, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return useQueries({ | ||
queries, | ||
combine: (results: UseQueryResult<EnsembleScalarResponse_api>[]): ResponseData => ({ | ||
data: results.map((result, index) => ({ | ||
...metaData[index], | ||
responses: result.data, | ||
})), | ||
isFetching: results.some((result) => result.isFetching), | ||
}), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
export type SubModule = { | ||
id: string; | ||
relX: number; | ||
relY: number; | ||
relWidth: number; | ||
relHeight: number; | ||
}; | ||
import { EnsembleIdent } from "@framework/EnsembleIdent"; | ||
|
||
export type State = { | ||
subModules: SubModule[]; | ||
selectedEnsembleIdents: EnsembleIdent[]; | ||
selectedTableNames: string[]; | ||
selectedResponseNames: string[]; | ||
}; |
Oops, something went wrong.