summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/admin/abuse_reports/constants.js
blob: ee2e9ab2cbf294869b54fa7d5dc0cd65945dd158 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { getUsers } from '~/rest_api';
import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue';
import UserToken from '~/vue_shared/components/filtered_search_bar/tokens/user_token.vue';
import {
  OPERATORS_IS,
  TOKEN_TITLE_STATUS,
} from '~/vue_shared/components/filtered_search_bar/constants';
import { __ } from '~/locale';

const STATUS_OPTIONS = [
  { value: 'closed', title: __('Closed') },
  { value: 'open', title: __('Open') },
];

export const FILTERED_SEARCH_TOKEN_USER = {
  type: 'user',
  icon: 'user',
  title: __('User'),
  token: UserToken,
  unique: true,
  operators: OPERATORS_IS,
  fetchUsers: getUsers,
  defaultUsers: [],
};

export const FILTERED_SEARCH_TOKEN_REPORTER = {
  ...FILTERED_SEARCH_TOKEN_USER,
  type: 'reporter',
  title: __('Reporter'),
};

export const FILTERED_SEARCH_TOKEN_STATUS = {
  type: 'status',
  icon: 'status',
  title: TOKEN_TITLE_STATUS,
  token: BaseToken,
  unique: true,
  options: STATUS_OPTIONS,
  operators: OPERATORS_IS,
};

export const DEFAULT_SORT = 'created_at_desc';

export const SORT_OPTIONS = [
  {
    id: 10,
    title: __('Created date'),
    sortDirection: {
      descending: DEFAULT_SORT,
      ascending: 'created_at_asc',
    },
  },
  {
    id: 20,
    title: __('Updated date'),
    sortDirection: {
      descending: 'updated_at_desc',
      ascending: 'updated_at_asc',
    },
  },
];

export const isValidSortKey = (key) =>
  SORT_OPTIONS.some(
    (sort) => sort.sortDirection.ascending === key || sort.sortDirection.descending === key,
  );

export const FILTERED_SEARCH_TOKEN_CATEGORY = {
  type: 'category',
  icon: 'label',
  title: __('Category'),
  token: BaseToken,
  unique: true,
  operators: OPERATORS_IS,
};

export const FILTERED_SEARCH_TOKENS = [
  FILTERED_SEARCH_TOKEN_USER,
  FILTERED_SEARCH_TOKEN_REPORTER,
  FILTERED_SEARCH_TOKEN_STATUS,
];