Skip to content

Commit

Permalink
Open tagged resource in drawer if self contains tag/rev
Browse files Browse the repository at this point in the history
Signed-off-by: Dinika Saxena <[email protected]>
  • Loading branch information
Dinika committed Sep 17, 2024
1 parent dab565f commit 2545da8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
14 changes: 13 additions & 1 deletion src/shared/containers/DataTableContainer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ describe('DataTableContainer - Row Click', () => {
let component: RenderResult;
let nexus: ReturnType<typeof createNexusClient>;
let nexusSpy: jest.SpyInstance;
let historySpy: jest.SpyInstance;

beforeAll(() => {
server = setupServer(
Expand Down Expand Up @@ -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
Expand All @@ -504,6 +506,7 @@ describe('DataTableContainer - Row Click', () => {
queryClient.clear();
localStorage.clear();
nexusSpy.mockClear();
historySpy.mockClear();
});

afterAll(() => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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}`)];

Expand All @@ -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 () => {
Expand All @@ -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');
});
});

Expand Down
23 changes: 18 additions & 5 deletions src/shared/containers/DataTableContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,32 @@ const DataTableContainer: React.FC<DataTableProps> = ({
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(() => {
Expand Down

0 comments on commit 2545da8

Please sign in to comment.