Commit 62c8c506 authored by Mark Florian's avatar Mark Florian

Refactor sort constants

This aligns better with our [guidelines][1] on constants.

[1]: https://docs.gitlab.com/ee/development/fe_guide/style/javascript.html#export-constants-as-primitives
parent 7678d206
...@@ -3,7 +3,7 @@ import { GlButton, GlDropdown, GlDropdownItem, GlIcon, GlTooltipDirective } from ...@@ -3,7 +3,7 @@ import { GlButton, GlDropdown, GlDropdownItem, GlIcon, GlTooltipDirective } from
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { DEPENDENCY_LIST_TYPES } from '../store/constants'; import { DEPENDENCY_LIST_TYPES } from '../store/constants';
import { SORT_FIELDS, SORT_ORDER } from '../store/modules/list/constants'; import { SORT_FIELDS, SORT_ASCENDING } from '../store/modules/list/constants';
export default { export default {
i18n: { i18n: {
...@@ -48,7 +48,7 @@ export default { ...@@ -48,7 +48,7 @@ export default {
return this.sortFields[this.sortField]; return this.sortFields[this.sortField];
}, },
sortOrderIcon() { sortOrderIcon() {
return this.sortOrder === SORT_ORDER.ascending ? 'sort-lowest' : 'sort-highest'; return this.sortOrder === SORT_ASCENDING ? 'sort-lowest' : 'sort-highest';
}, },
}, },
methods: { methods: {
......
...@@ -6,10 +6,8 @@ export const SORT_FIELDS = { ...@@ -6,10 +6,8 @@ export const SORT_FIELDS = {
severity: s__('Vulnerability|Severity'), severity: s__('Vulnerability|Severity'),
}; };
export const SORT_ORDER = { export const SORT_ASCENDING = 'asc';
ascending: 'asc', export const SORT_DESCENDING = 'desc';
descending: 'desc',
};
export const REPORT_STATUS = { export const REPORT_STATUS = {
ok: 'ok', ok: 'ok',
......
import { REPORT_STATUS, SORT_ORDER } from './constants'; import { REPORT_STATUS, SORT_ASCENDING, SORT_DESCENDING } from './constants';
import * as types from './mutation_types'; import * as types from './mutation_types';
export default { export default {
...@@ -38,7 +38,6 @@ export default { ...@@ -38,7 +38,6 @@ export default {
state.sortField = payload; state.sortField = payload;
}, },
[types.TOGGLE_SORT_ORDER](state) { [types.TOGGLE_SORT_ORDER](state) {
state.sortOrder = state.sortOrder = state.sortOrder === SORT_ASCENDING ? SORT_DESCENDING : SORT_ASCENDING;
state.sortOrder === SORT_ORDER.ascending ? SORT_ORDER.descending : SORT_ORDER.ascending;
}, },
}; };
import { FILTER, REPORT_STATUS, SORT_ORDER } from './constants'; import { FILTER, REPORT_STATUS, SORT_DESCENDING } from './constants';
export default () => ({ export default () => ({
endpoint: '', endpoint: '',
...@@ -16,5 +16,5 @@ export default () => ({ ...@@ -16,5 +16,5 @@ export default () => ({
}, },
filter: FILTER.all, filter: FILTER.all,
sortField: 'severity', sortField: 'severity',
sortOrder: SORT_ORDER.descending, sortOrder: SORT_DESCENDING,
}); });
...@@ -4,7 +4,7 @@ import { sortBy } from 'lodash'; ...@@ -4,7 +4,7 @@ import { sortBy } from 'lodash';
import * as actions from 'ee/dependencies/store/modules/list/actions'; import * as actions from 'ee/dependencies/store/modules/list/actions';
import { import {
FILTER, FILTER,
SORT_ORDER, SORT_DESCENDING,
FETCH_ERROR_MESSAGE, FETCH_ERROR_MESSAGE,
} from 'ee/dependencies/store/modules/list/constants'; } from 'ee/dependencies/store/modules/list/constants';
import * as types from 'ee/dependencies/store/modules/list/mutation_types'; import * as types from 'ee/dependencies/store/modules/list/mutation_types';
...@@ -194,7 +194,7 @@ describe('Dependencies actions', () => { ...@@ -194,7 +194,7 @@ describe('Dependencies actions', () => {
describe('given params', () => { describe('given params', () => {
const paramsGiven = { const paramsGiven = {
sort_by: 'packager', sort_by: 'packager',
sort: SORT_ORDER.descending, sort: SORT_DESCENDING,
page: 4, page: 4,
filter: FILTER.vulnerable, filter: FILTER.vulnerable,
}; };
......
import { REPORT_STATUS, SORT_ORDER } from 'ee/dependencies/store/modules/list/constants'; import {
REPORT_STATUS,
SORT_ASCENDING,
SORT_DESCENDING,
} from 'ee/dependencies/store/modules/list/constants';
import * as types from 'ee/dependencies/store/modules/list/mutation_types'; import * as types from 'ee/dependencies/store/modules/list/mutation_types';
import mutations from 'ee/dependencies/store/modules/list/mutations'; import mutations from 'ee/dependencies/store/modules/list/mutations';
import getInitialState from 'ee/dependencies/store/modules/list/state'; import getInitialState from 'ee/dependencies/store/modules/list/state';
...@@ -96,14 +100,14 @@ describe('Dependencies mutations', () => { ...@@ -96,14 +100,14 @@ describe('Dependencies mutations', () => {
describe(types.TOGGLE_SORT_ORDER, () => { describe(types.TOGGLE_SORT_ORDER, () => {
it('toggles the sort order', () => { it('toggles the sort order', () => {
const sortState = { sortOrder: SORT_ORDER.ascending }; const sortState = { sortOrder: SORT_ASCENDING };
mutations[types.TOGGLE_SORT_ORDER](sortState); mutations[types.TOGGLE_SORT_ORDER](sortState);
expect(sortState.sortOrder).toBe(SORT_ORDER.descending); expect(sortState.sortOrder).toBe(SORT_DESCENDING);
mutations[types.TOGGLE_SORT_ORDER](sortState); mutations[types.TOGGLE_SORT_ORDER](sortState);
expect(sortState.sortOrder).toBe(SORT_ORDER.ascending); expect(sortState.sortOrder).toBe(SORT_ASCENDING);
}); });
}); });
}); });
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