Skip to content

Commit

Permalink
fix(ui): Enable workflowtemplate submit button
Browse files Browse the repository at this point in the history
Signed-off-by: instauro <instauro@proton.me>
  • Loading branch information
instauro committed Nov 17, 2024
1 parent 6da0ff8 commit 1884c81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 8 additions & 0 deletions ui/src/shared/components/object-parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
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);
});
});

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 1884c81

Please sign in to comment.