Skip to content

Commit

Permalink
fix(ui): fix broken workflowtemplate submit button. Fixes #13892 (#13913
Browse files Browse the repository at this point in the history
)

Signed-off-by: instauro <[email protected]>
Co-authored-by: instauro <[email protected]>
(cherry picked from commit 2fd5488)
  • Loading branch information
instauro authored and Joibel committed Nov 22, 2024
1 parent b26ed4a commit f85d055
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 9 additions & 0 deletions ui/src/shared/components/object-parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import {exampleWorkflowTemplate} from '../examples';
import {parse, stringify} from './object-parser';

describe('parse and stringify are inverses', () => {
it('handles creationTimestamp', () => {
const testWorkflowTemplate = exampleWorkflowTemplate('test');
testWorkflowTemplate.metadata.creationTimestamp = '2024-11-17T06:56:52Z';
expect(parse(stringify(testWorkflowTemplate, 'yaml'))).toEqual(testWorkflowTemplate);
expect(parse(stringify(testWorkflowTemplate, 'json'))).toEqual(testWorkflowTemplate);
});
});

describe('parse', () => {
it('handles a valid JSON string', () => {
expect(parse('{}')).toEqual({});
Expand Down
13 changes: 6 additions & 7 deletions ui/src/shared/components/object-parser.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import YAML from 'yaml';

// Default is YAML 1.2, but Kubernetes uses YAML 1.1, which leads to subtle bugs.
// See https://github.com/argoproj/argo-workflows/issues/12205#issuecomment-2111572189
const yamlVersion = '1.1';

export function parse<T>(value: string): T {
if (value.startsWith('{')) {
return JSON.parse(value);
}
return YAML.parse(value, {
// Default is YAML 1.2, but Kubernetes uses YAML 1.1, which leads to subtle bugs.
// See https://github.com/argoproj/argo-workflows/issues/12205#issuecomment-2111572189
version: '1.1',
strict: false
}) as T;
return YAML.parse(value, {version: yamlVersion, strict: false}) as T;
}

export function stringify<T>(value: T, type: string) {
return type === 'yaml' ? YAML.stringify(value, {aliasDuplicateObjects: false}) : JSON.stringify(value, null, ' ');
return type === 'yaml' ? YAML.stringify(value, {aliasDuplicateObjects: false, version: yamlVersion, strict: false}) : JSON.stringify(value, null, ' ');
}

0 comments on commit f85d055

Please sign in to comment.