diff --git a/src/api/generated/index.ts b/src/api/generated/index.ts index 9db69b7..c138e92 100644 --- a/src/api/generated/index.ts +++ b/src/api/generated/index.ts @@ -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'; @@ -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'; diff --git a/src/api/generated/models/GetObjectResultsDto.ts b/src/api/generated/models/GetObjectResultsDto.ts index adfdf08..c8a997b 100644 --- a/src/api/generated/models/GetObjectResultsDto.ts +++ b/src/api/generated/models/GetObjectResultsDto.ts @@ -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; segmentWidth: ObjectEstimationResultDto; width: ObjectEstimationResultDto; diff --git a/src/api/generated/models/GetVariogramResultsDto.ts b/src/api/generated/models/GetVariogramResultsDto.ts index 9504462..fbc74b6 100644 --- a/src/api/generated/models/GetVariogramResultsDto.ts +++ b/src/api/generated/models/GetVariogramResultsDto.ts @@ -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; rmajor: number; rminor: number; diff --git a/src/api/generated/models/ResultStatus.ts b/src/api/generated/models/ResultStatus.ts new file mode 100644 index 0000000..874d446 --- /dev/null +++ b/src/api/generated/models/ResultStatus.ts @@ -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', +} diff --git a/src/api/generated/models/UpdateObjectResultCommandBody.ts b/src/api/generated/models/UpdateObjectResultCommandBody.ts new file mode 100644 index 0000000..55c6695 --- /dev/null +++ b/src/api/generated/models/UpdateObjectResultCommandBody.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type UpdateObjectResultCommandBody = { + status: string; +}; + diff --git a/src/api/generated/models/UpdateObjectResultCommandResponse.ts b/src/api/generated/models/UpdateObjectResultCommandResponse.ts new file mode 100644 index 0000000..31215b9 --- /dev/null +++ b/src/api/generated/models/UpdateObjectResultCommandResponse.ts @@ -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 | null; + data: UpdateObjectResultDto; +}; + diff --git a/src/api/generated/models/UpdateObjectResultDto.ts b/src/api/generated/models/UpdateObjectResultDto.ts new file mode 100644 index 0000000..9ae4565 --- /dev/null +++ b/src/api/generated/models/UpdateObjectResultDto.ts @@ -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; +}; + diff --git a/src/api/generated/models/UpdateVariogramResultCommandBody.ts b/src/api/generated/models/UpdateVariogramResultCommandBody.ts new file mode 100644 index 0000000..76625b2 --- /dev/null +++ b/src/api/generated/models/UpdateVariogramResultCommandBody.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type UpdateVariogramResultCommandBody = { + status: string; +}; + diff --git a/src/api/generated/models/UpdateVariogramResultCommandResponse.ts b/src/api/generated/models/UpdateVariogramResultCommandResponse.ts new file mode 100644 index 0000000..b9e1269 --- /dev/null +++ b/src/api/generated/models/UpdateVariogramResultCommandResponse.ts @@ -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 | null; + data: UpdateVariogramResultDto; +}; + diff --git a/src/api/generated/models/UpdateVariogramResultDto.ts b/src/api/generated/models/UpdateVariogramResultDto.ts new file mode 100644 index 0000000..fb815c5 --- /dev/null +++ b/src/api/generated/models/UpdateVariogramResultDto.ts @@ -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; +}; + diff --git a/src/api/generated/services/ResultsService.ts b/src/api/generated/services/ResultsService.ts index 7a3e737..1c708bd 100644 --- a/src/api/generated/services/ResultsService.ts +++ b/src/api/generated/services/ResultsService.ts @@ -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'; @@ -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 { + 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 { + 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`, + }, + }); + } + } diff --git a/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.styled.ts b/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.styled.ts index 5042de6..2300cbf 100644 --- a/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.styled.ts +++ b/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.styled.ts @@ -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; +`; diff --git a/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.tsx b/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.tsx index c4a839c..c19e221 100644 --- a/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.tsx +++ b/src/features/Results/CaseResult/CaseResultView/ObjectCaseResult/ResultArea/ResultArea.tsx @@ -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, @@ -23,6 +31,23 @@ export const ResultArea = ({ data: GetObjectResultsDto; }) => { const [open, setOpen] = useState(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); @@ -48,6 +73,22 @@ export const ResultArea = ({ if (x && y) return x * y + ' m^2'; }; + const updateStatus = (checked: boolean) => { + if (checked) { + putUpdateobject(ResultStatus.PUBLISH); + // updateObjectResult({ ...data, status: ResultStatus.PUBLISH }); + } else { + putUpdateobject(ResultStatus.DRAFT); + + // updateObjectResult({ ...data, status: ResultStatus.DRAFT }); + } + }; + + const checkedStatus = () => { + if (data.status === ResultStatus.PUBLISH) return true; + return false; + }; + return ( <> @@ -56,10 +97,22 @@ export const ResultArea = ({ computeMethod={computeMethod} modelArea={modelArea} /> - + + + + + ) => { + updateStatus(e.target.checked); + }} + checked={checkedStatus()} + label={data.status} + disabled={!isOwner} + > + diff --git a/src/hooks/GlobalState.tsx b/src/hooks/GlobalState.tsx index 260eb4e..d0f71cd 100644 --- a/src/hooks/GlobalState.tsx +++ b/src/hooks/GlobalState.tsx @@ -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()( @@ -229,5 +231,21 @@ export const usePepmContextStore = create()( 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, + ); + }), })), ); diff --git a/src/hooks/useMutateResults.ts b/src/hooks/useMutateResults.ts new file mode 100644 index 0000000..478d3de --- /dev/null +++ b/src/hooks/useMutateResults.ts @@ -0,0 +1,57 @@ +import { useMutation } from '@tanstack/react-query'; +import { + ResultsService, + UpdateObjectResultCommandBody, + UpdateVariogramResultCommandBody, +} from '../api/generated'; +import { queryClient } from '../auth/queryClient'; + +export const useMutateObjectResult = () => { + const putObjectResult = useMutation({ + mutationFn: ({ + id, + objectId, + requestBody, + }: { + id: string; + objectId: string; + requestBody: UpdateObjectResultCommandBody; + }) => { + return ResultsService.putApiAnalogueModelsResultsObject( + id, + objectId, + requestBody, + ); + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['object-result'] }); + }, + }); + + return putObjectResult; +}; + +export const useMutateVariogramResult = () => { + const putVariogramResult = useMutation({ + mutationFn: ({ + id, + variogramId, + requestBody, + }: { + id: string; + variogramId: string; + requestBody: UpdateVariogramResultCommandBody; + }) => { + return ResultsService.putApiAnalogueModelsResultsVariogram( + id, + variogramId, + requestBody, + ); + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['variogram-result'] }); + }, + }); + + return putVariogramResult; +};