Skip to content

Commit

Permalink
fix(step-form-component): provide step form defaults and preselect co…
Browse files Browse the repository at this point in the history
…lumn if necessary in complex steps [TCTC-9437] (#2251)

* fix(step-form-component): provide step form defaults and preselect column if necessary in complex steps

* fix: lint
  • Loading branch information
alice-sevin authored Sep 27, 2024
1 parent 3852692 commit 99c0ffc
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ui/src/components/stepforms/StepFormComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ref="step"
:translator="translator"
:initialStepValue="initialStepValue"
:stepFormDefaults="stepFormDefaults"
:isStepCreation="isStepCreation"
:columnTypes="columnTypes"
:backendError="backendError"
Expand Down Expand Up @@ -89,6 +90,10 @@ export default class StepFormComponent extends Vue {
pipelineNameOrDomain: string | ReferenceToExternalQuery,
) => Promise<string[] | undefined>;
// some complex steps use selectedColumns to preselect column (rename, filter...)
@Prop({})
selectedColumn?: string;
get isStepCreation() {
return this.initialStepValue === undefined;
}
Expand All @@ -105,7 +110,7 @@ export default class StepFormComponent extends Vue {
this.$emit('formSaved', step);
}
selectedColumns: string[] = [];
selectedColumns: string[] = this.selectedColumn ? [this.selectedColumn] : [];
setSelectedColumns({ column }: { column: string | undefined }) {
if (!!column && column !== this.selectedColumns[0]) {
Expand Down
1 change: 1 addition & 0 deletions ui/src/components/stepforms/StoreStepFormComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ref="step"
:translator="translator"
:initialStepValue="initialStepValue"
:stepFormDefaults="stepFormDefaults"
:isStepCreation="isStepCreation"
:columnTypes="columnTypes"
:backendError="backendError"
Expand Down
95 changes: 95 additions & 0 deletions ui/stories/StepForm.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,98 @@ export const Default: StoryObj<StepFormComponent> = {
},
},
};

export const Edition: StoryObj<StepFormComponent> = {
render: (args, { argTypes }) => ({
components: { StepFormComponent },
props: Object.keys(argTypes),
template: '<StepFormComponent v-bind="$props" @formSaved="onFormSaved" @back="onBack" />',
methods: {
onFormSaved: action('formSaved'),
onBack: action('back'),
},
}),
args: {
name: 'text',
availableDomains: [{ name: 'other_domain', uid: 'other_domain' }],
unjoinableDomains: [],
columnTypes: { a: 'string', b: 'boolean' },
availableVariables: SAMPLE_VARIABLES,
variableDelimiters: { start: '<%=', end: '%>' },
trustedVariableDelimiters: { start: '{{', end: '}}' },
variables: VARIABLES,
initialStepValue: {
text: 'Text value',
newColumn: 'a',
},
interpolateFunc: (a) => a,
getColumnNamesFromPipeline: () => Promise.resolve(['c', 'd']),
},
argTypes: {
name: {
disable: true,
},
},
};

export const WithDefaults: StoryObj<StepFormComponent> = {
render: (args, { argTypes }) => ({
components: { StepFormComponent },
props: Object.keys(argTypes),
template: '<StepFormComponent v-bind="$props" @formSaved="onFormSaved" @back="onBack" />',
methods: {
onFormSaved: action('formSaved'),
onBack: action('back'),
},
}),
args: {
name: 'text',
availableDomains: [{ name: 'other_domain', uid: 'other_domain' }],
unjoinableDomains: [],
columnTypes: { a: 'string', b: 'boolean' },
availableVariables: SAMPLE_VARIABLES,
variableDelimiters: { start: '<%=', end: '%>' },
trustedVariableDelimiters: { start: '{{', end: '}}' },
stepFormDefaults: {
newColumn: 'd',
},
variables: VARIABLES,
interpolateFunc: (a) => a,
getColumnNamesFromPipeline: () => Promise.resolve(['c', 'd']),
},
argTypes: {
name: {
disable: true,
},
},
};

export const WithPreselectedColumn: StoryObj<StepFormComponent> = {
render: (args, { argTypes }) => ({
components: { StepFormComponent },
props: Object.keys(argTypes),
template: '<StepFormComponent v-bind="$props" @formSaved="onFormSaved" @back="onBack" />',
methods: {
onFormSaved: action('formSaved'),
onBack: action('back'),
},
}),
args: {
name: 'filter',
availableDomains: [{ name: 'other_domain', uid: 'other_domain' }],
unjoinableDomains: [],
columnTypes: { a: 'string', b: 'boolean' },
availableVariables: SAMPLE_VARIABLES,
variableDelimiters: { start: '<%=', end: '%>' },
trustedVariableDelimiters: { start: '{{', end: '}}' },
selectedColumn: 'a',
variables: VARIABLES,
interpolateFunc: (a) => a,
getColumnNamesFromPipeline: () => Promise.resolve(['c', 'd']),
},
argTypes: {
name: {
disable: true,
},
},
};

0 comments on commit 99c0ffc

Please sign in to comment.