Commit 429259bc authored by samdbeckham's avatar samdbeckham

Adds changes from @leipert review

- Fixed some spelling mistakes
- Made the SET_FILTER mutation less terse and easier to parse
- Improved the i18n for the filter text getter
- Re-ran gettext
parent 41da600c
import { sprintf, __ } from '~/locale';
export const getFilter = state => filterId => state.filters.find(filter => filter.id === filterId);
export const getSelectedOptions = (state, getters) => filterId =>
......@@ -9,9 +11,14 @@ export const getSelectedOptionIds = (state, getters) => filterId =>
export const getSelectedOptionNames = (state, getters) => filterId => {
const selectedOptions = getters.getSelectedOptions(filterId);
const [firstOption] = selectedOptions.map(option => option.name);
return selectedOptions.length > 1
? `${firstOption} +${selectedOptions.length - 1} more`
: `${firstOption}`;
const extraOptionCount = selectedOptions.length - 1;
return extraOptionCount
? sprintf(__('%{firstOption} +%{extraOptionCount} more'), {
firstOption,
extraOptionCount,
})
: firstOption;
};
export const getFilterIds = state => state.filters.map(filter => filter.id);
......
......@@ -11,17 +11,25 @@ export default {
if (optionId === 'all') {
activeOptions = activeFilter.options.map(option => ({
...option,
selected: option.id === 'all',
selected: option.id === optionId,
}));
} else {
activeOptions = activeFilter.options.map(option => {
const selected =
option.id === optionId ? !option.selected : option.selected && option.id !== 'all';
if (option.id === 'all') {
return {
...option,
selected: false,
};
}
return {
...option,
selected,
};
if (option.id === optionId) {
return {
...option,
selected: !option.selected,
};
}
return option;
});
}
......
---
title: Allows the GSD to select multiple filters
title: Allows the Group Security Dashboard to select multiple filters
merge_request: 9031
author:
type: added
......@@ -29,7 +29,7 @@ describe('filters module getters', () => {
describe('getSelectedOptions', () => {
describe('with one selected option', () => {
it('should return "all" as the selcted option', () => {
it('should return "All" as the selected option', () => {
const state = createState();
const selectedOptions = getters.getSelectedOptions(state, mockedGetters(state))(
'report_type',
......
......@@ -150,6 +150,9 @@ msgstr ""
msgid "%{firstLabel} +%{labelCount} more"
msgstr ""
msgid "%{firstOption} +%{extraOptionCount} more"
msgstr ""
msgid "%{group_docs_link_start}Groups%{group_docs_link_end} allow you to manage and collaborate across multiple projects. Members of a group have access to all of its projects."
msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment