From 2545da8fce35e310f12787ca7abce1e02781700c Mon Sep 17 00:00:00 2001 From: Dinika Saxena Date: Tue, 17 Sep 2024 16:47:12 +0200 Subject: [PATCH] Open tagged resource in drawer if self contains tag/rev Signed-off-by: Dinika Saxena --- .github/workflows/review.yml | 4 ++-- .../containers/DataTableContainer.spec.tsx | 14 ++++++++++- src/shared/containers/DataTableContainer.tsx | 23 +++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml index 98554f80b..67de1e4fd 100644 --- a/.github/workflows/review.yml +++ b/.github/workflows/review.yml @@ -145,7 +145,7 @@ jobs: run: docker build . --tag=nexus-web:fresh - name: Start services - run: docker-compose -f ci/docker-compose.yml up -d && sleep 60 + run: docker compose -f ci/docker-compose.yml up -d && sleep 60 - name: Copy nexus-web into Cypress container run: docker cp ./. cypress:/e2e @@ -165,4 +165,4 @@ jobs: - name: Cleanup Docker Containers if: ${{ always() }} - run: docker-compose -f ci/docker-compose.yml down --rmi "local" --volumes + run: docker compose -f ci/docker-compose.yml down --rmi "local" --volumes diff --git a/src/shared/containers/DataTableContainer.spec.tsx b/src/shared/containers/DataTableContainer.spec.tsx index 2275ab980..09c01617b 100644 --- a/src/shared/containers/DataTableContainer.spec.tsx +++ b/src/shared/containers/DataTableContainer.spec.tsx @@ -442,6 +442,7 @@ describe('DataTableContainer - Row Click', () => { let component: RenderResult; let nexus: ReturnType; let nexusSpy: jest.SpyInstance; + let historySpy: jest.SpyInstance; beforeAll(() => { server = setupServer( @@ -495,6 +496,7 @@ describe('DataTableContainer - Row Click', () => { ? Promise.resolve([getMockResource('doesnt-matter', {}, 'agents')]) : Promise.resolve(getMockResource('doesnt-matter', {}, 'agents')) ); + historySpy = vitest.spyOn(history, 'push'); }); // reset any request handlers that are declared as a part of our tests @@ -504,6 +506,7 @@ describe('DataTableContainer - Row Click', () => { queryClient.clear(); localStorage.clear(); nexusSpy.mockClear(); + historySpy.mockClear(); }); afterAll(() => { @@ -538,6 +541,8 @@ describe('DataTableContainer - Row Click', () => { path: `${selfWithRevision}&format=expanded`, headers: { Accept: 'application/json' }, }); + const navigateTo = historySpy.mock.calls[0][0]; + expect(navigateTo).toContain('rev=30'); }); it('requests correct resource from delta when user clicks on row with tag in self', async () => { @@ -555,11 +560,13 @@ describe('DataTableContainer - Row Click', () => { path: `${selfWithTag}&format=expanded`, headers: { Accept: 'application/json' }, }); + const navigateTo = historySpy.mock.calls[0][0]; + expect(navigateTo).toContain('tag=30'); }); it('requests correct resource from delta when user clicks on row with tag and revision in self', async () => { const selfWithTagAndRev = - 'https://localhost:3000/resources/bbp/agents/_/persons%2Fc3358e61-7650-4954-99b7-f7572cbf5d5g?tag=30&rev=2-'; + 'https://localhost:3000/resources/bbp/agents/_/persons%2Fc3358e61-7650-4954-99b7-f7572cbf5d5g?tag=30&rev=20'; const resources = [getMockStudioResource('Malory', `${selfWithTagAndRev}`)]; @@ -572,6 +579,8 @@ describe('DataTableContainer - Row Click', () => { path: `${selfWithTagAndRev}&format=expanded`, headers: { Accept: 'application/json' }, }); + const navigateTo = historySpy.mock.calls[0][0]; + expect(navigateTo).toContain('rev=20'); }); it('requests correct resource from delta when user clicks on row with no tag or revision in self', async () => { @@ -591,6 +600,9 @@ describe('DataTableContainer - Row Click', () => { path: `${selfWithoutTagOrRev}?format=expanded`, headers: { Accept: 'application/json' }, }); + const navigateTo = historySpy.mock.calls[0][0]; + expect(navigateTo).not.toContain('rev'); + expect(navigateTo).not.toContain('tag'); }); }); diff --git a/src/shared/containers/DataTableContainer.tsx b/src/shared/containers/DataTableContainer.tsx index 4dc1c58b4..83b899a59 100644 --- a/src/shared/containers/DataTableContainer.tsx +++ b/src/shared/containers/DataTableContainer.tsx @@ -219,19 +219,32 @@ const DataTableContainer: React.FC = ({ if (resource['@type'] === 'Project') { return; } - const url = new URL(selfUrl); - url.searchParams.set('format', 'expanded'); + const resourceUrl = new URL(selfUrl); + resourceUrl.searchParams.set('format', 'expanded'); + nexus .httpGet({ - path: `${url.toString()}`, + path: `${resourceUrl.toString()}`, headers: { Accept: 'application/json' }, }) .then((fullIdResponse: Resource) => { const [orgLabel, projectLabel] = parseProjectUrl(resource._project); - const hist = `/${orgLabel}/${projectLabel}/resources/${encodeURIComponent( + let fullResourceId = `/${orgLabel}/${projectLabel}/resources/${encodeURIComponent( fullIdResponse[0]['@id'] )}`; - history.push(hist, { background: location }); + + const revision = resourceUrl.searchParams.get('rev'); + const tag = resourceUrl.searchParams.get('tag'); + + if (revision) { + fullResourceId = `${fullResourceId}?rev=${revision}`; + } else if (tag) { + fullResourceId = `${fullResourceId}?tag=${tag}`; + } + + history.push(`${fullResourceId.toString()}`, { + background: location, + }); }); }) .catch(() => {