diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-16 00:11:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-16 00:11:32 +0300 |
commit | 1c898dc5c10bbedf94386d917259153d73608495 (patch) | |
tree | f939cf185da9e96f7aba2200fa5ac74deffd71f9 /app/assets/javascripts/ide | |
parent | 22baaecaa84003c554f35752a729331e956d7659 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/ide')
-rw-r--r-- | app/assets/javascripts/ide/components/ide_tree_list.vue | 14 | ||||
-rw-r--r-- | app/assets/javascripts/ide/ide_router.js | 69 | ||||
-rw-r--r-- | app/assets/javascripts/ide/index.js | 11 | ||||
-rw-r--r-- | app/assets/javascripts/ide/services/index.js | 36 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/project.js | 57 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/mutation_types.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/mutations/project.js | 12 |
7 files changed, 102 insertions, 98 deletions
diff --git a/app/assets/javascripts/ide/components/ide_tree_list.vue b/app/assets/javascripts/ide/components/ide_tree_list.vue index b987adc8bae..0fc7337ad26 100644 --- a/app/assets/javascripts/ide/components/ide_tree_list.vue +++ b/app/assets/javascripts/ide/components/ide_tree_list.vue @@ -29,14 +29,20 @@ export default { }, }, watch: { - showLoading(newVal) { - if (!newVal) { - this.$emit('tree-ready'); - } + showLoading() { + this.notifyTreeReady(); }, }, + mounted() { + this.notifyTreeReady(); + }, methods: { ...mapActions(['toggleTreeOpen']), + notifyTreeReady() { + if (!this.showLoading) { + this.$emit('tree-ready'); + } + }, clickedFile() { performanceMarkAndMeasure({ mark: WEBIDE_MARK_FILE_CLICKED }); }, diff --git a/app/assets/javascripts/ide/ide_router.js b/app/assets/javascripts/ide/ide_router.js index 27cedd80347..1fc447886bb 100644 --- a/app/assets/javascripts/ide/ide_router.js +++ b/app/assets/javascripts/ide/ide_router.js @@ -1,8 +1,6 @@ import Vue from 'vue'; -import createFlash from '~/flash'; import IdeRouter from '~/ide/ide_router_extension'; import { joinPaths } from '~/lib/utils/url_utility'; -import { __ } from '~/locale'; import { WEBIDE_MARK_FETCH_PROJECT_DATA_START, WEBIDE_MARK_FETCH_PROJECT_DATA_FINISH, @@ -75,49 +73,34 @@ export const createRouter = (store, defaultBranch) => { router.beforeEach((to, from, next) => { if (to.params.namespace && to.params.project) { - performanceMarkAndMeasure({ mark: WEBIDE_MARK_FETCH_PROJECT_DATA_START }); - store - .dispatch('getProjectData', { - namespace: to.params.namespace, - projectId: to.params.project, - }) - .then(() => { - const basePath = to.params.pathMatch || ''; - const projectId = `${to.params.namespace}/${to.params.project}`; - const branchId = to.params.branchid; - const mergeRequestId = to.params.mrid; + const basePath = to.params.pathMatch || ''; + const projectId = `${to.params.namespace}/${to.params.project}`; + const branchId = to.params.branchid; + const mergeRequestId = to.params.mrid; - if (branchId) { - performanceMarkAndMeasure({ - mark: WEBIDE_MARK_FETCH_PROJECT_DATA_FINISH, - measures: [ - { - name: WEBIDE_MEASURE_FETCH_PROJECT_DATA, - start: WEBIDE_MARK_FETCH_PROJECT_DATA_START, - }, - ], - }); - store.dispatch('openBranch', { - projectId, - branchId, - basePath, - }); - } else if (mergeRequestId) { - store.dispatch('openMergeRequest', { - projectId, - mergeRequestId, - targetProjectId: to.query.target_project, - }); - } - }) - .catch((e) => { - createFlash({ - message: __('Error while loading the project data. Please try again.'), - fadeTransition: false, - addBodyClass: true, - }); - throw e; + performanceMarkAndMeasure({ mark: WEBIDE_MARK_FETCH_PROJECT_DATA_START }); + if (branchId) { + performanceMarkAndMeasure({ + mark: WEBIDE_MARK_FETCH_PROJECT_DATA_FINISH, + measures: [ + { + name: WEBIDE_MEASURE_FETCH_PROJECT_DATA, + start: WEBIDE_MARK_FETCH_PROJECT_DATA_START, + }, + ], + }); + store.dispatch('openBranch', { + projectId, + branchId, + basePath, + }); + } else if (mergeRequestId) { + store.dispatch('openMergeRequest', { + projectId, + mergeRequestId, + targetProjectId: to.query.target_project, }); + } } next(); diff --git a/app/assets/javascripts/ide/index.js b/app/assets/javascripts/ide/index.js index bdffed70882..df643675357 100644 --- a/app/assets/javascripts/ide/index.js +++ b/app/assets/javascripts/ide/index.js @@ -34,11 +34,18 @@ Vue.use(PerformancePlugin, { * @param {extendStoreCallback} options.extendStore - * Function that receives the default store and returns an extended one. */ -export function initIde(el, options = {}) { +export const initIde = (el, options = {}) => { if (!el) return null; const { rootComponent = ide, extendStore = identity } = options; + const store = createStore(); + const project = JSON.parse(el.dataset.project); + store.dispatch('setProject', { project }); + + // fire and forget fetching non-critical project info + store.dispatch('fetchProjectPermissions'); + const router = createRouter(store, el.dataset.defaultBranch || DEFAULT_BRANCH); return new Vue({ @@ -77,7 +84,7 @@ export function initIde(el, options = {}) { return createElement(rootComponent); }, }); -} +}; /** * Start the IDE. diff --git a/app/assets/javascripts/ide/services/index.js b/app/assets/javascripts/ide/services/index.js index 37a08bc4feb..805476c71bc 100644 --- a/app/assets/javascripts/ide/services/index.js +++ b/app/assets/javascripts/ide/services/index.js @@ -1,23 +1,12 @@ -import getIdeProject from 'ee_else_ce/ide/queries/get_ide_project.query.graphql'; import Api from '~/api'; +import getIdeProject from 'ee_else_ce/ide/queries/get_ide_project.query.graphql'; import dismissUserCallout from '~/graphql_shared/mutations/dismiss_user_callout.mutation.graphql'; +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import axios from '~/lib/utils/axios_utils'; import { joinPaths, escapeFileUrl } from '~/lib/utils/url_utility'; import ciConfig from '~/pipeline_editor/graphql/queries/ci_config.query.graphql'; -import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { query, mutate } from './gql'; -const fetchApiProjectData = (projectPath) => Api.project(projectPath).then(({ data }) => data); - -const fetchGqlProjectData = (projectPath) => - query({ - query: getIdeProject, - variables: { projectPath }, - }).then(({ data }) => ({ - ...data.project, - id: getIdFromGraphQLId(data.project.id), - })); - export default { getFileData(endpoint) { return axios.get(endpoint, { @@ -65,18 +54,6 @@ export default { ) .then(({ data }) => data); }, - getProjectData(namespace, project) { - const projectPath = `${namespace}/${project}`; - - return Promise.all([fetchApiProjectData(projectPath), fetchGqlProjectData(projectPath)]).then( - ([apiProjectData, gqlProjectData]) => ({ - data: { - ...apiProjectData, - ...gqlProjectData, - }, - }), - ); - }, getProjectMergeRequests(projectId, params = {}) { return Api.projectMergeRequests(projectId, params); }, @@ -119,4 +96,13 @@ export default { variables: { input: { featureName: name } }, }).then(({ data }) => data); }, + getProjectPermissionsData(projectPath) { + return query({ + query: getIdeProject, + variables: { projectPath }, + }).then(({ data }) => ({ + ...data.project, + id: getIdFromGraphQLId(data.project.id), + })); + }, }; diff --git a/app/assets/javascripts/ide/stores/actions/project.js b/app/assets/javascripts/ide/stores/actions/project.js index 93ad19ba81e..0ec808339fb 100644 --- a/app/assets/javascripts/ide/stores/actions/project.js +++ b/app/assets/javascripts/ide/stores/actions/project.js @@ -1,35 +1,44 @@ import { escape } from 'lodash'; import createFlash from '~/flash'; import { __, sprintf } from '~/locale'; +import { logError } from '~/lib/logger'; import api from '../../../api'; import service from '../../services'; import * as types from '../mutation_types'; -export const getProjectData = ({ commit, state }, { namespace, projectId, force = false } = {}) => - new Promise((resolve, reject) => { - if (!state.projects[`${namespace}/${projectId}`] || force) { - commit(types.TOGGLE_LOADING, { entry: state }); - service - .getProjectData(namespace, projectId) - .then((res) => res.data) - .then((data) => { - commit(types.TOGGLE_LOADING, { entry: state }); - commit(types.SET_PROJECT, { projectPath: `${namespace}/${projectId}`, project: data }); - commit(types.SET_CURRENT_PROJECT, `${namespace}/${projectId}`); - resolve(data); - }) - .catch(() => { - createFlash({ - message: __('Error loading project data. Please try again.'), - fadeTransition: false, - addBodyClass: true, - }); - reject(new Error(`Project not loaded ${namespace}/${projectId}`)); - }); - } else { - resolve(state.projects[`${namespace}/${projectId}`]); - } +const ERROR_LOADING_PROJECT = __('Error loading project data. Please try again.'); + +const errorFetchingData = (e) => { + logError(ERROR_LOADING_PROJECT, e); + + createFlash({ + message: ERROR_LOADING_PROJECT, + fadeTransition: false, + addBodyClass: true, }); +}; + +export const setProject = ({ commit }, { project } = {}) => { + if (!project) { + return; + } + const projectPath = project.path_with_namespace; + commit(types.SET_PROJECT, { projectPath, project }); + commit(types.SET_CURRENT_PROJECT, projectPath); +}; + +export const fetchProjectPermissions = ({ commit, state }) => { + const projectPath = state.currentProjectId; + if (!projectPath) { + return undefined; + } + return service + .getProjectPermissionsData(projectPath) + .then((permissions) => { + commit(types.UPDATE_PROJECT, { projectPath, props: permissions }); + }) + .catch(errorFetchingData); +}; export const refreshLastCommitData = ({ commit }, { projectId, branchId } = {}) => service diff --git a/app/assets/javascripts/ide/stores/mutation_types.js b/app/assets/javascripts/ide/stores/mutation_types.js index 77755b179ef..13f338c4a48 100644 --- a/app/assets/javascripts/ide/stores/mutation_types.js +++ b/app/assets/javascripts/ide/stores/mutation_types.js @@ -8,6 +8,7 @@ export const SET_LINKS = 'SET_LINKS'; // Project Mutation Types export const SET_PROJECT = 'SET_PROJECT'; export const SET_CURRENT_PROJECT = 'SET_CURRENT_PROJECT'; +export const UPDATE_PROJECT = 'UPDATE_PROJECT'; export const TOGGLE_EMPTY_STATE = 'TOGGLE_EMPTY_STATE'; // Merge request mutation types diff --git a/app/assets/javascripts/ide/stores/mutations/project.js b/app/assets/javascripts/ide/stores/mutations/project.js index 034fdad4305..9f65d3a543e 100644 --- a/app/assets/javascripts/ide/stores/mutations/project.js +++ b/app/assets/javascripts/ide/stores/mutations/project.js @@ -1,3 +1,4 @@ +import Vue from 'vue'; import * as types from '../mutation_types'; export default { @@ -24,4 +25,15 @@ export default { empty_repo: value, }); }, + [types.UPDATE_PROJECT](state, { projectPath, props }) { + const project = state.projects[projectPath]; + + if (!project || !props) { + return; + } + + Object.keys(props).forEach((key) => { + Vue.set(project, key, props[key]); + }); + }, }; |