Skip to content

Commit

Permalink
fix: Api changes adaption, fix breaking changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Feb 7, 2024
1 parent 1d5c61b commit 4b7ac39
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 115 deletions.
23 changes: 5 additions & 18 deletions src/features/Compute/CaseGroup/CaseGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,11 @@ export const CaseGroup = ({
);
}
};
const channelSettings = settingsFilter('Object');
const variogramSettings = settingsFilter('Variogram');

const variogramFilter = (name: string) => {
if (variogramSettings) {
return variogramSettings[0].allowedMethods.filter(
(item) => item.name === name,
);
}
};
const indicatorSettings = variogramFilter('Indicator');
const NetToGrossSettings = variogramFilter('Net-To-Gross');
const ContiniousParameterSettings = variogramFilter('ContiniousParameter');
const channelSettings = settingsFilter('Channel');
const indicatorSettings = settingsFilter('Indicator');
const NetToGrossSettings = settingsFilter('Net-To-Gross');
const ContiniousParameterSettings = settingsFilter('ContiniousParameter');

const filerLocalList = useCallback(
(methodType: string) => {
Expand Down Expand Up @@ -160,9 +152,7 @@ export const CaseGroup = ({

switch (methodType) {
case 'Channel':
methodId =
channelSettings &&
channelSettings[0].allowedMethods[0].computeMethodId;
methodId = channelSettings && channelSettings[0].computeMethodId;
break;
case 'Indicator':
methodId = indicatorSettings && indicatorSettings[0].computeMethodId;
Expand Down Expand Up @@ -235,13 +225,11 @@ export const CaseGroup = ({
const saveCase = async (
modelAreaId: string,
computeMethodId: string,
computeTypeId: string,
inputSettings: CreateComputeCaseInputSettingsForm[],
) => {
const caseRequestBody: CreateComputeCaseCommandForm = {
modelAreaId: modelAreaId,
computeMethodId: computeMethodId,
computeTypeId: computeTypeId,
inputSettings: inputSettings,
};
if (modelId) {
Expand Down Expand Up @@ -406,7 +394,6 @@ export const CaseGroup = ({
runCase={runCase}
removeLocalCase={removeLocalCase}
settingsFilter={settingsFilter}
variogramFilter={variogramFilter}
duplicateCase={duplicateCase}
/>
))}
Expand Down
27 changes: 5 additions & 22 deletions src/features/Compute/CaseGroup/CaseRow/CaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
CreateComputeCaseCommandResponse,
CreateComputeCaseInputSettingsForm,
ListComputeCasesByAnalogueModelIdQueryResponse,
ListComputeSettingsDto,
ListComputeSettingsInputDto,
ListComputeSettingsInputValueDto,
ListComputeSettingsMethodDto,
Expand All @@ -33,7 +32,6 @@ export const CaseRow = ({
deleteCase,
removeLocalCase,
settingsFilter,
variogramFilter,
duplicateCase,
}: {
rowCase: ComputeCaseDto;
Expand All @@ -44,7 +42,6 @@ export const CaseRow = ({
saveCase: (
modelAreaId: string,
computeMethodId: string,
computeTypeId: string,
inputSettings: CreateComputeCaseInputSettingsForm[],
) => Promise<CreateComputeCaseCommandResponse | undefined>;
updateCase?: (
Expand All @@ -58,10 +55,7 @@ export const CaseRow = ({
setAlertMessage: (message: string) => void;
runCase: (id: string) => void;
removeLocalCase: (id: string) => void;
settingsFilter: (name: string) => ListComputeSettingsDto[] | undefined;
variogramFilter?: (
name: string,
) => ListComputeSettingsMethodDto[] | undefined;
settingsFilter: (name: string) => ListComputeSettingsMethodDto[] | undefined;
duplicateCase?: (id: string) => void;
}) => {
const [selectedModelArea, setModelArea] = useState<ModelAreaDto[]>();
Expand All @@ -80,13 +74,9 @@ export const CaseRow = ({

const { data, isLoading } = useFetchModel();

const channelSettings = settingsFilter('Object');
const variogramSettings = settingsFilter('Variogram');

const indicatorSettings = variogramFilter && variogramFilter('Indicator');
const netToGrossSettings = variogramFilter && variogramFilter('Net-To-Gross');
const continiousParameterSettings =
variogramFilter && variogramFilter('ContiniousParameter');
const indicatorSettings = settingsFilter('Indicator');
const netToGrossSettings = settingsFilter('Net-To-Gross');
const continiousParameterSettings = settingsFilter('ContiniousParameter');

const runRowCase = () => {
if (id) runCase(id);
Expand Down Expand Up @@ -271,12 +261,7 @@ export const CaseRow = ({

// Check if the instance is an Object case and right data/methods is provided
// TODO: Seperate into own method, take type as argument. Support all types not just Channel cases
if (saveCase && variogramSettings) {
const computeType: ListComputeSettingsDto =
caseType === 'Object' && channelSettings
? channelSettings[0]
: variogramSettings[0];

if (saveCase) {
if (
row[0] !== undefined &&
selectedModelArea &&
Expand All @@ -302,7 +287,6 @@ export const CaseRow = ({
const res = await saveCase(
selectedModelArea[0].modelAreaId,
row[0].computeMethod.computeMethodId,
computeType.computeTypeId,
inputSettingsList,
);
if (res?.success) {
Expand All @@ -327,7 +311,6 @@ export const CaseRow = ({
const res = await saveCase(
'',
row[0].computeMethod.computeMethodId,
computeType.computeTypeId,
inputSettingsList,
);
if (res?.success) {
Expand Down
41 changes: 30 additions & 11 deletions src/features/Results/CaseResult/CaseResultView/CaseResultView.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
/* eslint-disable max-lines-per-function */
import * as Styled from './CaseResultView.styled';

import { Typography } from '@equinor/eds-core-react';
import { ComputeCaseDto, GetResultDto } from '../../../../api/generated';
import {
ComputeCaseDto,
GetChannelResultsDto,
} from '../../../../api/generated';
import { ChannelResult } from './ObjectCaseResult/ChannelResult';
import { VariogramCaseResult } from './VariogramCaseResult/VariogramCaseResult';
import ResultIMG from './vargrest_output-0-_variogram_slices_.png';

export const CaseResultView = ({
resultList,
channelResultList,
variogramResultList,
computeCases,
}: {
resultList: GetResultDto[];
channelResultList?: GetChannelResultsDto[];
variogramResultList?: GetChannelResultsDto[];
computeCases?: ComputeCaseDto[];
}) => {
const caseType = resultList[0].resultType;
const channelType =
channelResultList !== undefined && channelResultList[0].type
? channelResultList[0].type
: '';
const variogramType =
variogramResultList !== undefined && variogramResultList[0].type
? variogramResultList[0].type
: '';

return (
<Styled.CaseResultView>
<Typography variant="h2">{caseType} results</Typography>
<Typography variant="h2">
{channelType !== ''
? channelType
: variogramType !== ''
? variogramType
: ''}{' '}
results
</Typography>
<Styled.CaseResultList>
{caseType === 'Variogram' && (
{variogramResultList && (
<VariogramCaseResult
resultList={resultList}
resultList={variogramResultList}
img={ResultIMG}
></VariogramCaseResult>
)}

{caseType === 'Object' &&
resultList.map((obj, index) => (
{channelResultList &&
channelResultList.map((obj, index) => (
<Styled.Wrapper key={obj.computeCaseId}>
<ChannelResult
data={obj}
Expand All @@ -39,7 +58,7 @@ export const CaseResultView = ({
: []
}
></ChannelResult>
{index < resultList.length - 1 && (
{index < channelResultList.length - 1 && (
<Styled.StyledDivider
variant="small"
color="medium"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Typography } from '@equinor/eds-core-react';
import { ComputeCaseDto, GetResultDto } from '../../../../../api/generated';
import {
ComputeCaseDto,
GetChannelResultsDto,
} from '../../../../../api/generated';
import * as Styled from './ChannelResult.styled';
import { ChannelResultTable } from './ChannelResultTable';

export const ChannelResult = ({
data,
computeCase,
}: {
data: GetResultDto;
data: GetChannelResultsDto;
computeCase?: ComputeCaseDto[];
}) => {
let modelArea = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
/* eslint-disable max-lines-per-function */
import { Table } from '@equinor/eds-core-react';

import { GetResultDto } from '../../../../../api/generated';
import { GetChannelResultsDto } from '../../../../../api/generated';
import * as Styled from './ChannelResultTable.styled';

const NumberOfDecimals = 2;

export const ChannelResultTable = ({ data }: { data: GetResultDto }) => {
const filterValues = (name: string) => {
return data.resultValues.filter((d) => d.name === name);
export const ChannelResultTable = ({
data,
}: {
data: GetChannelResultsDto;
}) => {
const roundResultString = (value?: number) => {
if (value) {
return value.toFixed(NumberOfDecimals);
}
};

const roundResultString = (value: string) => {
return parseFloat(value).toFixed(NumberOfDecimals);
};

const channelHeightCount = filterValues('channel-height_count');
const channelHeightMean = filterValues('channel-height_mean');
const channelHeightSD = filterValues('channel-height_sd');

const channelWidthCount = filterValues('channel-width_count');
const channelWidthMean = filterValues('channel-width_mean');
const channelWidthSD = filterValues('channel-width_sd');

return (
<Styled.Table>
<Table.Head>
Expand All @@ -37,22 +31,22 @@ export const ChannelResultTable = ({ data }: { data: GetResultDto }) => {
<Table.Row>
<Styled.ColumnCell>Channel width</Styled.ColumnCell>
<Styled.DataCell>
{roundResultString(channelWidthMean[0].value)}
{roundResultString(data.channelWidth?.mean)}
</Styled.DataCell>
<Styled.DataCell>
{roundResultString(channelWidthSD[0].value)}
{roundResultString(data.channelWidth?.sd)}
</Styled.DataCell>
<Styled.DataCell>{channelWidthCount[0].value}</Styled.DataCell>
<Styled.DataCell>{data.channelWidth?.count}</Styled.DataCell>
</Table.Row>
<Table.Row>
<Styled.ColumnCell>Channel height</Styled.ColumnCell>
<Styled.DataCell>
{roundResultString(channelHeightMean[0].value)}
{roundResultString(data.channelHeight?.mean)}
</Styled.DataCell>
<Styled.DataCell>
{roundResultString(channelHeightSD[0].value)}
{roundResultString(data.channelHeight?.sd)}
</Styled.DataCell>
<Styled.DataCell>{channelHeightCount[0].value}</Styled.DataCell>
<Styled.DataCell>{data.channelHeight?.count}</Styled.DataCell>
</Table.Row>
</Table.Body>
</Styled.Table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetResultDto } from '../../../../../api/generated';
import { GetVariogramResultsDto } from '../../../../../api/generated';
import { CaseCardComponent } from '../../../../../components/CaseCardComponent/CaseCardComponent';
import { ImageView } from '../../../../../components/ImageView/ImageView';
import * as Styled from './VariogramCaseResult.styled';
Expand All @@ -8,13 +8,13 @@ export const VariogramCaseResult = ({
resultList,
img,
}: {
resultList: GetResultDto[];
resultList: GetVariogramResultsDto[];
img: string;
}) => {
return (
<>
{resultList.map((item) => (
<CaseCardComponent key={item.computeCaseId} title={item.resultType}>
<CaseCardComponent key={item.computeCaseId} title="Variogram">
<Styled.CaseResultCard>
<ImageView text="run" img={img} altText="run"></ImageView>
<Styled.CaseLeftDiv>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
/* eslint-disable max-lines-per-function */
import { Table } from '@equinor/eds-core-react';
import { GetVariogramResultsDto } from '../../../../../api/generated';

import { GetResultDto } from '../../../../../api/generated';

// const NumberOfDecimals = 2;

export const VariogramResultTable = ({ data }: { data: GetResultDto }) => {
// const filterValues = (name: string) => {
// return data.resultValues.filter((d) => d.name === name);
// };

// const roundResultString = (value: string) => {
// return parseFloat(value).toFixed(NumberOfDecimals);
// };

// const channelHeightCount = filterValues('channel-height_count');
// const channelHeightMean = filterValues('channel-height_mean');
// const channelHeightSD = filterValues('channel-height_sd');

export const VariogramResultTable = ({
data,
}: {
data: GetVariogramResultsDto;
}) => {
return (
<Table>
<Table.Body>
<Table.Row>
<Table.Cell>Quality factor</Table.Cell>
<Table.Cell>--Data--</Table.Cell>
<Table.Cell>{data.quality}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Model area</Table.Cell>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useQuery } from '@tanstack/react-query';
import { AnalogueModelsService } from '../api/generated/services/AnalogueModelsService';
import { ResultsService } from '../api/generated/services/ResultsService';

import { useMsal } from '@azure/msal-react';
import { useParams } from 'react-router-dom';
import { useAccessToken } from './useAccessToken';

export const useFetchResults = () => {
export const useFetchChannelResults = () => {
const { modelId } = useParams();
const { instance, accounts } = useMsal();
const token = useAccessToken(instance, accounts[0]);

const query = useQuery({
queryKey: ['model-results', modelId],
queryKey: ['channel-results', modelId],
queryFn: () =>
AnalogueModelsService.getApiAnalogueModelsResults(modelId as string),
ResultsService.getApiAnalogueModelsResultsChannel(modelId as string),
enabled: !!token,
});

Expand Down
Loading

0 comments on commit 4b7ac39

Please sign in to comment.