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