diff --git a/CHANGELOG.md b/CHANGELOG.md index ce8b0a99..f389d803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org). -## [Unreleased] +## [3.5.1] - 2022-01-08 ### Added * *Nothing* @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed * [#555](https://github.com/shlinkio/shlink-web-client/issues/555) Fixed vertical alignment in welcome screen logo. * [#554](https://github.com/shlinkio/shlink-web-client/issues/554) Fixed behavior in overview page, where items in the list of short URLs were stripped out when creating new ones, even if the amount of short URLs was still not yet big enough. +* [#557](https://github.com/shlinkio/shlink-web-client/issues/557) Fixed new tags added to new short URLs, not appearing on tags autosuggest. ## [3.5.0] - 2022-01-01 diff --git a/src/tags/reducers/tagsList.ts b/src/tags/reducers/tagsList.ts index 5859f818..fafbd339 100644 --- a/src/tags/reducers/tagsList.ts +++ b/src/tags/reducers/tagsList.ts @@ -9,6 +9,7 @@ import { CreateVisit, Stats } from '../../visits/types'; import { parseApiError } from '../../api/utils'; import { TagStats } from '../data'; import { ApiErrorAction } from '../../api/types/actions'; +import { CREATE_SHORT_URL, CreateShortUrlAction } from '../../short-urls/reducers/shortUrlCreation'; import { DeleteTagAction, TAG_DELETED } from './tagDelete'; import { EditTagAction, TAG_EDITED } from './tagEdit'; @@ -42,6 +43,7 @@ interface FilterTagsAction extends Action { type TagsCombinedAction = ListTagsAction & DeleteTagAction & CreateVisitsAction +& CreateShortUrlAction & EditTagAction & FilterTagsAction & ApiErrorAction; @@ -102,6 +104,10 @@ export default buildReducer({ ...state, stats: increaseVisitsForTags(calculateVisitsPerTag(createdVisits), state.stats), }), + [CREATE_SHORT_URL]: ({ tags: stateTags, ...rest }, { result }) => ({ + ...rest, + tags: stateTags.concat(result.tags.filter((tag) => !stateTags.includes(tag))), // More performant than [ ...new Set(...) ] + }), }, initialState); export const listTags = (buildShlinkApiClient: ShlinkApiClientBuilder, force = true) => () => async ( diff --git a/test/tags/reducers/tagsList.test.ts b/test/tags/reducers/tagsList.test.ts index 884efc1b..67bf868f 100644 --- a/test/tags/reducers/tagsList.test.ts +++ b/test/tags/reducers/tagsList.test.ts @@ -11,6 +11,8 @@ import reducer, { import { TAG_DELETED } from '../../../src/tags/reducers/tagDelete'; import { TAG_EDITED } from '../../../src/tags/reducers/tagEdit'; import { ShlinkState } from '../../../src/container/types'; +import { ShortUrl } from '../../../src/short-urls/data'; +import { CREATE_SHORT_URL } from '../../../src/short-urls/reducers/shortUrlCreation'; describe('tagsListReducer', () => { const state = (props: Partial) => Mock.of(props); @@ -74,6 +76,19 @@ describe('tagsListReducer', () => { filteredTags, }); }); + + it.each([ + [[ 'foo', 'foo3', 'bar3', 'fo' ], [ 'foo', 'bar', 'baz', 'foo2', 'fo', 'foo3', 'bar3' ]], + [[ 'foo', 'bar' ], [ 'foo', 'bar', 'baz', 'foo2', 'fo' ]], + [[ 'new', 'tag' ], [ 'foo', 'bar', 'baz', 'foo2', 'fo', 'new', 'tag' ]], + ])('appends new short URL\'s tags to the list of tags on CREATE_SHORT_URL', (shortUrlTags, expectedTags) => { + const tags = [ 'foo', 'bar', 'baz', 'foo2', 'fo' ]; + const result = Mock.of({ tags: shortUrlTags }); + + expect(reducer(state({ tags }), { type: CREATE_SHORT_URL, result } as any)).toEqual({ + tags: expectedTags, + }); + }); }); describe('filterTags', () => {