Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added switch for approving object result #382

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/api/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export type { PrepareChunkedUploadDto } from './models/PrepareChunkedUploadDto';
export type { ProblemDetails } from './models/ProblemDetails';
export type { RadixJobDto } from './models/RadixJobDto';
export type { RegionDto } from './models/RegionDto';
export { ResultStatus } from './models/ResultStatus';
export type { StratColumnDto } from './models/StratColumnDto';
export type { StratigraphicGroupDto } from './models/StratigraphicGroupDto';
export type { StratUnitDto } from './models/StratUnitDto';
Expand All @@ -148,8 +149,14 @@ export type { UpdateJobStatusDto } from './models/UpdateJobStatusDto';
export type { UpdateObjectEstimationStatusCommand } from './models/UpdateObjectEstimationStatusCommand';
export type { UpdateObjectEstimationStatusCommandResponse } from './models/UpdateObjectEstimationStatusCommandResponse';
export type { UpdateObjectEstimationStatusDto } from './models/UpdateObjectEstimationStatusDto';
export type { UpdateObjectResultCommandBody } from './models/UpdateObjectResultCommandBody';
export type { UpdateObjectResultCommandResponse } from './models/UpdateObjectResultCommandResponse';
export type { UpdateObjectResultDto } from './models/UpdateObjectResultDto';
export type { UpdateThumbnailGenStatusCommand } from './models/UpdateThumbnailGenStatusCommand';
export type { UpdateVariogramEstimationStatusCommand } from './models/UpdateVariogramEstimationStatusCommand';
export type { UpdateVariogramResultCommandBody } from './models/UpdateVariogramResultCommandBody';
export type { UpdateVariogramResultCommandResponse } from './models/UpdateVariogramResultCommandResponse';
export type { UpdateVariogramResultDto } from './models/UpdateVariogramResultDto';
export type { UploadAnalogueModelCommandResponse } from './models/UploadAnalogueModelCommandResponse';
export type { UploadAnalogueModelDto } from './models/UploadAnalogueModelDto';
export type { UploadChunkCommandResponse } from './models/UploadChunkCommandResponse';
Expand Down
2 changes: 2 additions & 0 deletions src/api/generated/models/GetObjectResultsDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import type { CoordinateDto } from './CoordinateDto';
import type { GetObjectResultsFileDto } from './GetObjectResultsFileDto';
import type { ObjectEstimationResultDto } from './ObjectEstimationResultDto';
import type { ObjectHeightDto } from './ObjectHeightDto';
import type { ResultStatus } from './ResultStatus';

