Commit 0821a25c authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '326685-vsa-reorder-stage-animation' into 'master'

[VSA] Reorder stage animation

See merge request gitlab-org/gitlab!64392
parents de583357 c2af91e9
<script> <script>
import { GlButton, GlForm, GlFormInput, GlFormGroup, GlFormRadioGroup, GlModal } from '@gitlab/ui'; import { GlButton, GlForm, GlFormInput, GlFormGroup, GlFormRadioGroup, GlModal } from '@gitlab/ui';
import { cloneDeep } from 'lodash'; import { cloneDeep, uniqueId } from 'lodash';
import Vue from 'vue'; import Vue from 'vue';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { filterStagesByHiddenStatus } from '~/cycle_analytics/utils'; import { filterStagesByHiddenStatus } from '~/cycle_analytics/utils';
...@@ -26,10 +26,14 @@ import { ...@@ -26,10 +26,14 @@ import {
const initializeStageErrors = (defaultStageConfig, selectedPreset = PRESET_OPTIONS_DEFAULT) => const initializeStageErrors = (defaultStageConfig, selectedPreset = PRESET_OPTIONS_DEFAULT) =>
selectedPreset === PRESET_OPTIONS_DEFAULT ? defaultStageConfig.map(() => ({})) : [{}]; selectedPreset === PRESET_OPTIONS_DEFAULT ? defaultStageConfig.map(() => ({})) : [{}];
const initializeStages = (defaultStageConfig, selectedPreset = PRESET_OPTIONS_DEFAULT) => const initializeStages = (defaultStageConfig, selectedPreset = PRESET_OPTIONS_DEFAULT) => {
selectedPreset === PRESET_OPTIONS_DEFAULT const stages =
? defaultStageConfig selectedPreset === PRESET_OPTIONS_DEFAULT
: [{ ...defaultCustomStageFields }]; ? defaultStageConfig
: [{ ...defaultCustomStageFields }];
return stages.map((stage) => ({ ...stage, transitionKey: uniqueId('stage-') }));
};
export default { export default {
name: 'ValueStreamForm', name: 'ValueStreamForm',
...@@ -85,6 +89,7 @@ export default { ...@@ -85,6 +89,7 @@ export default {
stageErrors: stageErrors:
cloneDeep(stageErrors) || initializeStageErrors(defaultStageConfig, initialPreset), cloneDeep(stageErrors) || initializeStageErrors(defaultStageConfig, initialPreset),
}; };
return { return {
hiddenStages: filterStagesByHiddenStatus(initialStages), hiddenStages: filterStagesByHiddenStatus(initialStages),
selectedPreset: initialPreset, selectedPreset: initialPreset,
...@@ -179,11 +184,6 @@ export default { ...@@ -179,11 +184,6 @@ export default {
} }
}); });
}, },
stageKey(index) {
return this.selectedPreset === PRESET_OPTIONS_DEFAULT
? `default-template-stage-${index}`
: `custom-template-stage-${index}`;
},
stageGroupLabel(index) { stageGroupLabel(index) {
return sprintf(this.$options.i18n.STAGE_INDEX, { index: index + 1 }); return sprintf(this.$options.i18n.STAGE_INDEX, { index: index + 1 });
}, },
...@@ -249,7 +249,10 @@ export default { ...@@ -249,7 +249,10 @@ export default {
addNewStage() { addNewStage() {
// validate previous stages only and add a new stage // validate previous stages only and add a new stage
this.validate(); this.validate();
Vue.set(this, 'stages', [...this.stages, { ...defaultCustomStageFields }]); Vue.set(this, 'stages', [
...this.stages,
{ ...defaultCustomStageFields, transitionKey: uniqueId('stage-') },
]);
Vue.set(this, 'stageErrors', [...this.stageErrors, {}]); Vue.set(this, 'stageErrors', [...this.stageErrors, {}]);
}, },
onAddStage() { onAddStage() {
...@@ -351,39 +354,41 @@ export default { ...@@ -351,39 +354,41 @@ export default {
@input="onSelectPreset" @input="onSelectPreset"
/> />
<div data-testid="extended-form-fields"> <div data-testid="extended-form-fields">
<div <transition-group name="stage-list" tag="div">
v-for="(stage, activeStageIndex) in stages" <div
ref="formStages" v-for="(stage, activeStageIndex) in stages"
:key="stageKey(activeStageIndex)" ref="formStages"
> :key="stage.id || stage.transitionKey"
<hr class="gl-my-3" />
<span
class="gl-display-flex gl-m-0 gl-vertical-align-middle gl-mr-2 gl-font-weight-bold gl-display-flex gl-pb-3"
>{{ stageGroupLabel(activeStageIndex) }}</span
> >
<custom-stage-fields <hr class="gl-my-3" />
v-if="stage.custom" <span
:stage="stage" class="gl-display-flex gl-m-0 gl-vertical-align-middle gl-mr-2 gl-font-weight-bold gl-display-flex gl-pb-3"
:stage-events="formEvents" >{{ stageGroupLabel(activeStageIndex) }}</span
:index="activeStageIndex" >
:total-stages="stages.length" <custom-stage-fields
:errors="fieldErrors(activeStageIndex)" v-if="stage.custom"
@move="handleMove" :stage="stage"
@remove="onRemove" :stage-events="formEvents"
@input="onFieldInput(activeStageIndex, $event)" :index="activeStageIndex"
/> :total-stages="stages.length"
<default-stage-fields :errors="fieldErrors(activeStageIndex)"
v-else @move="handleMove"
:stage="stage" @remove="onRemove"
:stage-events="formEvents" @input="onFieldInput(activeStageIndex, $event)"
:index="activeStageIndex" />
:total-stages="stages.length" <default-stage-fields
:errors="fieldErrors(activeStageIndex)" v-else
@move="handleMove" :stage="stage"
@hide="onHide" :stage-events="formEvents"
@input="validateStageFields(activeStageIndex)" :index="activeStageIndex"
/> :total-stages="stages.length"
</div> :errors="fieldErrors(activeStageIndex)"
@move="handleMove"
@hide="onHide"
@input="validateStageFields(activeStageIndex)"
/>
</div>
</transition-group>
<div v-if="hiddenStages.length"> <div v-if="hiddenStages.length">
<hr /> <hr />
<gl-form-group <gl-form-group
......
...@@ -54,3 +54,7 @@ ...@@ -54,3 +54,7 @@
flex: 0 0 20%; flex: 0 0 20%;
} }
} }
.stage-list-move {
transition: transform 0.15s;
}
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