Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « command_palette « global_search « components « super_sidebar « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5c8c0e59eaf8eb968df892330e37254a68e27c16 (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
import { isNil, omitBy } from 'lodash';
import { objectToQuery } from '~/lib/utils/url_utility';
import { SEARCH_SCOPE } from './constants';

export const commandMapper = ({ name, items }) => {
  // TODO: we filter out invite_members for now, because it is complicated to add the invite members modal here
  // and is out of scope for the basic command palette items. If it proves to be useful, we can add it later.
  return {
    name,
    items: items.filter(({ component }) => component !== 'invite_members'),
  };
};

export const linksReducer = (acc, menuItem) => {
  acc.push({
    text: menuItem.title,
    keywords: menuItem.title,
    icon: menuItem.icon,
    href: menuItem.link,
  });
  if (menuItem.items?.length) {
    const items = menuItem.items.map(({ title, link }) => ({
      keywords: title,
      text: [menuItem.title, title].join(' > '),
      href: link,
      icon: menuItem.icon,
    }));

    /* eslint-disable-next-line no-param-reassign */
    acc = [...acc, ...items];
  }
  return acc;
};

export const autocompleteQuery = ({ path, searchTerm, handle, projectId }) => {
  const query = omitBy(
    {
      term: searchTerm,
      project_id: projectId,
      filter: 'search',
      scope: SEARCH_SCOPE[handle],
    },
    isNil,
  );

  return `${path}?${objectToQuery(query)}`;
};