export type GetObjectResultsDto = {
objectResultId: string;
computeCaseId: string;
type: ComputeType;
status: ResultStatus;
objectResultFiles: Array<GetObjectResultsFileDto>;
segmentWidth: ObjectEstimationResultDto;
width: ObjectEstimationResultDto;
Expand Down
2 changes: 2 additions & 0 deletions src/api/generated/models/GetVariogramResultsDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import type { CoordinateDto } from './CoordinateDto';
import type { GetVariogramResultsVariogramResultFileDto } from './GetVariogramResultsVariogramResultFileDto';
import type { ResultStatus } from './ResultStatus';

export type GetVariogramResultsDto = {
computeCaseId: string;
variogramResultId: string;
identifier: number;
status: ResultStatus;
variogramResultFiles: Array<GetVariogramResultsVariogramResultFileDto>;
rmajor: number;
rminor: number;
Expand Down
9 changes: 9 additions & 0 deletions src/api/generated/models/ResultStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export enum ResultStatus {
DRAFT = 'Draft',
PUBLISH = 'Publish',
}
9 changes: 9 additions & 0 deletions src/api/generated/models/UpdateObjectResultCommandBody.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type UpdateObjectResultCommandBody = {
status: string;
};

15 changes: 15 additions & 0 deletions src/api/generated/models/UpdateObjectResultCommandResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { UpdateObjectResultDto } from './UpdateObjectResultDto';

export type UpdateObjectResultCommandResponse = {
success?: boolean;
count?: number | null;
message?: string | null;
validationErrors?: Array<string> | null;
data: UpdateObjectResultDto;
};

13 changes: 13 additions & 0 deletions src/api/generated/models/UpdateObjectResultDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { ResultStatus } from './ResultStatus';

export type UpdateObjectResultDto = {
analogueModelId: string;
objectResultId: string;
status: ResultStatus;
};

9 changes: 9 additions & 0 deletions src/api/generated/models/UpdateVariogramResultCommandBody.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type UpdateVariogramResultCommandBody = {
status: string;
};

15 changes: 15 additions & 0 deletions src/api/generated/models/UpdateVariogramResultCommandResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { UpdateVariogramResultDto } from './UpdateVariogramResultDto';

export type UpdateVariogramResultCommandResponse = {
success?: boolean;
count?: number | null;
message?: string | null;
validationErrors?: Array<string> | null;
data: UpdateVariogramResultDto;
};

13 changes: 13 additions & 0 deletions src/api/generated/models/UpdateVariogramResultDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { ResultStatus } from './ResultStatus';

export type UpdateVariogramResultDto = {
analogueModelId: string;
variogramResultId: string;
status: ResultStatus;
};

62 changes: 62 additions & 0 deletions src/api/generated/services/ResultsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
/* eslint-disable */
import type { GetObjectResultsByModelIdQueryResponse } from '../models/GetObjectResultsByModelIdQueryResponse';
import type { GetVariogramResultsByModelIdQueryResponse } from '../models/GetVariogramResultsByModelIdQueryResponse';
import type { UpdateObjectResultCommandBody } from '../models/UpdateObjectResultCommandBody';
import type { UpdateObjectResultCommandResponse } from '../models/UpdateObjectResultCommandResponse';
import type { UpdateVariogramResultCommandBody } from '../models/UpdateVariogramResultCommandBody';
import type { UpdateVariogramResultCommandResponse } from '../models/UpdateVariogramResultCommandResponse';

import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
Expand Down Expand Up @@ -55,4 +59,62 @@ export class ResultsService {
});
}

/**
* @param id
* @param objectId
* @param requestBody
* @returns UpdateObjectResultCommandResponse Success
* @throws ApiError
*/
public static putApiAnalogueModelsResultsObject(
id: string,
objectId: string,
requestBody?: UpdateObjectResultCommandBody,
): CancelablePromise<UpdateObjectResultCommandResponse> {
return __request(OpenAPI, {
method: 'PUT',
url: '/api/analogue-models/{id}/results/object/{objectId}',
path: {
'id': id,
'objectId': objectId,
},
body: requestBody,
mediaType: 'application/json-patch+json',
errors: {
400: `Bad Request`,
403: `Forbidden`,
404: `Not Found`,
},
});
}

