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

utils.js « users_select « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b46fd15fb7723ab360d3a8da387cbc9dea69531b (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
/**
 * Get options from data attributes on passed `$select`.
 * @param {jQuery} $select
 * @param {Object} optionsMap e.g. { optionKeyName: 'dataAttributeName' }
 */
export const getAjaxUsersSelectOptions = ($select, optionsMap) => {
  return Object.keys(optionsMap).reduce((accumulator, optionKey) => {
    const dataKey = optionsMap[optionKey];
    accumulator[optionKey] = $select.data(dataKey);

    return accumulator;
  }, {});
};

/**
 * Get query parameters used for users request from passed `options` parameter
 * @param {Object} options e.g. { currentUserId: 1, fooBar: 'baz' }
 * @param {Object} paramsMap e.g. { user_id: 'currentUserId', foo_bar: 'fooBar' }
 */
export const getAjaxUsersSelectParams = (options, paramsMap) => {
  return Object.keys(paramsMap).reduce((accumulator, paramKey) => {
    const optionKey = paramsMap[paramKey];
    accumulator[paramKey] = options[optionKey] || null;

    return accumulator;
  }, {});
};