summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/experiment_new_project_creation/components/app.vue
blob: 1060b37067e60b5a632d21d3a6f609c4b67f7635 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<script>
/* eslint-disable vue/no-v-html */
import { GlBreadcrumb, GlIcon, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
import { experiment } from '~/experimentation/utils';
import { __, s__ } from '~/locale';
import { NEW_REPO_EXPERIMENT } from '../constants';
import blankProjectIllustration from '../illustrations/blank-project.svg';
import ciCdProjectIllustration from '../illustrations/ci-cd-project.svg';
import createFromTemplateIllustration from '../illustrations/create-from-template.svg';
import importProjectIllustration from '../illustrations/import-project.svg';
import LegacyContainer from './legacy_container.vue';
import WelcomePage from './welcome.vue';

const BLANK_PANEL = 'blank_project';
const CI_CD_PANEL = 'cicd_for_external_repo';
const LAST_ACTIVE_TAB_KEY = 'new_project_last_active_tab';

const PANELS = [
  {
    key: 'blank',
    name: BLANK_PANEL,
    selector: '#blank-project-pane',
    title: s__('ProjectsNew|Create blank project'),
    description: s__(
      'ProjectsNew|Create a blank project to house your files, plan your work, and collaborate on code, among other things.',
    ),
    illustration: blankProjectIllustration,
  },
  {
    key: 'template',
    name: 'create_from_template',
    selector: '#create-from-template-pane',
    title: s__('ProjectsNew|Create from template'),
    description: s__(
      'Create a project pre-populated with the necessary files to get you started quickly.',
    ),
    illustration: createFromTemplateIllustration,
  },
  {
    key: 'import',
    name: 'import_project',
    selector: '#import-project-pane',
    title: s__('ProjectsNew|Import project'),
    description: s__(
      'Migrate your data from an external source like GitHub, Bitbucket, or another instance of GitLab.',
    ),
    illustration: importProjectIllustration,
  },
  {
    key: 'ci',
    name: CI_CD_PANEL,
    selector: '#ci-cd-project-pane',
    title: s__('ProjectsNew|Run CI/CD for external repository'),
    description: s__('ProjectsNew|Connect your external repository to GitLab CI/CD.'),
    illustration: ciCdProjectIllustration,
  },
];

export default {
  components: {
    GlBreadcrumb,
    GlIcon,
    WelcomePage,
    LegacyContainer,
  },
  directives: {
    SafeHtml,
  },
  props: {
    hasErrors: {
      type: Boolean,
      required: false,
      default: false,
    },
    isCiCdAvailable: {
      type: Boolean,
      required: false,
      default: false,
    },
    newProjectGuidelines: {
      type: String,
      required: false,
      default: '',
    },
  },

  data() {
    return {
      activeTab: null,
    };
  },

  computed: {
    decoratedPanels() {
      const PANEL_TITLES = experiment(NEW_REPO_EXPERIMENT, {
        use: () => ({
          blank: s__('ProjectsNew|Create blank project'),
          import: s__('ProjectsNew|Import project'),
        }),
        try: () => ({
          blank: s__('ProjectsNew|Create blank project/repository'),
          import: s__('ProjectsNew|Import project/repository'),
        }),
      });

      return PANELS.map(({ key, title, ...el }) => ({
        ...el,
        title: PANEL_TITLES[key] !== undefined ? PANEL_TITLES[key] : title,
      }));
    },

    availablePanels() {
      if (this.isCiCdAvailable) {
        return this.decoratedPanels;
      }

      return this.decoratedPanels.filter((p) => p.name !== CI_CD_PANEL);
    },

    activePanel() {
      return this.decoratedPanels.find((p) => p.name === this.activeTab);
    },

    breadcrumbs() {
      if (!this.activeTab || !this.activePanel) {
        return null;
      }

      return [
        { text: __('New project'), href: '#' },
        { text: this.activePanel.title, href: `#${this.activeTab}` },
      ];
    },
  },

  created() {
    this.handleLocationHashChange();

    if (this.hasErrors) {
      this.activeTab = localStorage.getItem(LAST_ACTIVE_TAB_KEY) || BLANK_PANEL;
    }

    window.addEventListener('hashchange', () => {
      this.handleLocationHashChange();
      this.resetProjectErrors();
    });
    this.$root.$on('clicked::link', (e) => {
      window.location = e.target.href;
    });
  },

  methods: {
    resetProjectErrors() {
      const errorsContainer = document.querySelector('.project-edit-errors');
      if (errorsContainer) {
        errorsContainer.innerHTML = '';
      }
    },

    handleLocationHashChange() {
      this.activeTab = window.location.hash.substring(1) || null;
      if (this.activeTab) {
        localStorage.setItem(LAST_ACTIVE_TAB_KEY, this.activeTab);
      }
    },
  },

  PANELS,
};
</script>

<template>
  <welcome-page v-if="activeTab === null" :panels="availablePanels" />
  <div v-else class="row">
    <div class="col-lg-3">
      <div class="gl-text-white" v-html="activePanel.illustration"></div>
      <h4>{{ activePanel.title }}</h4>
      <p>{{ activePanel.description }}</p>
      <div
        v-if="newProjectGuidelines"
        id="new-project-guideline"
        v-safe-html="newProjectGuidelines"
      ></div>
    </div>
    <div class="col-lg-9">
      <gl-breadcrumb v-if="breadcrumbs" :items="breadcrumbs">
        <template #separator>
          <gl-icon name="chevron-right" :size="8" />
        </template>
      </gl-breadcrumb>
      <template v-for="panel in $options.PANELS">
        <legacy-container
          v-if="activeTab === panel.name"
          :key="panel.name"
          class="gl-mt-3"
          :selector="panel.selector"
        />
      </template>
    </div>
  </div>
</template>