mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 18:27:25 +03:00
Improved how tags are exposed by the ApiClient when listing tags
This commit is contained in:
parent
67c674f073
commit
6fd30ed51a
4 changed files with 6 additions and 5 deletions
|
@ -61,14 +61,14 @@ export const listTags = (buildShlinkApiClient, force = true) => () => async (dis
|
|||
|
||||
try {
|
||||
const { listTags } = buildShlinkApiClient(getState);
|
||||
const { stats = [], data } = await listTags();
|
||||
const { tags, stats = [] } = await listTags();
|
||||
const processedStats = stats.reduce((acc, { tag, shortUrlsCount, visitsCount }) => {
|
||||
acc[tag] = { shortUrlsCount, visitsCount };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
dispatch({ tags: data, stats: processedStats, type: LIST_TAGS });
|
||||
dispatch({ tags, stats: processedStats, type: LIST_TAGS });
|
||||
} catch (e) {
|
||||
dispatch({ type: LIST_TAGS_ERROR });
|
||||
}
|
||||
|
|
|
@ -54,7 +54,8 @@ export default class ShlinkApiClient {
|
|||
|
||||
listTags = () =>
|
||||
this._performRequest('/tags', 'GET', { withStats: 'true' })
|
||||
.then((resp) => resp.data.tags);
|
||||
.then((resp) => resp.data.tags)
|
||||
.then(({ data, stats }) => ({ tags: data, stats }));
|
||||
|
||||
deleteTags = (tags) =>
|
||||
this._performRequest('/tags', 'DELETE', { tags })
|
||||
|
|
|
@ -103,7 +103,7 @@ describe('tagsListReducer', () => {
|
|||
it('dispatches loaded lists when no error occurs', async () => {
|
||||
const tags = [ 'foo', 'bar', 'baz' ];
|
||||
|
||||
listTagsMock.mockResolvedValue({ data: tags, stats: [] });
|
||||
listTagsMock.mockResolvedValue({ tags, stats: [] });
|
||||
buildShlinkApiClient.mockReturnValue({ listTags: listTagsMock });
|
||||
|
||||
await listTags(buildShlinkApiClient, true)()(dispatch, getState);
|
||||
|
|
|
@ -141,7 +141,7 @@ describe('ShlinkApiClient', () => {
|
|||
|
||||
const result = await listTags();
|
||||
|
||||
expect({ data: expectedTags }).toEqual(result);
|
||||
expect({ tags: expectedTags }).toEqual(result);
|
||||
expect(axiosSpy).toHaveBeenCalledWith(expect.objectContaining({ url: '/tags', method: 'GET' }));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue