debian-mirror-gitlab/app/assets/javascripts/members/utils.js

98 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import { __ } from '~/locale';
import { getParameterByName } from '~/lib/utils/common_utils';
import { setUrlParams } from '~/lib/utils/url_utility';
import { FIELDS, DEFAULT_SORT } from './constants';
export const generateBadges = (member, isCurrentUser) => [
{
show: isCurrentUser,
text: __("It's you"),
variant: 'success',
},
{
show: member.user?.blocked,
text: __('Blocked'),
variant: 'danger',
},
{
show: member.user?.twoFactorEnabled,
text: __('2FA'),
variant: 'info',
},
];
2021-03-08 18:12:59 +05:30
export const isGroup = (member) => {
2021-02-22 17:27:13 +05:30
return Boolean(member.sharedWithGroup);
};
export const isDirectMember = (member, sourceId) => {
return isGroup(member) || member.source?.id === sourceId;
};
export const isCurrentUser = (member, currentUserId) => {
return member.user?.id === currentUserId;
};
export const canRemove = (member, sourceId) => {
return isDirectMember(member, sourceId) && member.canRemove;
};
2021-03-08 18:12:59 +05:30
export const canResend = (member) => {
2021-02-22 17:27:13 +05:30
return Boolean(member.invite?.canResend);
};
export const canUpdate = (member, currentUserId, sourceId) => {
return (
!isCurrentUser(member, currentUserId) && isDirectMember(member, sourceId) && member.canUpdate
);
};
2021-03-08 18:12:59 +05:30
export const parseSortParam = (sortableFields) => {
2021-02-22 17:27:13 +05:30
const sortParam = getParameterByName('sort');
2021-03-08 18:12:59 +05:30
const sortedField = FIELDS.filter((field) => sortableFields.includes(field.key)).find(
(field) => field.sort?.asc === sortParam || field.sort?.desc === sortParam,
2021-02-22 17:27:13 +05:30
);
if (!sortedField) {
return DEFAULT_SORT;
}
return {
sortByKey: sortedField.key,
sortDesc: sortedField?.sort?.desc === sortParam,
};
};
export const buildSortHref = ({
sortBy,
sortDesc,
filteredSearchBarTokens,
filteredSearchBarSearchParam,
}) => {
2021-03-08 18:12:59 +05:30
const sortDefinition = FIELDS.find((field) => field.key === sortBy)?.sort;
2021-02-22 17:27:13 +05:30
if (!sortDefinition) {
return '';
}
const sortParam = sortDesc ? sortDefinition.desc : sortDefinition.asc;
const filterParams =
filteredSearchBarTokens?.reduce((accumulator, token) => {
return {
...accumulator,
[token]: getParameterByName(token),
};
}, {}) || {};
if (filteredSearchBarSearchParam) {
filterParams[filteredSearchBarSearchParam] = getParameterByName(filteredSearchBarSearchParam);
}
return setUrlParams({ ...filterParams, sort: sortParam }, window.location.href, true);
};
// Defined in `ee/app/assets/javascripts/vue_shared/components/members/utils.js`
export const canOverride = () => false;