Skip to content

Commit

Permalink
[frontend] Show artifact preview in UI (#2172) (#3707)
Browse files Browse the repository at this point in the history
* show a preview of an artifact in the ui

* Add styling to preview box

* fix minor typo in unit test

* minor fixes + DetailsTable now accepts a ValueComponent again

* encode uricomponent for generate artifact url

* fix classname typo

* Added valueComponentProps for DetailsTable for better type checking.

* fix mock bug in test. peek -> maxbytes & maxlines for MinioArtifactPreview

* fix format

* mock Editor
  • Loading branch information
eterna2 authored May 11, 2020
1 parent b1c9976 commit 30345d1
Show file tree
Hide file tree
Showing 13 changed files with 1,031 additions and 780 deletions.
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

0 comments on commit 30345d1

Please sign in to comment.