mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 17:40:23 +03:00
Migrated filterTags action to use payload
This commit is contained in:
parent
b9e02cf344
commit
b7622b2b38
2 changed files with 7 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { createAction, PayloadAction } from '@reduxjs/toolkit';
|
||||||
import { isEmpty, reject } from 'ramda';
|
import { isEmpty, reject } from 'ramda';
|
||||||
import { Action, Dispatch } from 'redux';
|
import { Action, Dispatch } from 'redux';
|
||||||
import { createNewVisits, CreateVisitsAction } from '../../visits/reducers/visitCreation';
|
import { createNewVisits, CreateVisitsAction } from '../../visits/reducers/visitCreation';
|
||||||
|
@ -35,9 +36,7 @@ interface ListTagsAction extends Action<string> {
|
||||||
stats: TagsStatsMap;
|
stats: TagsStatsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FilterTagsAction extends Action<string> {
|
type FilterTagsAction = PayloadAction<string>;
|
||||||
searchTerm: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TagsCombinedAction = ListTagsAction
|
type TagsCombinedAction = ListTagsAction
|
||||||
& DeleteTagAction
|
& DeleteTagAction
|
||||||
|
@ -95,7 +94,7 @@ export default buildReducer<TagsList, TagsCombinedAction>({
|
||||||
tags: state.tags.map(renameTag(payload.oldName, payload.newName)).sort(),
|
tags: state.tags.map(renameTag(payload.oldName, payload.newName)).sort(),
|
||||||
filteredTags: state.filteredTags.map(renameTag(payload.oldName, payload.newName)).sort(),
|
filteredTags: state.filteredTags.map(renameTag(payload.oldName, payload.newName)).sort(),
|
||||||
}),
|
}),
|
||||||
[FILTER_TAGS]: (state, { searchTerm }) => ({
|
[FILTER_TAGS]: (state, { payload: searchTerm }) => ({
|
||||||
...state,
|
...state,
|
||||||
filteredTags: state.tags.filter((tag) => tag.toLowerCase().match(searchTerm.toLowerCase())),
|
filteredTags: state.tags.filter((tag) => tag.toLowerCase().match(searchTerm.toLowerCase())),
|
||||||
}),
|
}),
|
||||||
|
@ -136,4 +135,4 @@ export const listTags = (buildShlinkApiClient: ShlinkApiClientBuilder, force = t
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const filterTags = (searchTerm: string): FilterTagsAction => ({ type: FILTER_TAGS, searchTerm });
|
export const filterTags = createAction<string>(FILTER_TAGS);
|
||||||
|
|
|
@ -77,10 +77,10 @@ describe('tagsListReducer', () => {
|
||||||
|
|
||||||
it('filters original list of tags by provided search term on FILTER_TAGS', () => {
|
it('filters original list of tags by provided search term on FILTER_TAGS', () => {
|
||||||
const tags = ['foo', 'bar', 'baz', 'Foo2', 'fo'];
|
const tags = ['foo', 'bar', 'baz', 'Foo2', 'fo'];
|
||||||
const searchTerm = 'Fo';
|
const payload = 'Fo';
|
||||||
const filteredTags = ['foo', 'Foo2', 'fo'];
|
const filteredTags = ['foo', 'Foo2', 'fo'];
|
||||||
|
|
||||||
expect(reducer(state({ tags }), { type: FILTER_TAGS, searchTerm } as any)).toEqual({
|
expect(reducer(state({ tags }), { type: FILTER_TAGS, payload } as any)).toEqual({
|
||||||
tags,
|
tags,
|
||||||
filteredTags,
|
filteredTags,
|
||||||
});
|
});
|
||||||
|
@ -101,7 +101,7 @@ describe('tagsListReducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('filterTags', () => {
|
describe('filterTags', () => {
|
||||||
it('creates expected action', () => expect(filterTags('foo')).toEqual({ type: FILTER_TAGS, searchTerm: 'foo' }));
|
it('creates expected action', () => expect(filterTags('foo')).toEqual({ type: FILTER_TAGS, payload: 'foo' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('listTags', () => {
|
describe('listTags', () => {
|
||||||
|
|
Loading…
Reference in a new issue