Skip to content

Commit c8fdd4f

Browse files
committed
Fix UI to properly handle YAML and fix regressions
1 parent e1f695c commit c8fdd4f

File tree

11 files changed

+39
-31
lines changed

11 files changed

+39
-31
lines changed

ui/ui-app/src/app/components/common/ArtifactTypeIcon.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ArtifactTypes } from "@services/useArtifactTypesService.ts";
66
* Properties
77
*/
88
export type ArtifactTypeIconProps = {
9-
type: string;
9+
artifactType: string;
1010
};
1111

1212
/**
@@ -15,7 +15,7 @@ export type ArtifactTypeIconProps = {
1515
export const ArtifactTypeIcon: FunctionComponent<ArtifactTypeIconProps> = (props: ArtifactTypeIconProps) => {
1616

1717
return (
18-
<div className={ArtifactTypes.getClassNames(props.type)} title={ArtifactTypes.getTitle(props.type)} />
18+
<div className={ArtifactTypes.getClassNames(props.artifactType)} title={ArtifactTypes.getTitle(props.artifactType)} />
1919
);
2020

2121
};

ui/ui-app/src/app/pages/artifact/components/tabs/ArtifactInfoTabContent.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const ArtifactInfoTabContent: FunctionComponent<ArtifactInfoTabContentPro
5656
<CardTitle>
5757
<div className="title-and-type">
5858
<Flex>
59-
<FlexItem className="type"><ArtifactTypeIcon type={props.artifact.type} /></FlexItem>
59+
<FlexItem className="type"><ArtifactTypeIcon artifactType={props.artifact.artifactType} /></FlexItem>
6060
<FlexItem className="title">Artifact metadata</FlexItem>
6161
<FlexItem className="actions" align={{ default: "alignRight" }}>
6262
<IfAuth isDeveloper={true}>

ui/ui-app/src/app/pages/explore/components/artifactList/ArtifactList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const ArtifactList: FunctionComponent<ArtifactListProps> = (props: Artifa
3737
if (artifact.description) {
3838
return artifact.description;
3939
}
40-
return `An artifact of type ${artifact.type} with no description.`;
40+
return `An artifact of type ${artifact.artifactType} with no description.`;
4141
};
4242

4343
return (
@@ -48,7 +48,7 @@ export const ArtifactList: FunctionComponent<ArtifactListProps> = (props: Artifa
4848
<DataListItemCells
4949
dataListCells={[
5050
<DataListCell key="type icon" className="type-icon-cell">
51-
<ArtifactTypeIcon type={artifact.type}/>
51+
<ArtifactTypeIcon artifactType={artifact.artifactType}/>
5252
</DataListCell>,
5353
<DataListCell key="main content" className="content-cell">
5454
<div className="artifact-title">

ui/ui-app/src/app/pages/group/components/tabs/ArtifactsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const ArtifactsTable: FunctionComponent<ArtifactsTableProps> = (props: Ar
6464
// Type.
6565
if (colIndex === 1) {
6666
return (
67-
<ArtifactTypeIcon type={column.type} />
67+
<ArtifactTypeIcon artifactType={column.artifactType} />
6868
);
6969
}
7070
// Created on.

ui/ui-app/src/app/pages/version/components/tabs/ContentTabContent.tsx

+23-18
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ const getEditorMode = (artifactType: string, content: string): string => {
1919
const ct: string = detectContentType(artifactType, content);
2020
return TYPE_MAP[ct];
2121
};
22-
//
23-
// const formatContent = (artifactContent: string): string => {
24-
// try {
25-
// const pval: any = JSON.parse(artifactContent);
26-
// if (pval) {
27-
// return JSON.stringify(pval, null, 2);
28-
// }
29-
// } catch (e) {
30-
// // Do nothing
31-
// }
32-
// return artifactContent;
33-
// };
22+
23+
const formatJsonContent = (artifactContent: string): string => {
24+
try {
25+
const pval: any = JSON.parse(artifactContent);
26+
if (pval) {
27+
return JSON.stringify(pval, null, 2);
28+
}
29+
} catch (e) {
30+
// Do nothing
31+
}
32+
return artifactContent;
33+
};
3434

3535

3636
/**
@@ -46,8 +46,11 @@ export type ContentTabContentProps = {
4646
* Models the content of the Artifact Content tab.
4747
*/
4848
export const ContentTabContent: FunctionComponent<ContentTabContentProps> = (props: ContentTabContentProps) => {
49-
const [content, setContent] = useState(props.versionContent);
50-
const [editorMode, setEditorMode] = useState(getEditorMode(props.artifactType, props.versionContent));
49+
const em: string = getEditorMode(props.artifactType, props.versionContent);
50+
const fc: string = em === "json" ? formatJsonContent(props.versionContent) : props.versionContent;
51+
52+
const [content, setContent] = useState(fc);
53+
const [editorMode, setEditorMode] = useState(em);
5154
const [compactButtons, setCompactButtons] = useState(false);
5255

5356
const { ref, width = 0, height = 0 } = useResizeObserver<HTMLDivElement>();
@@ -61,18 +64,20 @@ export const ContentTabContent: FunctionComponent<ContentTabContentProps> = (pro
6164
if (mode === editorMode) {
6265
return;
6366
} else {
64-
let content: string = `Error formatting code to: ${mode}`;
67+
let newContent: string = `Error formatting code to: ${mode}`;
6568
try {
6669
if (mode === "yaml") {
67-
content = YAML.stringify(JSON.parse(content), null, 4);
70+
newContent = YAML.stringify(JSON.parse(content), null, 4);
71+
console.info("NEW CONTENT (yaml): ", newContent);
6872
} else {
69-
content = JSON.stringify(YAML.parse(content), null, 2);
73+
newContent = JSON.stringify(YAML.parse(content), null, 2);
74+
console.info("NEW CONTENT (json): ", newContent);
7075
}
7176
} catch (e) {
7277
handleInvalidContentError(e);
7378
}
7479
setEditorMode(mode);
75-
setContent(content);
80+
setContent(newContent);
7681
}
7782
};
7883

ui/ui-app/src/app/pages/version/components/tabs/InfoTabContent.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const InfoTabContent: FunctionComponent<InfoTabContentProps> = (props: In
5151
<CardTitle>
5252
<div className="title-and-type">
5353
<Flex>
54-
<FlexItem className="type"><ArtifactTypeIcon type={props.artifact.type} /></FlexItem>
54+
<FlexItem className="type"><ArtifactTypeIcon artifactType={props.artifact.artifactType} /></FlexItem>
5555
<FlexItem className="title">Version metadata</FlexItem>
5656
<FlexItem className="actions" align={{ default: "alignRight" }}>
5757
<IfAuth isDeveloper={true}>

ui/ui-app/src/models/artifactMetaData.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface ArtifactMetaData {
66
name: string|null;
77
description: string|null;
88
labels: { [key: string]: string | undefined };
9-
type: string;
9+
artifactType: string;
1010
version: string;
1111
owner: string;
1212
createdOn: string;

ui/ui-app/src/models/searchedArtifact.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export interface SearchedArtifact {
22

33
groupId: string|null;
44
artifactId: string;
5-
type: string;
5+
artifactType: string;
66
state: string;
77
name: string;
88
description: string;

ui/ui-app/src/models/searchedVersion.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export interface SearchedVersion {
33
globalId: number;
44
contentId: number|null;
55
version: string;
6-
type: string;
6+
artifactType: string;
77
state: string;
88
name: string;
99
description: string;

ui/ui-app/src/models/versionMetaData.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export interface VersionMetaData {
1111
contentId: number;
1212
globalId: number;
1313
state: string;
14-
type: string;
14+
artifactType: string;
1515

1616
}

ui/ui-app/src/utils/content.utils.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import YAML from "yaml";
22
import { ContentTypes } from "@models/contentTypes.model.ts";
3+
import { isStringEmptyOrUndefined } from "@utils/string.utils.ts";
34

45
/**
56
* Returns true if the given content is JSON formatted.
@@ -99,8 +100,8 @@ export function contentToString(content: any): string {
99100
}
100101

101102

102-
export function detectContentType(type: string, content: string): string {
103-
switch (type) {
103+
export function detectContentType(artifactType: string, content: string): string {
104+
switch (artifactType) {
104105
case "PROTOBUF":
105106
return ContentTypes.APPLICATION_PROTOBUF;
106107
case "WSDL":
@@ -116,6 +117,8 @@ export function detectContentType(type: string, content: string): string {
116117
return ContentTypes.APPLICATION_XML;
117118
} else if (isYaml(content)) {
118119
return ContentTypes.APPLICATION_YAML;
120+
} else if (!isStringEmptyOrUndefined(content) && (content.indexOf("proto2") != -1 || content.indexOf("proto3") != -1)) {
121+
return ContentTypes.APPLICATION_PROTOBUF;
119122
} else {
120123
return ContentTypes.APPLICATION_OCTET_STREAM;
121124
}

0 commit comments

Comments
 (0)