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

Make gs:// links in metadata UI point to GCS console page #2167

Merged
merged 4 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions frontend/src/components/GcsLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import { generateGcsConsoleUri } from '../lib/Utils';

/**
* A component that renders a gcs console link when gcsUri is gs:// and pure
* text if it is not a valid gs:// uri.
*/
export const GcsLink: React.FC<{ gcsUri?: string }> = ({ gcsUri }) => {
const gcsConsoleUri = gcsUri ? generateGcsConsoleUri(gcsUri) : undefined;
if (gcsConsoleUri) {
// Opens in new window safely
return <a href={gcsConsoleUri} target={'_blank'} rel={'noreferrer noopener'}>{gcsUri}</a>;
} else {
return <>{gcsUri}</>;
}
};
5 changes: 4 additions & 1 deletion frontend/src/components/ResourceInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { stylesheet } from 'typestyle';
import { color, commonCss } from '../Css';
import { getMetadataValue } from '../lib/Utils';
import { Artifact, Execution } from '../generated/src/apis/metadata/metadata_store_pb';
import { GcsLink } from './GcsLink';

export const css = stylesheet({
field: {
Expand Down Expand Up @@ -75,7 +76,9 @@ export class ResourceInfo extends React.Component<ResourceInfoProps, {}> {
if (this.props.resourceType === ResourceType.ARTIFACT) {
return <>
<dt className={css.term}>URI</dt>
<dd className={css.value}>{this.props.resource.getUri()}</dd>
<dd className={css.value}>
<GcsLink gcsUri={this.props.resource.getUri()} />
</dd>
</>;
}
return null;
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/lib/Utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,20 @@ export function getExpandedRow(expandedRows: Map<number, Row[]>, columns: Column
);
};
}

const GCS_CONSOLE_BASE = 'https://console.cloud.google.com/storage/browser/';
const GCS_URI_PREFIX = 'gs://';

/**
* Generates a cloud console uri from gs:// uri
*
* @param gcsUri Gcs uri that starts with gs://, like gs://bucket/path/file
* @returns A link user can open to visit cloud console page. Returns undefined when gcsUri is not valid.
*/
export function generateGcsConsoleUri(gcsUri: string): string | undefined {
if (!gcsUri.startsWith(GCS_URI_PREFIX)) {
return undefined;
}

return GCS_CONSOLE_BASE + gcsUri.substring(GCS_URI_PREFIX.length);
}
6 changes: 5 additions & 1 deletion frontend/src/pages/ArtifactList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Artifact, ArtifactType } from '../generated/src/apis/metadata/metadata_
import { ArtifactProperties, ArtifactCustomProperties, ListRequest, Apis } from '../lib/Apis';
import { GetArtifactTypesRequest, GetArtifactsRequest } from '../generated/src/apis/metadata/metadata_store_service_pb';
import { getArtifactCreationTime } from '../lib/MetadataUtils';
import { GcsLink } from '../components/GcsLink';

interface ArtifactListState {
artifacts: Artifact[];
Expand Down Expand Up @@ -57,7 +58,7 @@ class ArtifactList extends Page<{}, ArtifactListState> {
},
{ label: 'ID', flex: 1, sortKey: 'id' },
{ label: 'Type', flex: 2, sortKey: 'type' },
{ label: 'URI', flex: 2, sortKey: 'uri', },
{ label: 'URI', flex: 2, sortKey: 'uri', customRenderer: this.uriCustomRenderer },
{ label: 'Created at', flex: 1, sortKey: 'created_at' },
],
expandedRows: new Map(),
Expand Down Expand Up @@ -133,6 +134,9 @@ class ArtifactList extends Page<{}, ArtifactListState> {
);
}

private uriCustomRenderer: React.FC<CustomRendererProps<string>> =
({ value }) => <GcsLink gcsUri={value} />

/**
* Temporary solution to apply sorting, filtering, and pagination to the
* local list of artifacts until server-side handling is available
Expand Down
1 change: 1 addition & 0 deletions frontend/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
true,
"check-format",
"ban-keywords",
"allow-pascal-case",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows react function component.

"allow-leading-underscore",
"allow-trailing-underscore"
]
Expand Down