From ff523b12a0d3150f491cd4a74339029f70afcdd8 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Mon, 27 Sep 2021 10:38:04 +0200 Subject: [PATCH] SimpleList: Add support for custom url --- .../src/list/SimpleList.spec.tsx | 86 +++++++++++++++++++ .../ra-ui-materialui/src/list/SimpleList.tsx | 7 +- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/packages/ra-ui-materialui/src/list/SimpleList.spec.tsx b/packages/ra-ui-materialui/src/list/SimpleList.spec.tsx index 4eea79fabe3..b3bf28344f1 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList.spec.tsx +++ b/packages/ra-ui-materialui/src/list/SimpleList.spec.tsx @@ -49,4 +49,90 @@ describe('', () => { ).not.toBeNull(); }); }); + + it.each([ + [ + 'edit', + 'edit', + ['http://localhost/posts/1', 'http://localhost/posts/2'], + ], + [ + 'show', + 'show', + ['http://localhost/posts/1/show', 'http://localhost/posts/2/show'], + ], + [ + 'custom', + (record, id) => `/posts/${id}/custom`, + [ + 'http://localhost/posts/1/custom', + 'http://localhost/posts/2/custom', + ], + ], + ])( + 'should render %s links for each item', + async (_, link, expectedUrls) => { + const { getByText } = renderWithRouter( + + record.id.toString()} + secondaryText={} + /> + + ); + + await waitFor(() => { + expect(getByText('1').closest('a').href).toEqual( + expectedUrls[0] + ); + expect(getByText('2').closest('a').href).toEqual( + expectedUrls[1] + ); + }); + } + ); + + it('should not render links if linkType is false', async () => { + const { getByText } = renderWithRouter( + + record.id.toString()} + secondaryText={} + /> + + ); + + await waitFor(() => { + expect(getByText('1').closest('a')).toBeNull(); + expect(getByText('2').closest('a')).toBeNull(); + }); + }); }); diff --git a/packages/ra-ui-materialui/src/list/SimpleList.tsx b/packages/ra-ui-materialui/src/list/SimpleList.tsx index fea434a2ac8..df5d84b1ba8 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList.tsx +++ b/packages/ra-ui-materialui/src/list/SimpleList.tsx @@ -131,7 +131,8 @@ const SimpleList = ( record={data[id]} > { > {children} + ) : link !== false ? ( + + {children} + ) : ( {children} );