debian-mirror-gitlab/app/assets/javascripts/super_sidebar/components/create_menu.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
2.6 KiB
Vue
Raw Normal View History

2023-04-23 21:23:45 +05:30
<script>
2023-07-09 08:55:56 +05:30
import {
GlDisclosureDropdown,
GlTooltip,
GlDisclosureDropdownGroup,
GlDisclosureDropdownItem,
} from '@gitlab/ui';
import InviteMembersTrigger from '~/invite_members/components/invite_members_trigger.vue';
2023-04-23 21:23:45 +05:30
import { __ } from '~/locale';
2023-07-09 08:55:56 +05:30
import {
TOP_NAV_INVITE_MEMBERS_COMPONENT,
TRIGGER_ELEMENT_DISCLOSURE_DROPDOWN,
} from '~/invite_members/constants';
2023-06-20 00:43:36 +05:30
import { DROPDOWN_Y_OFFSET } from '../constants';
// Left offset required for the dropdown to be aligned with the super sidebar
const DROPDOWN_X_OFFSET = -147;
2023-04-23 21:23:45 +05:30
export default {
components: {
GlDisclosureDropdown,
2023-07-09 08:55:56 +05:30
GlDisclosureDropdownGroup,
GlDisclosureDropdownItem,
2023-04-23 21:23:45 +05:30
GlTooltip,
2023-07-09 08:55:56 +05:30
InviteMembersTrigger,
2023-04-23 21:23:45 +05:30
},
i18n: {
createNew: __('Create new...'),
},
props: {
groups: {
type: Array,
required: true,
},
},
2023-06-20 00:43:36 +05:30
data() {
return {
dropdownOpen: false,
};
},
2023-07-09 08:55:56 +05:30
methods: {
isInvitedMembers(groupItem) {
return groupItem.component === TOP_NAV_INVITE_MEMBERS_COMPONENT;
},
closeAndFocus() {
this.$refs.dropdown.closeAndFocus();
},
},
2023-04-23 21:23:45 +05:30
toggleId: 'create-menu-toggle',
2023-06-20 00:43:36 +05:30
popperOptions: {
modifiers: [
{
name: 'offset',
options: {
offset: [DROPDOWN_X_OFFSET, DROPDOWN_Y_OFFSET],
},
},
],
},
2023-07-09 08:55:56 +05:30
TRIGGER_ELEMENT_DISCLOSURE_DROPDOWN,
2023-04-23 21:23:45 +05:30
};
</script>
<template>
<div>
<gl-disclosure-dropdown
2023-07-09 08:55:56 +05:30
ref="dropdown"
2023-04-23 21:23:45 +05:30
category="tertiary"
icon="plus"
no-caret
text-sr-only
:toggle-text="$options.i18n.createNew"
:toggle-id="$options.toggleId"
2023-06-20 00:43:36 +05:30
:popper-options="$options.popperOptions"
2023-05-27 22:25:52 +05:30
data-qa-selector="new_menu_toggle"
2023-07-09 08:55:56 +05:30
data-testid="new-menu-toggle"
2023-06-20 00:43:36 +05:30
@shown="dropdownOpen = true"
@hidden="dropdownOpen = false"
2023-07-09 08:55:56 +05:30
>
<gl-disclosure-dropdown-group
v-for="(group, index) in groups"
:key="group.name"
:bordered="index !== 0"
:group="group"
>
<template v-for="groupItem in group.items">
<invite-members-trigger
v-if="isInvitedMembers(groupItem)"
:key="`${groupItem.text}-trigger`"
trigger-source="top-nav"
:trigger-element="$options.TRIGGER_ELEMENT_DISCLOSURE_DROPDOWN"
@modal-opened="closeAndFocus"
/>
<gl-disclosure-dropdown-item v-else :key="groupItem.text" :item="groupItem" />
</template>
</gl-disclosure-dropdown-group>
</gl-disclosure-dropdown>
2023-06-20 00:43:36 +05:30
<gl-tooltip
v-if="!dropdownOpen"
:target="`#${$options.toggleId}`"
placement="bottom"
container="#super-sidebar"
>
2023-04-23 21:23:45 +05:30
{{ $options.i18n.createNew }}
</gl-tooltip>
</div>
</template>