diff options
Diffstat (limited to 'app/assets/javascripts/groups/members/utils.js')
-rw-r--r-- | app/assets/javascripts/groups/members/utils.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/assets/javascripts/groups/members/utils.js b/app/assets/javascripts/groups/members/utils.js new file mode 100644 index 00000000000..662eecc4e38 --- /dev/null +++ b/app/assets/javascripts/groups/members/utils.js @@ -0,0 +1,44 @@ +import { isUndefined } from 'lodash'; +import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import { + GROUP_MEMBER_BASE_PROPERTY_NAME, + GROUP_MEMBER_ACCESS_LEVEL_PROPERTY_NAME, + GROUP_LINK_BASE_PROPERTY_NAME, + GROUP_LINK_ACCESS_LEVEL_PROPERTY_NAME, +} from './constants'; + +export const parseDataAttributes = el => { + const { members, groupId, memberPath } = el.dataset; + + return { + members: convertObjectPropsToCamelCase(JSON.parse(members), { deep: true }), + sourceId: parseInt(groupId, 10), + memberPath, + }; +}; + +const baseRequestFormatter = (basePropertyName, accessLevelPropertyName) => ({ + accessLevel, + ...otherProperties +}) => { + const accessLevelProperty = !isUndefined(accessLevel) + ? { [accessLevelPropertyName]: accessLevel } + : {}; + + return { + [basePropertyName]: { + ...accessLevelProperty, + ...otherProperties, + }, + }; +}; + +export const memberRequestFormatter = baseRequestFormatter( + GROUP_MEMBER_BASE_PROPERTY_NAME, + GROUP_MEMBER_ACCESS_LEVEL_PROPERTY_NAME, +); + +export const groupLinkRequestFormatter = baseRequestFormatter( + GROUP_LINK_BASE_PROPERTY_NAME, + GROUP_LINK_ACCESS_LEVEL_PROPERTY_NAME, +); |