-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
558 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/features/AddModel/AddModelDialog/AddModelDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* eslint-disable max-lines-per-function */ | ||
import { Button, Typography } from '@equinor/eds-core-react'; | ||
import { useEffect, useState } from 'react'; | ||
import { ModelInputFilesTable } from '../ModelInputFilesTable/ModelInputFilesTable'; | ||
import { ModelMetadata } from '../ModelMetadata/ModelMetadata'; | ||
import * as Styled from './AddModelDialog.styled'; | ||
|
||
interface AddModelDialogProps { | ||
isOpen: boolean; | ||
confirm: (file: File) => Promise<void>; | ||
cancel: () => void; | ||
} | ||
|
||
export default interface MetadataProps { | ||
description?: string; | ||
field: string[]; | ||
zone?: string[]; | ||
formation: string[]; | ||
analogue?: string[]; | ||
} | ||
|
||
export type ErrorType = { | ||
field?: string; | ||
formation?: string; | ||
file?: string; | ||
}; | ||
export const AddModelDialog = ({ | ||
isOpen, | ||
confirm, | ||
cancel, | ||
}: AddModelDialogProps) => { | ||
const [isFileDisplay, setFileDisplay] = useState<boolean>(false); | ||
const [files, setFiles] = useState<{ NC?: File; INI?: File }>({ | ||
NC: undefined, | ||
INI: undefined, | ||
}); | ||
const [metadata, setMetadata] = useState<Partial<MetadataProps>>(); | ||
const [errors, setErrors] = useState({}); | ||
const [submitting, setSubmitting] = useState(false); | ||
|
||
function toggleINIFileContent() { | ||
setFileDisplay(!isFileDisplay); | ||
} | ||
|
||
const INIFileContent = () => <p>Not implemented yet...</p>; | ||
|
||
const validateValues = (inputValues: Partial<MetadataProps> | undefined) => { | ||
const errors: ErrorType = {}; | ||
if (inputValues?.field === undefined || inputValues?.field?.length === 0) { | ||
errors.field = 'Field not selected'; | ||
} | ||
|
||
if ( | ||
inputValues?.formation === undefined || | ||
inputValues?.formation?.length === 0 | ||
) { | ||
errors.formation = 'Formation not selected'; | ||
} | ||
|
||
if (!files.NC) { | ||
errors.file = 'NC file missing'; | ||
} | ||
return errors; | ||
}; | ||
|
||
const handleSubmit = () => { | ||
setErrors(validateValues(metadata)); | ||
setSubmitting(true); | ||
}; | ||
|
||
const finishSubmit = () => { | ||
if (files.NC) confirm(files.NC); | ||
}; | ||
|
||
useEffect(() => { | ||
if (Object.keys(errors).length === 0 && submitting) { | ||
finishSubmit(); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [errors, submitting]); | ||
|
||
return ( | ||
<Styled.Dialog open={isOpen}> | ||
<Styled.Dialog.Header> | ||
<Styled.Dialog.Title>Add new model</Styled.Dialog.Title> | ||
</Styled.Dialog.Header> | ||
<Styled.DialogCustomContent scrollable> | ||
<ModelInputFilesTable | ||
files={files} | ||
setFiles={setFiles} | ||
fileDisplay={{ | ||
isVisible: isFileDisplay, | ||
toggle: toggleINIFileContent, | ||
}} | ||
/> | ||
{isFileDisplay && <INIFileContent />} | ||
<ModelMetadata | ||
errors={errors} | ||
metadata={metadata} | ||
setMetadata={setMetadata} | ||
/> | ||
{Object.keys(errors).includes('file') && ( | ||
<Typography className="error">NC file missing</Typography> | ||
)} | ||
</Styled.DialogCustomContent> | ||
<Styled.DialogActions> | ||
<Button onClick={handleSubmit}>Confirm and start uploading</Button> | ||
<Button variant="outlined" onClick={cancel}> | ||
Cancel | ||
</Button> | ||
</Styled.DialogActions> | ||
</Styled.Dialog> | ||
); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...tures/FileUploader/FileUploader.styled.ts → ...Model/FileUploader/FileUploader.styled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/features/FileUploader/FileUploader.tsx → ...es/AddModel/FileUploader/FileUploader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lInputFilesTable/ModelInputFilesTable.tsx → ...lInputFilesTable/ModelInputFilesTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/features/AddModel/ModelMetadata/ModelMetadata.styled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TextField } from '@equinor/eds-core-react'; | ||
import styled from 'styled-components'; | ||
import { spacings } from '../../../tokens/spacings'; | ||
export const ModelMetadata = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: ${spacings.MEDIUM}; | ||
`; | ||
|
||
export const Form = styled.form` | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: ${spacings.MEDIUM}; | ||
`; | ||
|
||
export const AutocompleteWrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: ${spacings.MEDIUM}; | ||
`; | ||
export const AutocompleteRow = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
flex: end; | ||
column-gap: ${spacings.MEDIUM}; | ||
> div { | ||
flex-grow: 1; | ||
} | ||
`; | ||
|
||
export const TextInput = styled(TextField)` | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
export const Required = styled.div` | ||
> label { | ||
color: red; | ||
} | ||
> .model-required { | ||
> div { | ||
> div { | ||
border: solid 2px red; | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* eslint-disable max-lines-per-function */ | ||
import { | ||
Autocomplete, | ||
AutocompleteChanges, | ||
Label, | ||
Typography, | ||
} from '@equinor/eds-core-react'; | ||
import MetadataProps, { ErrorType } from '../AddModelDialog/AddModelDialog'; | ||
|
||
import * as Styled from './ModelMetadata.styled'; | ||
|
||
export const ModelMetadata = ({ | ||
errors, | ||
metadata, | ||
setMetadata, | ||
}: { | ||
errors: ErrorType; | ||
metadata: Partial<MetadataProps> | undefined; | ||
setMetadata: (metadata: Partial<MetadataProps>) => void; | ||
}) => { | ||
const fields = { | ||
description: 'Description string', | ||
field: ['Tor', 'Pål'], | ||
zone: ['Zone 1', 'Zone 2', 'Zone 3'], | ||
formation: ['Rocky', 'Hilly', 'Flat'], | ||
analogue: ['Analouge1', 'Analouge2'], | ||
}; | ||
|
||
const handleInput = (e: AutocompleteChanges<string>, target: string) => { | ||
setMetadata({ ...metadata, [target]: e.selectedItems }); | ||
}; | ||
|
||
return ( | ||
<Styled.ModelMetadata className="model-metadata"> | ||
<Typography variant="h4">Description and metadata</Typography> | ||
<Styled.Form> | ||
<Styled.TextInput | ||
id="model-description" | ||
label="Model description (optional)" | ||
value={metadata?.description} | ||
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => | ||
setMetadata({ ...metadata, description: e.currentTarget.value }) | ||
} | ||
multiline | ||
rows={4} | ||
rowsMax={8} | ||
/> | ||
<Styled.AutocompleteWrapper> | ||
<Styled.AutocompleteRow> | ||
<Styled.Required> | ||
<Autocomplete | ||
className={`${errors.field && 'model-required'}`} | ||
label="Field" | ||
options={fields.field} | ||
onOptionsChange={(e: AutocompleteChanges<string>) => | ||
handleInput(e, 'field') | ||
} | ||
></Autocomplete> | ||
{errors.field && <Label label="This field is required"></Label>} | ||
</Styled.Required> | ||
<Styled.Required> | ||
<Autocomplete | ||
className={`${errors.formation && 'model-required'}`} | ||
label="Formation" | ||
options={fields.formation} | ||
multiple | ||
onOptionsChange={(e: AutocompleteChanges<string>) => | ||
handleInput(e, 'formation') | ||
} | ||
></Autocomplete> | ||
{errors.formation && ( | ||
<Label label="This field is required"></Label> | ||
)} | ||
</Styled.Required> | ||
</Styled.AutocompleteRow> | ||
<Styled.AutocompleteRow> | ||
<Autocomplete | ||
label="Analogue (optional)" | ||
options={fields.analogue} | ||
multiple | ||
onOptionsChange={(e: AutocompleteChanges<string>) => | ||
setMetadata({ ...metadata, analogue: e.selectedItems }) | ||
} | ||
></Autocomplete> | ||
<Autocomplete | ||
label="Zone (optional)" | ||
options={fields.zone} | ||
onOptionsChange={(e: AutocompleteChanges<string>) => | ||
setMetadata({ ...metadata, zone: e.selectedItems }) | ||
} | ||
></Autocomplete> | ||
</Styled.AutocompleteRow> | ||
</Styled.AutocompleteWrapper> | ||
</Styled.Form> | ||
</Styled.ModelMetadata> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.