diff --git a/ee/app/assets/javascripts/remote_development/components/create/get_project_details_query.vue b/ee/app/assets/javascripts/remote_development/components/create/get_project_details_query.vue index 49f029ed4deff1dee161528ebc7d0af582ee71ec..5c6725273cd6f3f3baa8a5bbe116cc28ac10690b 100644 --- a/ee/app/assets/javascripts/remote_development/components/create/get_project_details_query.vue +++ b/ee/app/assets/javascripts/remote_development/components/create/get_project_details_query.vue @@ -1,6 +1,7 @@ @@ -28,7 +30,7 @@ export default { :svg-path="emptyStateSvgPath" > diff --git a/ee/app/assets/javascripts/remote_development/constants.js b/ee/app/assets/javascripts/remote_development/constants.js index ef80b96b831eadb3a39e0fa100ad9a0d83d13ebf..63444320203b81bb9bd50cabe2e974cf5ed3a593 100644 --- a/ee/app/assets/javascripts/remote_development/constants.js +++ b/ee/app/assets/javascripts/remote_development/constants.js @@ -1,4 +1,4 @@ -export const DEFAULT_DEVFILE_PATH = '.devfile'; +export const DEFAULT_DEVFILE_PATH = '.devfile.yaml'; export const DEFAULT_EDITOR = 'webide'; export const WORKSPACE_STATES = { // eslint-disable-next-line @gitlab/require-i18n-strings @@ -12,3 +12,9 @@ export const WORKSPACE_STATES = { // eslint-disable-next-line @gitlab/require-i18n-strings terminated: 'Terminated', }; +export const DEFAULT_DESIRED_STATE = WORKSPACE_STATES.running; + +export const ROUTES = { + index: 'index', + create: 'create', +}; diff --git a/ee/app/assets/javascripts/remote_development/graphql/fragments/workspace.fragment.graphql b/ee/app/assets/javascripts/remote_development/graphql/fragments/workspace.fragment.graphql deleted file mode 100644 index e582f359a1329038a297061b70c33053ac86360b..0000000000000000000000000000000000000000 --- a/ee/app/assets/javascripts/remote_development/graphql/fragments/workspace.fragment.graphql +++ /dev/null @@ -1,14 +0,0 @@ -fragment Workspace on Workspace { - id - name - namespace - desiredState - actualState - displayedState - url - editor - devfileRef - devfilePath - devfile - deploymentResourceVersion -} diff --git a/ee/app/assets/javascripts/remote_development/graphql/mutations/workspace_create.mutation.graphql b/ee/app/assets/javascripts/remote_development/graphql/mutations/workspace_create.mutation.graphql index 43109bf4d06755cf51d29e806c7c0742d065e197..a5f2395ab7c427677114b66510027c7fe71ae41b 100644 --- a/ee/app/assets/javascripts/remote_development/graphql/mutations/workspace_create.mutation.graphql +++ b/ee/app/assets/javascripts/remote_development/graphql/mutations/workspace_create.mutation.graphql @@ -1,10 +1,5 @@ -#import "../fragments/workspace.fragment.graphql" - mutation workspaceCreate($input: WorkspaceCreateInput!) { workspaceCreate(input: $input) @client { - workspace { - ...Workspace - } errors } } diff --git a/ee/app/assets/javascripts/remote_development/graphql/queries/get_group_cluster_agents.query.graphql b/ee/app/assets/javascripts/remote_development/graphql/queries/get_group_cluster_agents.query.graphql new file mode 100644 index 0000000000000000000000000000000000000000..5d4bf35f944b50713b5642c44b6f5ae43fbe6b13 --- /dev/null +++ b/ee/app/assets/javascripts/remote_development/graphql/queries/get_group_cluster_agents.query.graphql @@ -0,0 +1,11 @@ +query getGroupClusterAgents($groupPath: ID!) { + group(fullPath: $groupPath) { + id + clusterAgents { + nodes { + id + name + } + } + } +} diff --git a/ee/app/assets/javascripts/remote_development/graphql/queries/get_project_details.query.graphql b/ee/app/assets/javascripts/remote_development/graphql/queries/get_project_details.query.graphql index 300ecc3169935c26f3b1743eb56b36d4d2a31014..28305474687646e7099e8276fc2b10375bb04a59 100644 --- a/ee/app/assets/javascripts/remote_development/graphql/queries/get_project_details.query.graphql +++ b/ee/app/assets/javascripts/remote_development/graphql/queries/get_project_details.query.graphql @@ -4,14 +4,9 @@ query getProjectDetails($projectFullPath: ID!, $devFilePath: String!) { group { id fullPath - clusterAgents { - nodes { - id - name - } - } } repository { + rootRef blobs(paths: [$devFilePath]) { nodes { id diff --git a/ee/app/assets/javascripts/remote_development/init_workspaces_app.js b/ee/app/assets/javascripts/remote_development/init_workspaces_app.js index 797526a1526fc8aa971a40b81858d45106e97ed0..990675c86b390c20a2a717c3b8206677c3c8cb7c 100644 --- a/ee/app/assets/javascripts/remote_development/init_workspaces_app.js +++ b/ee/app/assets/javascripts/remote_development/init_workspaces_app.js @@ -8,41 +8,7 @@ import userWorkspacesListQuery from './graphql/queries/user_workspaces_list.quer Vue.use(VueApollo); const createApolloProvider = () => { - /* - * This is dummy data used to support frontend development - * while the backend APIs are in development. - */ - const resolvers = { - Mutation: { - workspaceCreate: () => { - return { - workspace: { - id: 1, - // eslint-disable-next-line @gitlab/require-i18n-strings - name: 'Workspace 1', - // eslint-disable-next-line @gitlab/require-i18n-strings - namespace: 'Namespace', - projectFullPath: 'GitLab.org / GitLab', - // eslint-disable-next-line @gitlab/require-i18n-strings - desiredState: 'Running', - // eslint-disable-next-line @gitlab/require-i18n-strings - actualState: 'Started', - // eslint-disable-next-line @gitlab/require-i18n-strings - displayedState: 'Started', - url: 'https://gdk.test:3443', - // eslint-disable-next-line @gitlab/require-i18n-strings - editor: 'VSCode', - devfile: 'devfile', - branch: 'master', - lastUsed: '2020-01-01T00:00:00.000Z', - }, - errors: [], - }; - }, - }, - }; - - const defaultClient = createDefaultClient(resolvers); + const defaultClient = createDefaultClient(); // what: Dummy data to support development defaultClient.cache.writeQuery({ query: userWorkspacesListQuery, diff --git a/ee/app/assets/javascripts/remote_development/pages/create.vue b/ee/app/assets/javascripts/remote_development/pages/create.vue index 22e0c48ee3c3ac7aacef6360a5593a220fead3e7..f445386e9c0080d495983163379e7327d5fe9784 100644 --- a/ee/app/assets/javascripts/remote_development/pages/create.vue +++ b/ee/app/assets/javascripts/remote_development/pages/create.vue @@ -2,13 +2,12 @@ import { GlAlert, GlButton, GlForm, GlFormGroup, GlFormSelect } from '@gitlab/ui'; import { s__ } from '~/locale'; import { createAlert } from '~/alert'; -import { visitUrl } from '~/lib/utils/url_utility'; import { logError } from '~/lib/logger'; import { helpPagePath } from '~/helpers/help_page_helper'; import SearchProjectsListbox from '../components/create/search_projects_listbox.vue'; import GetProjectDetailsQuery from '../components/create/get_project_details_query.vue'; import workspaceCreateMutation from '../graphql/mutations/workspace_create.mutation.graphql'; -import { DEFAULT_EDITOR } from '../constants'; +import { DEFAULT_DESIRED_STATE, DEFAULT_DEVFILE_PATH, DEFAULT_EDITOR, ROUTES } from '../constants'; export const i18n = { title: s__('Workspaces|New workspace'), @@ -23,19 +22,14 @@ export const i18n = { devfileProjectHelp: s__('Workspaces|You can create a workspace for Premium projects only.'), }, }, - alerts: { - noAgents: { - title: s__("Workspaces|You can't create a workspace for this project"), - content: s__( - "Workspaces|To create a workspace for this project, an administrator must configure an agent for the project's group.", - ), - }, - noDevFile: { - title: s__("Workspaces|This project doesn't have a devfile"), - content: s__( - 'Workspaces|A devfile is a configuration file for your workspace. Without a devfile, a default workspace is created for this project. You can change that workspace at any time.', - ), - }, + invalidProjectAlert: { + title: s__("Workspaces|You can't create a workspace for this project"), + noAgentsContent: s__( + "Workspaces|To create a workspace for this project, an administrator must configure an agent for the project's group.", + ), + noDevFileContent: s__( + 'Workspaces|To create a workspace, add a devfile to this project. A devfile is a configuration file for your workspace.', + ), }, submitButton: { create: s__('Workspaces|Create workspace'), @@ -63,9 +57,10 @@ export default { selectedAgent: null, isCreatingWorkspace: false, clusterAgents: [], - hasDevFile: true, + hasDevFile: null, groupPath: null, projectId: null, + rootRef: null, projectDetailsLoaded: false, }; }, @@ -80,7 +75,7 @@ export default { return this.projectDetailsLoaded && !this.displayClusterAgentsAlert && !this.hasDevFile; }, saveWorkspaceEnabled() { - return this.selectedProject && this.selectedAgent; + return this.selectedProject && this.selectedAgent && this.hasDevFile; }, workspacesHelpPath() { return helpPagePath('user/project/remote_development/index', { anchor: 'workspace' }); @@ -97,12 +92,13 @@ export default { }, }, methods: { - onProjectDetailsResult({ hasDevFile, clusterAgents, groupPath, id }) { + onProjectDetailsResult({ hasDevFile, clusterAgents, groupPath, id, rootRef }) { this.projectDetailsLoaded = true; this.hasDevFile = hasDevFile; this.clusterAgents = clusterAgents; this.groupPath = groupPath; this.projectId = id; + this.rootRef = rootRef; }, onProjectDetailsError() { createAlert({ message: i18n.fetchProjectDetailsFailedMessage }); @@ -111,7 +107,7 @@ export default { try { this.isCreatingWorkspace = true; - const { data } = await this.$apollo.mutate({ + const result = await this.$apollo.mutate({ mutation: workspaceCreateMutation, variables: { input: { @@ -119,18 +115,21 @@ export default { groupPath: this.groupPath, clusterAgentId: this.selectedAgent, editor: DEFAULT_EDITOR, + desiredState: DEFAULT_DESIRED_STATE, + devfilePath: DEFAULT_DEVFILE_PATH, + devfileRef: this.rootRef, }, }, }); - const { errors, workspace } = data.workspaceCreate; + const { errors } = result.data.workspaceCreate; if (errors.length > 0) { createAlert({ message: errors[0] }); return; } - visitUrl(workspace.url); + this.$router.push(ROUTES.index); } catch (error) { logError(error); createAlert({ message: i18n.createWorkspaceFailedMessage }); @@ -140,6 +139,7 @@ export default { }, }, i18n, + ROUTES, };