From 83467b0534eeed2d816912daf1e1e7efd07e4cf6 Mon Sep 17 00:00:00 2001 From: "jean-philippe.blary" Date: Wed, 2 Aug 2023 09:37:51 +0200 Subject: [PATCH] fix(explore): don't put ? if no query parameters Signed-off-by: jean-philippe.blary --- .changeset/violet-dogs-breathe.md | 5 +++++ plugins/explore/src/api/ExploreClient.test.ts | 16 ++++++++++++++++ plugins/explore/src/api/ExploreClient.ts | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/violet-dogs-breathe.md diff --git a/.changeset/violet-dogs-breathe.md b/.changeset/violet-dogs-breathe.md new file mode 100644 index 0000000000..938c8df678 --- /dev/null +++ b/.changeset/violet-dogs-breathe.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-explore': patch +--- + +Don't put "?" in URL if no query parameters. diff --git a/plugins/explore/src/api/ExploreClient.test.ts b/plugins/explore/src/api/ExploreClient.test.ts index bbec568a09..77eb42ddf6 100644 --- a/plugins/explore/src/api/ExploreClient.test.ts +++ b/plugins/explore/src/api/ExploreClient.test.ts @@ -83,6 +83,22 @@ describe('ExploreClient', () => { }); expect(response).toEqual(expectedResponse); }); + + it('should request explore tools without filters', async () => { + const expectedResponse: GetExploreToolsResponse = { + tools: mockTools, + }; + + server.use( + rest.get(`${mockBaseUrl}/tools`, (req, res, ctx) => { + expect(req.url.search).toBe(''); + return res(ctx.json(expectedResponse)); + }), + ); + + const response = await client.getTools(); + expect(response).toEqual(expectedResponse); + }); }); describe('when using exploreToolsConfig for backwards compatibility', () => { diff --git a/plugins/explore/src/api/ExploreClient.ts b/plugins/explore/src/api/ExploreClient.ts index 9dca2755fe..4528200b43 100644 --- a/plugins/explore/src/api/ExploreClient.ts +++ b/plugins/explore/src/api/ExploreClient.ts @@ -71,7 +71,7 @@ export class ExploreClient implements ExploreApi { filter?.lifecycle?.map(l => `lifecycle=${encodeURIComponent(l)}`) ?? []; const query = [...tags, ...lifecycles].join('&'); - const response = await fetch(`${baseUrl}/tools?${query}`); + const response = await fetch(`${baseUrl}/tools${query ? `?${query}` : ''}`); if (!response.ok) { throw await ResponseError.fromResponse(response);