Skip to content

Commit

Permalink
Added queries for response fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Nov 3, 2023
1 parent 495a341 commit 95c60a3
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,30 @@ export type FilterSelectProps = {
name: string;
options: string[];
size: number;
onChange?: (value: string) => void;
onChange?: (values: string[]) => void;
};

export const FilterSelect: React.FC<FilterSelectProps> = (props) => {
const [value, setValue] = useValidState<string>("", props.options);
const [values, setValues] = React.useState<string[]>([]);

const selectOptions = props.options.map((option) => ({ value: `${option}`, label: `${option}` }));

function handleSelectionChange(values: string[]) {
setValue(values[0]);
function handleSelectionChange(newValues: string[]) {
setValues(newValues);
if (props.onChange) {
props.onChange(values[0]);
props.onChange(newValues);
}
}

return (
<Label text={props.name}>
<Select options={selectOptions} size={props.size} value={[value]} onChange={handleSelectionChange} />
<Select
options={selectOptions}
size={props.size}
value={values}
onChange={handleSelectionChange}
multiple
/>
</Label>
);
};
Expand Down
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";

Check warning on line 4 in frontend/src/modules/InplaceVolumetricsNew/hooks/useRealizationResponses.ts

View workflow job for this annotation

GitHub Actions / frontend

'QueriesOptions' is defined but never used

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),
}),
});
}
4 changes: 3 additions & 1 deletion frontend/src/modules/InplaceVolumetricsNew/loadModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { State } from "./state";
import { view } from "./view";

const defaultState: State = {
subModules: [],
selectedEnsembleIdents: [],
selectedResponseNames: [],
selectedTableNames: [],
};

const module = ModuleRegistry.initModule<State>("InplaceVolumetricsNew", defaultState);
Expand Down
27 changes: 24 additions & 3 deletions frontend/src/modules/InplaceVolumetricsNew/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ function findValidRealizations(ensembleIdents: EnsembleIdent[], ensembleSet: Ens
}

export const settings = ({ workbenchSession, moduleContext }: ModuleFCProps<State>) => {
const [selectedEnsembleIdents, setSelectedEnsembleIdents] = React.useState<EnsembleIdent[]>([]);
const [selectedEnsembleIdents, setSelectedEnsembleIdents] = moduleContext.useStoreState("selectedEnsembleIdents");
const [selectedResponseNames, setSelectedResponseNames] = moduleContext.useStoreState("selectedResponseNames");

Check warning on line 37 in frontend/src/modules/InplaceVolumetricsNew/settings.tsx

View workflow job for this annotation

GitHub Actions / frontend

'selectedResponseNames' is assigned a value but never used
const [selectedTableNames, setSelectedTableNames] = moduleContext.useStoreState("selectedTableNames");

const isEnsembleSetLoading = useIsEnsembleSetLoading(workbenchSession);
const ensembleSet = useEnsembleSet(workbenchSession);

Expand All @@ -51,12 +54,25 @@ export const settings = ({ workbenchSession, moduleContext }: ModuleFCProps<Stat
return <FilterSelect key={categoryName} name={categoryName} options={stringifiedOptions} size={5} />;
}

function handleSourceChange(values: string[]) {
setSelectedTableNames(values);
}

function handleResponsesChange(values: string[]) {
setSelectedResponseNames(values);
}

const validRealizations = findValidRealizations(selectedEnsembleIdents, ensembleSet);

return (
<div className="w-full h-full flex flex-col gap-4">
<CollapsibleGroup title="Volume response" icon={<BubbleChart fontSize="small" />} expanded>
<FilterSelect name="Response" options={filterOptions?.responses || []} size={5} />
<FilterSelect
name="Response"
options={filterOptions?.responses || []}
size={5}
onChange={handleResponsesChange}
/>
</CollapsibleGroup>
<CollapsibleGroup title="Filter" icon={<FilterAlt fontSize="small" />} expanded>
<div className="flex flex-col gap-2">
Expand All @@ -77,7 +93,12 @@ export const settings = ({ workbenchSession, moduleContext }: ModuleFCProps<Stat
className="flex flex-col gap-2"
>
<FilterSelect name="Fluid zone" options={filterOptions?.fluidZones || []} size={2} />
<FilterSelect name="Source" options={filterOptions?.sources || []} size={2} />
<FilterSelect
name="Source"
options={filterOptions?.sources || []}
size={2}
onChange={handleSourceChange}
/>
{filterOptions &&
Object.entries(filterOptions.categories).map(([category, values]) =>
makeCategoricalSelect(category, values)
Expand Down
12 changes: 4 additions & 8 deletions frontend/src/modules/InplaceVolumetricsNew/state.ts
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[];
};
Loading

0 comments on commit 95c60a3

Please sign in to comment.