diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-02 12:10:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-02 12:10:59 +0300 |
commit | 78bc39880c4b06b2fbe682e0201722a11237a425 (patch) | |
tree | 00500cb71d9e86a404ec42264cc3b4992e5610ce /app/assets/javascripts/environments | |
parent | 377b57afa8292caa96921fac7daf6279e12304de (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/environments')
-rw-r--r-- | app/assets/javascripts/environments/components/new_environments_app.vue | 12 | ||||
-rw-r--r-- | app/assets/javascripts/environments/graphql/client.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/environments/graphql/queries/environment_app.query.graphql (renamed from app/assets/javascripts/environments/graphql/queries/environmentApp.query.graphql) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/environments/graphql/queries/poll_interval.query.graphql | 3 | ||||
-rw-r--r-- | app/assets/javascripts/environments/graphql/resolvers.js | 83 | ||||
-rw-r--r-- | app/assets/javascripts/environments/graphql/typedefs.graphql | 17 |
6 files changed, 98 insertions, 19 deletions
diff --git a/app/assets/javascripts/environments/components/new_environments_app.vue b/app/assets/javascripts/environments/components/new_environments_app.vue index a5526f9cd71..bfb5689d623 100644 --- a/app/assets/javascripts/environments/components/new_environments_app.vue +++ b/app/assets/javascripts/environments/components/new_environments_app.vue @@ -1,6 +1,7 @@ <script> import { GlBadge, GlTab, GlTabs } from '@gitlab/ui'; -import environmentAppQuery from '../graphql/queries/environmentApp.query.graphql'; +import environmentAppQuery from '../graphql/queries/environment_app.query.graphql'; +import pollIntervalQuery from '../graphql/queries/poll_interval.query.graphql'; import EnvironmentFolder from './new_environment_folder.vue'; export default { @@ -13,7 +14,16 @@ export default { apollo: { environmentApp: { query: environmentAppQuery, + pollInterval() { + return this.interval; + }, }, + interval: { + query: pollIntervalQuery, + }, + }, + data() { + return { interval: undefined }; }, computed: { folders() { diff --git a/app/assets/javascripts/environments/graphql/client.js b/app/assets/javascripts/environments/graphql/client.js index c734c2fba0c..c019b4d16f3 100644 --- a/app/assets/javascripts/environments/graphql/client.js +++ b/app/assets/javascripts/environments/graphql/client.js @@ -1,6 +1,6 @@ import VueApollo from 'vue-apollo'; import createDefaultClient from '~/lib/graphql'; -import environmentApp from './queries/environmentApp.query.graphql'; +import environmentApp from './queries/environment_app.query.graphql'; import { resolvers } from './resolvers'; import typeDefs from './typedefs.graphql'; diff --git a/app/assets/javascripts/environments/graphql/queries/environmentApp.query.graphql b/app/assets/javascripts/environments/graphql/queries/environment_app.query.graphql index faa76c0a42c..faa76c0a42c 100644 --- a/app/assets/javascripts/environments/graphql/queries/environmentApp.query.graphql +++ b/app/assets/javascripts/environments/graphql/queries/environment_app.query.graphql diff --git a/app/assets/javascripts/environments/graphql/queries/poll_interval.query.graphql b/app/assets/javascripts/environments/graphql/queries/poll_interval.query.graphql new file mode 100644 index 00000000000..28afc30a0dd --- /dev/null +++ b/app/assets/javascripts/environments/graphql/queries/poll_interval.query.graphql @@ -0,0 +1,3 @@ +query pollInterval { + interval @client +} diff --git a/app/assets/javascripts/environments/graphql/resolvers.js b/app/assets/javascripts/environments/graphql/resolvers.js index 8322b806370..9bb00f92ac4 100644 --- a/app/assets/javascripts/environments/graphql/resolvers.js +++ b/app/assets/javascripts/environments/graphql/resolvers.js @@ -1,5 +1,12 @@ import axios from '~/lib/utils/axios_utils'; +import { s__ } from '~/locale'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import pollIntervalQuery from './queries/poll_interval.query.graphql'; + +const buildErrors = (errors = []) => ({ + errors, + __typename: 'LocalEnvironmentErrors', +}); const mapNestedEnvironment = (env) => ({ ...convertObjectPropsToCamelCase(env, { deep: true }), @@ -12,17 +19,27 @@ const mapEnvironment = (env) => ({ export const resolvers = (endpoint) => ({ Query: { - environmentApp() { - return axios.get(endpoint, { params: { nested: true } }).then((res) => ({ - availableCount: res.data.available_count, - environments: res.data.environments.map(mapNestedEnvironment), - reviewApp: { - ...convertObjectPropsToCamelCase(res.data.review_app), - __typename: 'ReviewApp', - }, - stoppedCount: res.data.stopped_count, - __typename: 'LocalEnvironmentApp', - })); + environmentApp(_context, _variables, { cache }) { + return axios.get(endpoint, { params: { nested: true } }).then((res) => { + const interval = res.headers['poll-interval']; + + if (interval) { + cache.writeQuery({ query: pollIntervalQuery, data: { interval } }); + } else { + cache.writeQuery({ query: pollIntervalQuery, data: { interval: undefined } }); + } + + return { + availableCount: res.data.available_count, + environments: res.data.environments.map(mapNestedEnvironment), + reviewApp: { + ...convertObjectPropsToCamelCase(res.data.review_app), + __typename: 'ReviewApp', + }, + stoppedCount: res.data.stopped_count, + __typename: 'LocalEnvironmentApp', + }; + }); }, folder(_, { environment: { folderPath } }) { return axios.get(folderPath, { params: { per_page: 3 } }).then((res) => ({ @@ -32,19 +49,51 @@ export const resolvers = (endpoint) => ({ __typename: 'LocalEnvironmentFolder', })); }, + isLastDeployment(_, { environment }) { + // eslint-disable-next-line @gitlab/require-i18n-strings + return environment?.lastDeployment?.['last?']; + }, }, - Mutations: { - stopEnvironment(_, { environment: { stopPath } }) { - return axios.post(stopPath); + Mutation: { + stopEnvironment(_, { environment }) { + return axios + .post(environment.stopPath) + .then(() => buildErrors()) + .catch(() => { + return buildErrors([ + s__('Environments|An error occurred while stopping the environment, please try again'), + ]); + }); }, deleteEnvironment(_, { environment: { deletePath } }) { return axios.delete(deletePath); }, - rollbackEnvironment(_, { environment: { retryUrl } }) { - return axios.post(retryUrl); + rollbackEnvironment(_, { environment, isLastDeployment }) { + return axios + .post(environment?.retryUrl) + .then(() => buildErrors()) + .catch(() => { + buildErrors([ + isLastDeployment + ? s__( + 'Environments|An error occurred while re-deploying the environment, please try again', + ) + : s__( + 'Environments|An error occurred while rolling back the environment, please try again', + ), + ]); + }); }, cancelAutoStop(_, { environment: { autoStopPath } }) { - return axios.post(autoStopPath); + return axios + .post(autoStopPath) + .then(() => buildErrors()) + .catch((err) => + buildErrors([ + err?.response?.data?.message || + s__('Environments|An error occurred while canceling the auto stop, please try again'), + ]), + ); }, }, }); diff --git a/app/assets/javascripts/environments/graphql/typedefs.graphql b/app/assets/javascripts/environments/graphql/typedefs.graphql index 49ea719449e..f0172765ebe 100644 --- a/app/assets/javascripts/environments/graphql/typedefs.graphql +++ b/app/assets/javascripts/environments/graphql/typedefs.graphql @@ -33,3 +33,20 @@ type LocalEnvironmentApp { environments: [NestedLocalEnvironment!]! reviewApp: ReviewApp! } + +type LocalErrors { + errors: [String!]! +} + +extend type Query { + environmentApp: LocalEnvironmentApp + folder(environment: NestedLocalEnvironment): LocalEnvironmentFolder + isLastDeployment: Boolean +} + +extend type Mutation { + stopEnvironment(environment: LocalEnvironment): LocalErrors + deleteEnvironment(environment: LocalEnvironment): LocalErrors + rollbackEnvironment(environment: LocalEnvironment): LocalErrors + cancelAutoStop(environment: LocalEnvironment): LocalErrors +} |