summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/index.js
blob: 3b1d35c1f22687a203f1e9ebbf8dc1ec122a3f55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
import { parseBoolean } from '../lib/utils/common_utils';
import Translate from '../vue_shared/translate';
import environmentsComponent from './components/environments_app.vue';

Vue.use(Translate);
Vue.use(VueApollo);

const apolloProvider = new VueApollo({
  defaultClient: createDefaultClient(),
});

export default (el) => {
  if (el) {
    return new Vue({
      el,
      components: {
        environmentsComponent,
      },
      apolloProvider,
      provide: {
        projectPath: el.dataset.projectPath,
        defaultBranchName: el.dataset.defaultBranchName,
      },
      data() {
        const environmentsData = el.dataset;

        return {
          endpoint: environmentsData.environmentsDataEndpoint,
          newEnvironmentPath: environmentsData.newEnvironmentPath,
          helpPagePath: environmentsData.helpPagePath,
          canCreateEnvironment: parseBoolean(environmentsData.canCreateEnvironment),
        };
      },
      render(createElement) {
        return createElement('environments-component', {
          props: {
            endpoint: this.endpoint,
            newEnvironmentPath: this.newEnvironmentPath,
            helpPagePath: this.helpPagePath,
            canCreateEnvironment: this.canCreateEnvironment,
          },
        });
      },
    });
  }

  return null;
};