This is an automated email from the ASF dual-hosted git repository. pawarprasad123 pushed a commit to branch atlas-2.6 in repository https://gitbox.apache.org/repos/asf/atlas.git
commit 55b291b2e72f57f3fd08a2ef1627af3fa0513552 Author: Brijesh Bhalala <[email protected]> AuthorDate: Wed Jul 15 17:58:02 2026 +0530 ATLAS-5339: Atlas React UI: Clicking Create Entity while on an Entity Detail Page opens the Edit Form instead of Create Form (#693) ( cherry -picked from the commit 9df46eb180eeeac5992909bd2d5257fb5acf0b70) * ATLAS-5339: Atlas React UI: Clicking Create Entity while on an Entity Detail Page opens the Edit Form instead of Create Form * ATLAS-5339: Atlas React UI: Clicking Create Entity while on an Entity Detail Page opens the Edit Form instead of Create Form --- .../components/CreateDropdown/CreateDropdown.tsx | 1 + .../__tests__/CreateDropdown.test.tsx | 5 ++- dashboard/src/views/Entity/EntityForm.tsx | 7 +++- dashboard/src/views/__tests__/EntityForm.test.tsx | 48 ++++++++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/dashboard/src/components/CreateDropdown/CreateDropdown.tsx b/dashboard/src/components/CreateDropdown/CreateDropdown.tsx index cb32d4e2a..81658bd0d 100644 --- a/dashboard/src/components/CreateDropdown/CreateDropdown.tsx +++ b/dashboard/src/components/CreateDropdown/CreateDropdown.tsx @@ -152,6 +152,7 @@ const CreateDropdown = () => { <EntityForm open={entityModal} onClose={() => setEntityModal(false)} + isAdd={true} /> )} {classificationModal && ( diff --git a/dashboard/src/components/CreateDropdown/__tests__/CreateDropdown.test.tsx b/dashboard/src/components/CreateDropdown/__tests__/CreateDropdown.test.tsx index fff608e37..7eed8279e 100644 --- a/dashboard/src/components/CreateDropdown/__tests__/CreateDropdown.test.tsx +++ b/dashboard/src/components/CreateDropdown/__tests__/CreateDropdown.test.tsx @@ -29,9 +29,9 @@ jest.mock('react-router-dom', () => ({ jest.mock('@views/Entity/EntityForm', () => ({ __esModule: true, - default: ({ open, onClose }: { open: boolean; onClose: () => void }) => + default: ({ open, onClose, isAdd }: { open: boolean; onClose: () => void; isAdd?: boolean }) => open ? ( - <div data-testid="entity-form"> + <div data-testid="entity-form" data-isadd={isAdd ? 'true' : 'false'}> <button type="button" onClick={onClose}> Close entity </button> @@ -84,6 +84,7 @@ describe('CreateDropdown (header Create menu)', () => { fireEvent.click(screen.getByText('Entity')) expect(await screen.findByTestId('entity-form')).toBeInTheDocument() + expect(screen.getByTestId('entity-form')).toHaveAttribute('data-isadd', 'true') fireEvent.click(screen.getByText('Close entity')) await waitFor(() => { diff --git a/dashboard/src/views/Entity/EntityForm.tsx b/dashboard/src/views/Entity/EntityForm.tsx index 4cc40497f..d933b0ec1 100644 --- a/dashboard/src/views/Entity/EntityForm.tsx +++ b/dashboard/src/views/Entity/EntityForm.tsx @@ -78,15 +78,18 @@ export function reducer(state: State, action: Action): State { const EntityForm = ({ open, - onClose + onClose, + isAdd = false }: { open: boolean; onClose: () => void; + isAdd?: boolean; }) => { const key = "atlas.ui.editable.entity.types"; const dispatchApi = useAppDispatch(); const navigate = useNavigate(); - const { guid }: any = useParams(); + const { guid: urlGuid }: any = useParams(); + const guid = isAdd ? undefined : urlGuid; const [_searchParams, setSearchParams] = useSearchParams(); const { entityData = {} }: any = useAppSelector((state: any) => state.entity); diff --git a/dashboard/src/views/__tests__/EntityForm.test.tsx b/dashboard/src/views/__tests__/EntityForm.test.tsx index 048de96bf..63d336faf 100644 --- a/dashboard/src/views/__tests__/EntityForm.test.tsx +++ b/dashboard/src/views/__tests__/EntityForm.test.tsx @@ -266,6 +266,54 @@ describe('EntityForm - 100% Coverage', () => { expect(screen.getByTestId('modal-title')).toHaveTextContent('Create entity'); }); + test('opens in Create mode when isAdd=true even if URL has guid', async () => { + mockGuid = 'detail-page-guid-123'; + const store = createStore(mockEntityData, mockSessionData, mockTypeHeaderData); + render( + <Provider store={store}> + <MemoryRouter initialEntries={['/detailPage/detail-page-guid-123']}> + <EntityForm open={true} onClose={jest.fn()} isAdd={true} /> + </MemoryRouter> + </Provider> + ); + expect(screen.getByTestId('modal-title')).toHaveTextContent('Create entity'); + expect(mockGetEntity).not.toHaveBeenCalled(); + }); + + test('opens in Edit mode when isAdd=false and URL has guid (ensures edit behavior is unchanged)', async () => { + mockGuid = 'detail-page-guid-123'; + + // Mock successful API response for Edit mode + mockGetEntity.mockResolvedValue({ + data: { + entity: { + guid: 'detail-page-guid-123', + typeName: 'DataSet', + attributes: { name: 'Test Entity' } + } + } + }); + mockGetTypedef.mockResolvedValue({ + data: { attributeDefs: [], relationshipAttributeDefs: [] } + }); + + const store = createStore(mockEntityData, mockSessionData, mockTypeHeaderData); + render( + <Provider store={store}> + <MemoryRouter initialEntries={['/detailPage/detail-page-guid-123']}> + <EntityForm open={true} onClose={jest.fn()} isAdd={false} /> + </MemoryRouter> + </Provider> + ); + + await waitFor(() => { + expect(mockGetEntity).toHaveBeenCalledWith('detail-page-guid-123', 'GET', {}); + }); + await waitFor(() => { + expect(screen.getByTestId('modal-title')).toHaveTextContent('Edit entity'); + }); + }); + test('does not render when open is false', () => { const store = createStore(mockEntityData, mockSessionData, mockTypeHeaderData); render(
