diff --git a/packages/dm-core-plugins/src/explorer/components/dialogs/NewEntityDialog.tsx b/packages/dm-core-plugins/src/explorer/components/dialogs/NewEntityDialog.tsx index 79ab35940..8818c395c 100644 --- a/packages/dm-core-plugins/src/explorer/components/dialogs/NewEntityDialog.tsx +++ b/packages/dm-core-plugins/src/explorer/components/dialogs/NewEntityDialog.tsx @@ -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' @@ -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 @@ -22,13 +25,15 @@ type TProps = { const NewEntityDialog = (props: TProps) => { const { setDialogId, node, setNodeOpen } = props - const [blueprint, setBlueprint] = useState('') + const [blueprintName, setBlueprintName] = useState('') + const [newName, setNewName] = useState(defaultName) const [loading, setLoading] = useState(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`) @@ -57,13 +62,24 @@ const NewEntityDialog = (props: TProps) => { + {blueprint?.attributes.filter( + (attr: TAttribute) => attr.name === 'name' + ) && ( + setNewName(e.target.value)} + label={'New name'} + helperText={'Optional'} + defaultValue={defaultName} + /> + )} -