Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frontend] Show artifact preview in UI (#2172) #3707

Merged
merged 10 commits into from
May 11, 2020
449 changes: 414 additions & 35 deletions frontend/src/components/DetailsTable.test.tsx

Large diffs are not rendered by default.

35 changes: 20 additions & 15 deletions frontend/src/components/DetailsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'brace';
import 'brace/ext/language_tools';
import 'brace/mode/json';
import 'brace/theme/github';
import { S3Artifact } from 'third_party/argo-ui/argo_template';

export const css = stylesheet({
key: {
Expand All @@ -48,22 +47,29 @@ export const css = stylesheet({
},
});

interface DetailsTableProps {
fields: Array<KeyValue<string | S3Artifact>>;
export interface ValueComponentProps<T> {
value?: string | T;
[key: string]: any;
}

interface DetailsTableProps<T> {
fields: Array<KeyValue<string | T>>;
title?: string;
valueComponent?: React.FC<{ value: S3Artifact }>;
valueComponent?: React.FC<ValueComponentProps<T>>;
valueComponentProps?: { [key: string]: any };
}

function isString(x: any): x is string {
return typeof x === 'string';
}

const DetailsTable = (props: DetailsTableProps) => {
const DetailsTable = <T extends {}>(props: DetailsTableProps<T>) => {
const { fields, title, valueComponent: ValueComponent, valueComponentProps } = props;
return (
<React.Fragment>
{!!props.title && <div className={commonCss.header}>{props.title}</div>}
{!!title && <div className={commonCss.header}>{title}</div>}
<div>
{props.fields.map((f, i) => {
{fields.map((f, i) => {
const [key, value] = f;

// only try to parse json if value is a string
Expand Down Expand Up @@ -97,18 +103,17 @@ const DetailsTable = (props: DetailsTableProps) => {
// do nothing
}
}
// If the value isn't a JSON object, just display it as is
// If a ValueComponent and a value is provided, render the value with
// the ValueComponent. Otherwise render the value as a string (empty string if null or undefined).
return (
<div key={i} className={css.row}>
<span className={css.key}>{key}</span>
<span className={css.valueText}>
{(() => {
const ValueComponent = props.valueComponent;
if (ValueComponent && !!value && !isString(value)) {
return <ValueComponent value={value} />;
}
return value;
})()}
{ValueComponent && value ? (
<ValueComponent value={value} {...valueComponentProps} />
) : (
`${value || ''}`
)}
</span>
</div>
);
Expand Down
106 changes: 0 additions & 106 deletions frontend/src/components/MinioArtifactLink.test.tsx

This file was deleted.

36 changes: 0 additions & 36 deletions frontend/src/components/MinioArtifactLink.tsx

This file was deleted.

Loading