Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load resource with tag/revision if it exists in self #1546

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/shared/containers/DataTableContainer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,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 @@ -485,6 +486,7 @@ describe('DataTableContainer - Row Click', () => {
? Promise.resolve([getMockResource('doesnt-matter', {}, 'agents')])
: Promise.resolve(getMockResource('doesnt-matter', {}, 'agents'))
);
historySpy = jest.spyOn(history, 'push');
});

// reset any request handlers that are declared as a part of our tests
Expand All @@ -494,6 +496,7 @@ describe('DataTableContainer - Row Click', () => {
queryClient.clear();
localStorage.clear();
nexusSpy.mockClear();
historySpy.mockClear();
});

afterAll(() => {
Expand Down Expand Up @@ -529,6 +532,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 @@ -547,11 +552,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 @@ -565,6 +572,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 @@ -585,6 +594,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(error => {
Expand Down
Loading