Skip to content

Commit

Permalink
Frontend - Shorten output names
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Apr 4, 2021
1 parent 5fbf224 commit 8e4a5a6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
47 changes: 47 additions & 0 deletions frontend/src/lib/WorkflowParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,29 @@ describe('WorkflowParser', () => {
});
});

it('handles trimming output parameter name', () => {
const workflow = {
status: {
nodes: {
node1: {
templateName: 'my-component',
outputs: {
parameters: [
{
name: 'my-component-output-param1',
value: 'output param1 value',
},
],
},
},
},
},
};
expect(WorkflowParser.getNodeInputOutputParams(workflow as any, 'node1')).toEqual({
inputParams: [],
outputParams: [['output-param1', 'output param1 value']],
});
});
it('handles a node with one input and one output parameter', () => {
const workflow = {
status: {
Expand Down Expand Up @@ -773,6 +796,30 @@ describe('WorkflowParser', () => {
});
});

it('handles trimming output artifact name', () => {
const workflow = {
status: {
nodes: {
node1: {
templateName: 'my-component',
outputs: {
artifacts: [
{
name: 'my-component-output-art1',
s3,
},
],
},
},
},
},
};
expect(WorkflowParser.getNodeInputOutputArtifacts(workflow as any, 'node1')).toEqual({
inputArtifacts: [],
outputArtifacts: [['output-art1', s3]],
});
});

it('handles a node with one input and one output artifacts', () => {
const workflow = {
status: {
Expand Down
24 changes: 20 additions & 4 deletions frontend/src/lib/WorkflowParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ export default class WorkflowParser {
return g;
}

static trimPrefix(str: string, prefix: string): string {
if (str.startsWith(prefix)) {
return str.slice(prefix.length);
} else {
return str;
}
}

public static getParameters(workflow?: Workflow): Parameter[] {
if (workflow && workflow.spec && workflow.spec.arguments) {
return workflow.spec.arguments.parameters || [];
Expand Down Expand Up @@ -187,12 +195,16 @@ export default class WorkflowParser {
return { inputParams, outputParams };
}

const { inputs, outputs } = workflow.status.nodes[nodeId];
const { inputs, outputs, templateName } = workflow.status.nodes[nodeId];
const namePrefixToStrip = templateName + '-';
if (!!inputs && !!inputs.parameters) {
inputParams = inputs.parameters.map(p => [p.name, p.value || '']);
}
if (!!outputs && !!outputs.parameters) {
outputParams = outputs.parameters.map(p => [p.name, p.value || '']);
outputParams = outputs.parameters.map(p => [
WorkflowParser.trimPrefix(p.name, namePrefixToStrip),
p.value || '',
]);
}
return { inputParams, outputParams };
}
Expand All @@ -217,12 +229,16 @@ export default class WorkflowParser {
return { inputArtifacts, outputArtifacts };
}

const { inputs, outputs } = workflow.status.nodes[nodeId];
const { inputs, outputs, templateName } = workflow.status.nodes[nodeId];
const namePrefixToStrip = templateName + '-';
if (!!inputs && !!inputs.artifacts) {
inputArtifacts = inputs.artifacts.map(({ name, s3 }) => [name, s3]);
}
if (!!outputs && !!outputs.artifacts) {
outputArtifacts = outputs.artifacts.map(({ name, s3 }) => [name, s3]);
outputArtifacts = outputs.artifacts.map(({ name, s3 }) => [
WorkflowParser.trimPrefix(name, namePrefixToStrip),
s3,
]);
}
return { inputArtifacts, outputArtifacts };
}
Expand Down

0 comments on commit 8e4a5a6

Please sign in to comment.