debian-mirror-gitlab/app/assets/javascripts/snippets/index.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
2020-11-24 15:15:51 +05:30
import { SNIPPET_LEVELS_MAP, SNIPPET_VISIBILITY_PRIVATE } from '~/snippets/constants';
2021-03-11 19:13:27 +05:30
import Translate from '~/vue_shared/translate';
2020-01-01 13:55:28 +05:30
Vue.use(VueApollo);
Vue.use(Translate);
2021-01-03 14:25:43 +05:30
export default function appFactory(el, Component) {
2020-01-01 13:55:28 +05:30
if (!el) {
return false;
}
const apolloProvider = new VueApollo({
2021-10-27 15:23:28 +05:30
defaultClient: createDefaultClient(
{},
{
batchMax: 1,
assumeImmutableResults: true,
},
),
2020-01-01 13:55:28 +05:30
});
2020-11-24 15:15:51 +05:30
const {
visibilityLevels = '[]',
selectedLevel,
multipleLevelsRestricted,
2021-10-27 15:23:28 +05:30
reportAbusePath,
2020-11-24 15:15:51 +05:30
...restDataset
} = el.dataset;
2021-01-29 00:20:46 +05:30
return new Vue({
el,
apolloProvider,
provide: {
2020-11-24 15:15:51 +05:30
visibilityLevels: JSON.parse(visibilityLevels),
selectedLevel: SNIPPET_LEVELS_MAP[selectedLevel] ?? SNIPPET_VISIBILITY_PRIVATE,
multipleLevelsRestricted: 'multipleLevelsRestricted' in el.dataset,
2021-10-27 15:23:28 +05:30
reportAbusePath,
2020-11-24 15:15:51 +05:30
},
2020-01-01 13:55:28 +05:30
render(createElement) {
2020-04-22 19:07:51 +05:30
return createElement(Component, {
2020-01-01 13:55:28 +05:30
props: {
2020-11-24 15:15:51 +05:30
...restDataset,
2020-01-01 13:55:28 +05:30
},
});
},
});
2020-04-22 19:07:51 +05:30
}