diff --git a/src/components/AreaCoordinates/AreaCoordinates.styled.tsx b/src/components/AreaCoordinates/AreaCoordinates.styled.tsx new file mode 100644 index 00000000..8f5b4567 --- /dev/null +++ b/src/components/AreaCoordinates/AreaCoordinates.styled.tsx @@ -0,0 +1,41 @@ +import { Typography } from '@equinor/eds-core-react'; +import styled from 'styled-components'; +import { spacings } from '../../tokens/spacings'; + +export const SideSheet = styled.div` + display: flex; + flex-direction: column; + + row-gap: ${spacings.MEDIUM}; +`; +export const Form = styled.form` + display: flex; + flex-direction: column; + + row-gap: ${spacings.LARGE}; +`; + +export const CoordinateGroup = styled.div` + display: flex; + flex-direction: column; + + > .autocomplete-error { + > div { + > div { + border: solid 2px red; + } + } + } + + > .input-error { + > div { + > input { + border: solid 2px red; + } + } + } +`; + +export const ErrorMessage = styled(Typography)` + color: red; +`; diff --git a/src/components/AreaCoordinates/AreaCoordinates.tsx b/src/components/AreaCoordinates/AreaCoordinates.tsx new file mode 100644 index 00000000..39f15761 --- /dev/null +++ b/src/components/AreaCoordinates/AreaCoordinates.tsx @@ -0,0 +1,263 @@ +/* eslint-disable max-lines-per-function */ +import { + Autocomplete, + AutocompleteChanges, + Button, + Input, + Label, + Typography, +} from '@equinor/eds-core-react'; +import { useQuery } from '@tanstack/react-query'; +import { useEffect, useState } from 'react'; +import { AnalogueModelsService } from '../../api/generated/services/AnalogueModelsService'; +import optionTypes from '../../features/Compute/ComputeVariogram/CaseCard/CaseCard'; +import * as Styled from './AreaCoordinates.styled'; + +interface CoordinateType { + top: { + X?: string; + Y?: string; + }; + bottom: { + X?: string; + Y?: string; + }; +} + +type AreaErrorType = { + area?: string; + coordinateTop?: string; + coordinateBottom?: string; +}; +export const AreaCoordinates = ({ modelId }: { modelId: string }) => { + const [selectedArea, setSelectedArea] = useState(); + const [areaCoordinats, setAreaCoordinats] = useState({ + top: { + X: undefined, + Y: undefined, + }, + bottom: { + X: undefined, + Y: undefined, + }, + }); + const [errors, setErrors] = useState({}); + const [submitting, setSubmitting] = useState(false); + + const { data, isLoading } = useQuery({ + queryKey: ['analogue-models', modelId], + queryFn: () => AnalogueModelsService.getApiAnalogueModels1(modelId), + }); + + const modelAreas: optionTypes[] = [ + { id: 10, name: 'Proximal' }, + { id: 11, name: 'Left' }, + { id: 12, name: 'Distal' }, + ]; + + const validateValues = ( + selectedArea?: optionTypes, + areaCoordinats?: CoordinateType, + ) => { + const errors: AreaErrorType = {}; + if (selectedArea === undefined) { + errors.area = 'Area to define coordinates for not selected'; + } + + if ( + areaCoordinats?.top.X === undefined || + areaCoordinats?.top.Y === undefined || + areaCoordinats?.top.X.length < 1 || + areaCoordinats?.top.Y.length < 1 + ) { + errors.coordinateTop = 'Top coordinates not selected'; + } + + if ( + areaCoordinats?.bottom.X === undefined || + areaCoordinats?.bottom.Y === undefined || + areaCoordinats?.bottom.X.length < 1 || + areaCoordinats?.bottom.Y.length < 1 + ) { + errors.coordinateBottom = 'Bottom coordinates not selected'; + } + console.log(errors); + + return errors; + }; + + const finishSubmit = () => { + console.log(selectedArea); + console.log(areaCoordinats); + }; + + useEffect(() => { + if (Object.keys(errors).length === 0 && submitting) { + finishSubmit(); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [errors, submitting]); + + const saveChange = () => { + setErrors(validateValues(selectedArea, areaCoordinats)); + setSubmitting(true); + }; + + if (isLoading)

Loading.....

; + + return ( + + {data?.success && {data.data.name}} + Set coordinates: + + + Area to define + + option.name} + onOptionsChange={(changes: AutocompleteChanges) => + setSelectedArea(changes.selectedItems[0]) + } + > + + + + Top Left Corner +
+
+
+
+
+ + Bottom Right Corner +
+
+
+
+
+ {(errors.area || errors.coordinateBottom || errors.coordinateTop) && ( + + Highlighted fields required + + )} + +
+
+ ); +}; + +/** + * + * + * +const CoordinateSet = ({ + label, + position, + areaCoordinats, + setAreaCoordinats, +}: { + label: string; + position: { + X: string; + Y: string; + }; + areaCoordinats: CoordinateType; + setAreaCoordinats: (areaCoordinats: CoordinateType) => void; +}) => { + return ( +
+ {label} +
+
+
+
+
+ ); +}; + */ diff --git a/src/components/Table.tsx b/src/components/Table.tsx index 96508401..e447beb6 100644 --- a/src/components/Table.tsx +++ b/src/components/Table.tsx @@ -1,12 +1,16 @@ /* eslint-disable max-lines-per-function */ -import { Button, Chip } from '@equinor/eds-core-react'; +import { Button, Chip, Scrim, SideSheet } from '@equinor/eds-core-react'; import { EdsDataGrid } from '@equinor/eds-data-grid-react'; import { useQuery } from '@tanstack/react-query'; +import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { AnalogueModelsService } from '../api/generated'; +import { AreaCoordinates } from './AreaCoordinates/AreaCoordinates'; import * as Styled from './Table.styled'; export const Table = () => { + const [toggle, setToggle] = useState(false); + const [activeModel, setActiveModel] = useState(); const { isLoading, data } = useQuery({ queryKey: ['analogue-models'], queryFn: () => AnalogueModelsService.getApiAnalogueModels(), @@ -81,8 +85,30 @@ export const Table = () => { header: '', id: 'navigate', }, + { + accessorKey: 'areas', + cell: ({ row }) => ( + + ), + header: '', + id: 'areas', + }, ]} /> + {activeModel && ( + + setToggle(!toggle)}> + + + + )} ); };