Commit c9d676c1 authored by Phil Hughes's avatar Phil Hughes

changed mutations, update single object instead of returning new array

bunch of i18n stuff 🙈
parent 6c9844c1
<script> <script>
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import _ from 'underscore';
import { sprintf, __ } from '../../../locale'; import { sprintf, __ } from '../../../locale';
import LoadingIcon from '../../../vue_shared/components/loading_icon.vue'; import LoadingIcon from '../../../vue_shared/components/loading_icon.vue';
import Icon from '../../../vue_shared/components/icon.vue'; import Icon from '../../../vue_shared/components/icon.vue';
...@@ -28,12 +29,15 @@ export default { ...@@ -28,12 +29,15 @@ export default {
return sprintf( return sprintf(
__('You can also test your .gitlab-ci.yml in the %{linkStart}Lint%{linkEnd}'), __('You can also test your .gitlab-ci.yml in the %{linkStart}Lint%{linkEnd}'),
{ {
linkStart: `<a href="${this.currentProject.web_url}/-/ci/lint">`, linkStart: `<a href="${_.escape(this.currentProject.web_url)}/-/ci/lint">`,
linkEnd: '</a>', linkEnd: '</a>',
}, },
false, false,
); );
}, },
showLoadingIcon() {
return this.isLoadingPipeline && this.latestPipeline === null;
},
}, },
created() { created() {
this.fetchLatestPipeline(); this.fetchLatestPipeline();
...@@ -47,7 +51,7 @@ export default { ...@@ -47,7 +51,7 @@ export default {
<template> <template>
<div class="ide-pipeline"> <div class="ide-pipeline">
<loading-icon <loading-icon
v-if="isLoadingPipeline && latestPipeline === null" v-if="showLoadingIcon"
class="prepend-top-default" class="prepend-top-default"
size="2" size="2"
/> />
...@@ -62,7 +66,7 @@ export default { ...@@ -62,7 +66,7 @@ export default {
/> />
<span class="prepend-left-8"> <span class="prepend-left-8">
<strong> <strong>
Pipeline {{ __('Pipeline') }}
</strong> </strong>
<a <a
:href="latestPipeline.path" :href="latestPipeline.path"
...@@ -88,7 +92,7 @@ export default { ...@@ -88,7 +92,7 @@ export default {
class="bs-callout bs-callout-danger" class="bs-callout bs-callout-danger"
> >
<p class="append-bottom-0"> <p class="append-bottom-0">
Found errors in your .gitlab-ci.yml: {{ __('Found errors in your .gitlab-ci.yml:') }}
</p> </p>
<p class="append-bottom-0"> <p class="append-bottom-0">
{{ latestPipeline.yamlError }} {{ latestPipeline.yamlError }}
...@@ -106,7 +110,7 @@ export default { ...@@ -106,7 +110,7 @@ export default {
:active="!pipelineFailed" :active="!pipelineFailed"
> >
<template slot="title"> <template slot="title">
Jobs {{ __('Jobs') }}
<span <span
v-if="jobsCount" v-if="jobsCount"
class="badge badge-pill" class="badge badge-pill"
...@@ -123,7 +127,7 @@ export default { ...@@ -123,7 +127,7 @@ export default {
:active="pipelineFailed" :active="pipelineFailed"
> >
<template slot="title"> <template slot="title">
Failed Jobs {{ __('Failed Jobs') }}
<span <span
v-if="failedJobsCount" v-if="failedJobsCount"
class="badge badge-pill" class="badge badge-pill"
......
// eslint-disable-next-line import/prefer-default-export
export const states = {
failed: 'failed',
};
import { states } from './constants';
export const hasLatestPipeline = state => !state.isLoadingPipeline && !!state.latestPipeline; export const hasLatestPipeline = state => !state.isLoadingPipeline && !!state.latestPipeline;
export const pipelineFailed = state => export const pipelineFailed = state =>
state.latestPipeline && state.latestPipeline.details.status.text === 'failed'; state.latestPipeline && state.latestPipeline.details.status.text === states.failed;
export const failedStages = state => export const failedStages = state =>
state.stages.filter(stage => stage.status.text.toLowerCase() === 'failed').map(stage => ({ state.stages.filter(stage => stage.status.text.toLowerCase() === states.failed).map(stage => ({
...stage, ...stage,
jobs: stage.jobs.filter(job => job.status.text.toLowerCase() === 'failed'), jobs: stage.jobs.filter(job => job.status.text.toLowerCase() === states.failed),
})); }));
export const failedJobsCount = state => export const failedJobsCount = state =>
state.stages.reduce( state.stages.reduce(
(acc, stage) => acc + stage.jobs.filter(j => j.status.text === 'failed').length, (acc, stage) => acc + stage.jobs.filter(j => j.status.text === states.failed).length,
0, 0,
); );
export const jobsCount = state => state.stages.reduce((acc, stage) => acc + stage.jobs.length, 0); export const jobsCount = state => state.stages.reduce((acc, stage) => acc + stage.jobs.length, 0);
export default () => {};
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
import * as types from './mutation_types'; import * as types from './mutation_types';
import { normalizeJob } from './utils';
export default { export default {
[types.REQUEST_LATEST_PIPELINE](state) { [types.REQUEST_LATEST_PIPELINE](state) {
...@@ -38,39 +39,20 @@ export default { ...@@ -38,39 +39,20 @@ export default {
} }
}, },
[types.REQUEST_JOBS](state, id) { [types.REQUEST_JOBS](state, id) {
state.stages = state.stages.map(stage => const stage = state.stages.find(s => s.id === id);
Object.assign(stage, { stage.isLoading = true;
isLoading: id === stage.id ? true : stage.isLoading,
}),
);
}, },
[types.RECEIVE_JOBS_ERROR](state, id) { [types.RECEIVE_JOBS_ERROR](state, id) {
state.stages = state.stages.map(stage => const stage = state.stages.find(s => s.id === id);
Object.assign(stage, { stage.isLoading = false;
isLoading: id === stage.id ? false : stage.isLoading,
}),
);
}, },
[types.RECEIVE_JOBS_SUCCESS](state, { id, data }) { [types.RECEIVE_JOBS_SUCCESS](state, { id, data }) {
const normalizeData = job => ({ const stage = state.stages.find(s => s.id === id);
id: job.id, stage.isLoading = false;
name: job.name, stage.jobs = data.latest_statuses.map(normalizeJob);
status: job.status,
path: job.build_path,
});
state.stages = state.stages.map(stage =>
Object.assign(stage, {
isLoading: id === stage.id ? false : stage.isLoading,
jobs: id === stage.id ? data.latest_statuses.map(normalizeData) : stage.jobs,
}),
);
}, },
[types.TOGGLE_STAGE_COLLAPSE](state, id) { [types.TOGGLE_STAGE_COLLAPSE](state, id) {
state.stages = state.stages.map(stage => const stage = state.stages.find(s => s.id === id);
Object.assign(stage, { stage.isCollapsed = !stage.isCollapsed;
isCollapsed: stage.id === id ? !stage.isCollapsed : stage.isCollapsed,
}),
);
}, },
}; };
// eslint-disable-next-line import/prefer-default-export
export const normalizeJob = job => ({
id: job.id,
name: job.name,
status: job.status,
path: job.build_path,
});
...@@ -16,14 +16,18 @@ describe('IDE pipeline stage', () => { ...@@ -16,14 +16,18 @@ describe('IDE pipeline stage', () => {
const store = createStore(); const store = createStore();
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
store.state.pipelines.stages = stages.map((mappedState, i) => ({ Vue.set(
...mappedState, store.state.pipelines,
id: i, 'stages',
dropdownPath: mappedState.dropdown_path, stages.map((mappedState, i) => ({
jobs: [], ...mappedState,
isLoading: false, id: i,
isCollapsed: false, dropdownPath: mappedState.dropdown_path,
})); jobs: [],
isLoading: false,
isCollapsed: false,
})),
);
stage = store.state.pipelines.stages[0]; stage = store.state.pipelines.stages[0];
...@@ -35,7 +39,7 @@ describe('IDE pipeline stage', () => { ...@@ -35,7 +39,7 @@ describe('IDE pipeline stage', () => {
stage, stage,
}).$mount(); }).$mount();
setTimeout(done); setTimeout(done, 500);
}); });
afterEach(() => { afterEach(() => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment