debian-mirror-gitlab/app/assets/javascripts/nav/components/new_nav_toggle.vue

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

81 lines
2.1 KiB
Vue
Raw Normal View History

2023-03-04 22:38:38 +05:30
<script>
import { GlBadge, GlToggle } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils';
import { createAlert } from '~/flash';
import { s__ } from '~/locale';
2023-03-17 16:20:25 +05:30
import Tracking from '~/tracking';
2023-03-04 22:38:38 +05:30
export default {
i18n: {
badgeLabel: s__('NorthstarNavigation|Alpha'),
sectionTitle: s__('NorthstarNavigation|Navigation redesign'),
toggleMenuItemLabel: s__('NorthstarNavigation|New navigation'),
toggleLabel: s__('NorthstarNavigation|Toggle new navigation'),
updateError: s__(
'NorthstarNavigation|Could not update the new navigation preference. Please try again later.',
),
},
components: {
GlBadge,
GlToggle,
},
props: {
enabled: {
type: Boolean,
required: true,
},
endpoint: {
type: String,
required: true,
},
},
data() {
return {
isEnabled: this.enabled,
};
},
methods: {
2023-03-17 16:20:25 +05:30
toggleNav() {
this.isEnabled = !this.isEnabled;
this.updateAndReload();
},
async updateAndReload() {
2023-03-04 22:38:38 +05:30
try {
2023-03-17 16:20:25 +05:30
await axios.put(this.endpoint, { user: { use_new_navigation: this.isEnabled } });
Tracking.event(undefined, 'click_toggle', {
label: this.enabled ? 'disable_new_nav_beta' : 'enable_new_nav_beta',
2023-04-23 21:23:45 +05:30
property: this.enabled ? 'navigation' : 'navigation_top',
2023-03-17 16:20:25 +05:30
});
2023-03-04 22:38:38 +05:30
window.location.reload();
} catch (error) {
createAlert({
message: this.$options.i18n.updateError,
error,
});
}
},
},
};
</script>
<template>
<li>
<div
class="gl-px-4 gl-py-2 gl-display-flex gl-justify-content-space-between gl-align-items-center"
>
<b>{{ $options.i18n.sectionTitle }}</b>
2023-03-17 16:20:25 +05:30
<gl-badge variant="info">{{ $options.i18n.badgeLabel }}</gl-badge>
2023-03-04 22:38:38 +05:30
</div>
2023-03-17 16:20:25 +05:30
<div
class="menu-item gl-cursor-pointer gl-display-flex! gl-justify-content-space-between gl-align-items-center"
@click.prevent.stop="toggleNav"
>
2023-03-04 22:38:38 +05:30
{{ $options.i18n.toggleMenuItemLabel }}
2023-03-17 16:20:25 +05:30
<gl-toggle :value="isEnabled" :label="$options.i18n.toggleLabel" label-position="hidden" />
2023-03-04 22:38:38 +05:30
</div>
</li>
</template>