From 65d41bd5f3f72525841b210592408f7f4c70ef19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Collin=20L=C3=B8kken?= Date: Tue, 9 Jan 2024 16:53:45 +0100 Subject: [PATCH] feat: name in new entity picker --- e2e/tests/plugin-explorer.spec.ts | 5 +- .../components/dialogs/NewEntityDialog.tsx | 52 ++++++++++++++++--- packages/dm-core/src/domain/Tree.ts | 2 +- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/e2e/tests/plugin-explorer.spec.ts b/e2e/tests/plugin-explorer.spec.ts index dbbe62cae..b07a9c116 100644 --- a/e2e/tests/plugin-explorer.spec.ts +++ b/e2e/tests/plugin-explorer.spec.ts @@ -40,7 +40,7 @@ test('Create blueprint', async ({ page }) => { ).toBeVisible() }) -test('Create entity', async ({ page }) => { +test('Create entity with name', async ({ page }) => { await page .getByRole('button', { name: 'package Playwright', exact: true }) .click({ button: 'right' }) @@ -52,11 +52,12 @@ test('Create entity', async ({ page }) => { await dialog.getByRole('button', { name: 'plugins' }).click() await dialog.getByRole('button', { name: 'Playwright' }).click() await dialog.getByRole('button', { name: 'PlaywrightBlueprint' }).click() + await dialog.getByLabel('Name').fill('PlaywrightEntity') await dialog.getByRole('button', { name: 'Create' }).click() await expect(page.getByRole('alert')).toHaveText(['Entity is created']) await expect(dialog).not.toBeVisible() await expect( - page.getByRole('button', { name: 'file new_entity' }) + page.getByRole('button', { name: 'file PlaywrightEntity' }) ).toBeVisible() }) 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..d7551bf55 100644 --- a/packages/dm-core-plugins/src/explorer/components/dialogs/NewEntityDialog.tsx +++ b/packages/dm-core-plugins/src/explorer/components/dialogs/NewEntityDialog.tsx @@ -1,12 +1,16 @@ import { + ApplicationContext, BlueprintPicker, Dialog, ErrorResponse, + TAttribute, + TBlueprint, TreeNode, + useDMSS, } 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 React, { useContext, useEffect, useState } from 'react' import { toast } from 'react-toastify' import { EDialog } from '../../types' import { @@ -22,13 +26,33 @@ type TProps = { const NewEntityDialog = (props: TProps) => { const { setDialogId, node, setNodeOpen } = props - const [blueprint, setBlueprint] = useState('') + const [blueprintName, setBlueprintName] = useState('') + const [blueprint, setBlueprint] = useState() + const [newName, setNewName] = useState('') const [loading, setLoading] = useState(false) + const dmssAPI = useDMSS() + const { name } = useContext(ApplicationContext) + + useEffect(() => { + if (!blueprintName) return + dmssAPI + .blueprintGet({ typeRef: blueprintName, context: name }) + .then((response: any) => { + setBlueprint(response.data.blueprint) + }) + }, [blueprintName]) + + const nameField: TAttribute | undefined = blueprint?.attributes.find( + (attr: TAttribute) => attr.name === 'name' + ) const handleCreate = () => { setLoading(true) node - .appendEntity(`dmss://${blueprint}`, 'new_entity') + .appendEntity( + `dmss://${blueprintName}`, + newName.length > 0 ? newName : undefined + ) .then(() => { setNodeOpen(true) toast.success(`Entity is created`) @@ -57,13 +81,27 @@ const NewEntityDialog = (props: TProps) => { + {nameField && ( + setNewName(e.target.value)} + label={'Name'} + helperText={nameField.optional ? 'Optional' : 'Required'} + /> + )} -