Commit 0a234010 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'fc-fix-graph-to-work-with-nodes' into 'master'

Fix CI viz to work with new nodes structure

See merge request gitlab-org/gitlab!50273
parents 7f0e569d 327901bd
...@@ -102,11 +102,11 @@ export default { ...@@ -102,11 +102,11 @@ export default {
}; };
}, },
update(data) { update(data) {
const { ciConfigData } = data || {}; const { ciConfig } = data || {};
const stageNodes = ciConfigData?.stages?.nodes || []; const stageNodes = ciConfig?.stages?.nodes || [];
const stages = unwrapStagesWithNeeds(stageNodes); const stages = unwrapStagesWithNeeds(stageNodes);
return { ...ciConfigData, stages }; return { ...ciConfig, stages };
}, },
error() { error() {
this.reportFailure(LOAD_FAILURE_UNKNOWN); this.reportFailure(LOAD_FAILURE_UNKNOWN);
......
...@@ -47,8 +47,11 @@ export default { ...@@ -47,8 +47,11 @@ export default {
}; };
}, },
computed: { computed: {
pipelineStages() {
return this.pipelineData?.stages || [];
},
isPipelineDataEmpty() { isPipelineDataEmpty() {
return !this.isInvalidCiConfig && isEmpty(this.pipelineData?.stages); return !this.isInvalidCiConfig && isEmpty(this.pipelineStages);
}, },
isInvalidCiConfig() { isInvalidCiConfig() {
return this.pipelineData?.status === CI_CONFIG_STATUS_INVALID; return this.pipelineData?.status === CI_CONFIG_STATUS_INVALID;
...@@ -133,7 +136,7 @@ export default { ...@@ -133,7 +136,7 @@ export default {
methods: { methods: {
prepareLinkData() { prepareLinkData() {
try { try {
const arrayOfJobs = unwrapArrayOfJobs(this.pipelineData); const arrayOfJobs = unwrapArrayOfJobs(this.pipelineStages);
const parsedData = parseData(arrayOfJobs); const parsedData = parseData(arrayOfJobs);
this.links = generateLinksData(parsedData, this.$options.CONTAINER_ID); this.links = generateLinksData(parsedData, this.$options.CONTAINER_ID);
} catch { } catch {
...@@ -141,7 +144,7 @@ export default { ...@@ -141,7 +144,7 @@ export default {
} }
}, },
getStageBackgroundClasses(index) { getStageBackgroundClasses(index) {
const { length } = this.pipelineData.stages; const { length } = this.pipelineStages;
// It's possible for a graph to have only one stage, in which // It's possible for a graph to have only one stage, in which
// case we concatenate both the left and right rounding classes // case we concatenate both the left and right rounding classes
if (length === 1) { if (length === 1) {
...@@ -162,7 +165,7 @@ export default { ...@@ -162,7 +165,7 @@ export default {
// The first time we hover, we create the object where // The first time we hover, we create the object where
// we store all the data to properly highlight the needs. // we store all the data to properly highlight the needs.
if (!this.needsObject) { if (!this.needsObject) {
const jobs = createJobsHash(this.pipelineData); const jobs = createJobsHash(this.pipelineStages);
this.needsObject = generateJobNeedsDict(jobs) ?? {}; this.needsObject = generateJobNeedsDict(jobs) ?? {};
} }
...@@ -227,7 +230,7 @@ export default { ...@@ -227,7 +230,7 @@ export default {
</template> </template>
</svg> </svg>
<div <div
v-for="(stage, index) in pipelineData.stages" v-for="(stage, index) in pipelineStages"
:key="`${stage.name}-${index}`" :key="`${stage.name}-${index}`"
class="gl-flex-direction-column" class="gl-flex-direction-column"
> >
......
...@@ -78,18 +78,12 @@ export const pipelineData = { ...@@ -78,18 +78,12 @@ export const pipelineData = {
groups: [ groups: [
{ {
name: 'deploy_1', name: 'deploy_1',
jobs: [{ script: 'yarn magick', stage: 'deploy' }], jobs: [{ script: 'yarn magick', stage: 'deploy', needs: ['test_1'] }],
id: jobId4, id: jobId4,
}, },
], ],
}, },
], ],
jobs: {
[jobId1]: {},
[jobId2]: {},
[jobId3]: {},
[jobId4]: {},
},
}; };
export const singleStageData = { export const singleStageData = {
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import { pipelineData, singleStageData } from './mock_data'; import { pipelineData, singleStageData } from './mock_data';
import { CI_CONFIG_STATUS_INVALID } from '~/pipeline_editor/constants'; import { CI_CONFIG_STATUS_INVALID, CI_CONFIG_STATUS_VALID } from '~/pipeline_editor/constants';
import { DRAW_FAILURE, EMPTY_PIPELINE_DATA, INVALID_CI_CONFIG } from '~/pipelines/constants'; import { DRAW_FAILURE, EMPTY_PIPELINE_DATA, INVALID_CI_CONFIG } from '~/pipelines/constants';
import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue'; import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue';
import StagePill from '~/pipelines/components/pipeline_graph/stage_pill.vue'; import StagePill from '~/pipelines/components/pipeline_graph/stage_pill.vue';
...@@ -56,18 +56,20 @@ describe('pipeline graph component', () => { ...@@ -56,18 +56,20 @@ describe('pipeline graph component', () => {
}); });
}); });
describe('without `INVALID` status', () => { describe('with `VALID` status', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent({
pipelineData: { status: CI_CONFIG_STATUS_VALID, stages: [{ name: 'hello', groups: [] }] },
});
}); });
it('renders the graph with no status error', () => { it('renders the graph with no status error', () => {
expect(findAlert().text()).not.toBe(wrapper.vm.$options.warningTexts[INVALID_CI_CONFIG]); expect(findAlert().exists()).toBe(false);
expect(findPipelineGraph().exists()).toBe(true); expect(findPipelineGraph().exists()).toBe(true);
}); });
}); });
describe('with error while rendering the links', () => { describe('with error while rendering the links with needs', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent();
}); });
......
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