/**
* @param id
* @param variogramId
* @param requestBody
* @returns UpdateVariogramResultCommandResponse Success
* @throws ApiError
*/
public static putApiAnalogueModelsResultsVariogram(
id: string,
variogramId: string,
requestBody?: UpdateVariogramResultCommandBody,
): CancelablePromise<UpdateVariogramResultCommandResponse> {
return __request(OpenAPI, {
method: 'PUT',
url: '/api/analogue-models/{id}/results/variogram/{variogramId}',
path: {
'id': id,
'variogramId': variogramId,
},
body: requestBody,
mediaType: 'application/json-patch+json',
errors: {
400: `Bad Request`,
403: `Forbidden`,
404: `Not Found`,
},
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ export const VerticalDivider = styled.div`
margin: 0 ${spacings.MEDIUM};
border: 0.5px solid #e0e0e0;
`;

export const CenterElements = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import {
Divider,
Icon,
Label,
Switch,
Typography,
} from '@equinor/eds-core-react';
import { bar_chart as barChart } from '@equinor/eds-icons';
import { useState } from 'react';
import { ChangeEvent, useState } from 'react';
import { GetObjectResultsDto } from '../../../../../../api/generated/models/GetObjectResultsDto';
import { ResultPlotDialog } from '../ResultPlotDialog/ResultPlotDialog';
import * as Styled from './ResultArea.styled';
import { ResultCaseMetadata } from './ResultCaseMetadata/ResultCaseMetadata';
import {
ResultStatus,
UpdateObjectResultCommandBody,
} from '../../../../../../api/generated';
import { usePepmContextStore } from '../../../../../../hooks/GlobalState';
import { useIsOwnerOrAdmin } from '../../../../../../hooks/useIsOwnerOrAdmin';
import { useMutateObjectResult } from '../../../../../../hooks/useMutateResults';
export const ResultArea = ({
computeMethod,
modelArea,
Expand All @@ -23,6 +31,23 @@ export const ResultArea = ({
data: GetObjectResultsDto;
}) => {
const [open, setOpen] = useState<boolean>(false);
const { analogueModel, updateObjectResult } = usePepmContextStore();
const isOwner = useIsOwnerOrAdmin();
const mutateObjectResult = useMutateObjectResult();

const putUpdateobject = async (status: ResultStatus) => {
const requestBody: UpdateObjectResultCommandBody = { status: status };

const objectUpdate = await mutateObjectResult.mutateAsync({
id: analogueModel.analogueModelId,
objectId: data.objectResultId,
requestBody: requestBody,
});

if (objectUpdate.success) {
updateObjectResult({ ...data, status: status });
}
};

const toggleOpen = () => {
setOpen(!open);
Expand All @@ -48,6 +73,19 @@ export const ResultArea = ({
if (x && y) return x * y + ' m^2';
};

const updateStatus = (checked: boolean) => {
if (checked) {
putUpdateobject(ResultStatus.PUBLISH);
} else {
putUpdateobject(ResultStatus.DRAFT);
}
};

const checkedStatus = () => {
if (data.status === ResultStatus.PUBLISH) return true;
return false;
};

return (
<>
<Styled.Wrapper>
Expand All @@ -56,10 +94,22 @@ export const ResultArea = ({
computeMethod={computeMethod}
modelArea={modelArea}
/>
<Button variant="outlined" onClick={toggleOpen}>
<Icon data={barChart} title={'Open plot for case results.'} />
Show plot
</Button>
<Styled.CenterElements>
<Button variant="outlined" onClick={toggleOpen}>
<Icon data={barChart} title={'Open plot for case results.'} />
Show plot
</Button>

<Label style={{ paddingTop: '0.5rem' }} label="Status"></Label>
<Switch
onChange={(e: ChangeEvent<HTMLInputElement>) => {
updateStatus(e.target.checked);
}}
checked={checkedStatus()}
label={data.status}
disabled={!isOwner}
></Switch>
</Styled.CenterElements>
</Styled.ResultHeader>

<Styled.Divider>
Expand Down
18 changes: 18 additions & 0 deletions src/hooks/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type IPepmContextActions = {
setComputeSettings: (computeSettings: ListComputeSettingsMethodDto[]) => void;
setObjectEstimationResults: (objectResults: GetObjectResultsDto[]) => void;
setVariogramResults: (variogramResults: GetVariogramResultsDto[]) => void;
updateObjectResult: (objectResult: GetObjectResultsDto) => void;
updateVariogramResult: (variogramResult: GetVariogramResultsDto) => void;
};

export const usePepmContextStore = create<IPepmContext & IPepmContextActions>()(
Expand Down Expand Up @@ -229,5 +231,21 @@ export const usePepmContextStore = create<IPepmContext & IPepmContextActions>()(
set((state) => {
state.variogramResults = variogramResults;
}),
updateObjectResult: (objectResult: GetObjectResultsDto) =>
set((state) => {
state.objectResults = state.objectResults.map((res) =>
res.objectResultId !== objectResult.objectResultId
? res
: objectResult,
);
}),
updateVariogramResult: (variogramResult: GetVariogramResultsDto) =>
set((state) => {
state.variogramResults = state.variogramResults.map((res) =>
res.variogramResultId !== variogramResult.variogramResultId
? res
: variogramResult,
);
}),
})),
);
Loading