Skip to content

Commit

Permalink
feat: name in new entity picker
Browse files Browse the repository at this point in the history
  • Loading branch information
collinlokken committed Jan 9, 2024
1 parent 3221c14 commit 1870420
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
BlueprintPicker,
Dialog,
ErrorResponse,
TAttribute,
TreeNode,
useBlueprint,
} from '@development-framework/dm-core'
import { Button, Progress } from '@equinor/eds-core-react'
import { Button, Progress, TextField } from '@equinor/eds-core-react'
import { AxiosError } from 'axios'
import React, { useState } from 'react'
import { toast } from 'react-toastify'
Expand All @@ -14,6 +16,7 @@ import {
STANDARD_DIALOG_WIDTH,
} from '../context-menu/NodeRightClickMenu'

const defaultName = 'new_entity'
type TProps = {
setDialogId: (id: EDialog | undefined) => void
node: TreeNode
Expand All @@ -22,13 +25,15 @@ type TProps = {

const NewEntityDialog = (props: TProps) => {
const { setDialogId, node, setNodeOpen } = props
const [blueprint, setBlueprint] = useState<string>('')
const [blueprintName, setBlueprintName] = useState<string>('')
const [newName, setNewName] = useState<string>(defaultName)
const [loading, setLoading] = useState<boolean>(false)
const { blueprint } = useBlueprint(blueprintName)

const handleCreate = () => {
setLoading(true)
node
.appendEntity(`dmss://${blueprint}`, 'new_entity')
.appendEntity(`dmss://${blueprintName}`, newName ?? defaultName)
.then(() => {
setNodeOpen(true)
toast.success(`Entity is created`)
Expand Down Expand Up @@ -57,13 +62,24 @@ const NewEntityDialog = (props: TProps) => {
<Dialog.CustomContent>
<BlueprintPicker
label='Blueprint'
onChange={setBlueprint}
formData={blueprint}
onChange={setBlueprintName}
formData={blueprintName}
fieldType={'input-field'}
/>
{blueprint?.attributes.filter(
(attr: TAttribute) => attr.name === 'name'
) && (
<TextField
id={'entity-name'}
onChange={(e: any) => setNewName(e.target.value)}
label={'New name'}
helperText={'Optional'}
defaultValue={defaultName}
/>
)}
</Dialog.CustomContent>
<Dialog.Actions>
<Button disabled={blueprint === ''} onClick={handleCreate}>
<Button disabled={blueprintName === ''} onClick={handleCreate}>
{loading ? <Progress.Dots /> : 'Create'}
</Button>
<Button variant='outlined' onClick={() => setDialogId(undefined)}>
Expand Down

0 comments on commit 1870420

Please sign in to comment.