-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
223 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
frontend/src/pages/pipelines/global/experiments/artifacts/ArtifactOverviewDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
Flex, | ||
FlexItem, | ||
Stack, | ||
Title, | ||
DescriptionList, | ||
DescriptionListGroup, | ||
DescriptionListTerm, | ||
DescriptionListDescription, | ||
} from '@patternfly/react-core'; | ||
import { CodeEditor } from '@patternfly/react-code-editor'; | ||
|
||
import { Artifact, Value } from '~/third_party/mlmd'; | ||
import { ArtifactUriLink } from './ArtifactUriLink'; | ||
|
||
interface ArtifactOverviewDetailsProps { | ||
artifact: Artifact.AsObject | undefined; | ||
} | ||
|
||
export const ArtifactOverviewDetails: React.FC<ArtifactOverviewDetailsProps> = ({ artifact }) => { | ||
const getPropertyValue = React.useCallback((property: Value.AsObject): React.ReactNode => { | ||
let propValue: React.ReactNode = | ||
property.stringValue || property.intValue || property.doubleValue || property.boolValue || ''; | ||
|
||
if (property.structValue || property.protoValue) { | ||
propValue = ( | ||
<CodeEditor | ||
isReadOnly | ||
code={JSON.stringify(property.structValue || property.protoValue)} | ||
height="sizeToFit" | ||
/> | ||
); | ||
} | ||
|
||
return propValue; | ||
}, []); | ||
|
||
return ( | ||
<Flex | ||
spaceItems={{ default: 'spaceItems2xl' }} | ||
direction={{ default: 'column' }} | ||
className="pf-v5-u-pt-lg pf-v5-u-pb-lg" | ||
> | ||
<FlexItem> | ||
<Stack hasGutter> | ||
<Title headingLevel="h3">Live system dataset</Title> | ||
<DescriptionList isHorizontal data-testid="dataset-description-list"> | ||
<DescriptionListGroup> | ||
{artifact?.uri && ( | ||
<> | ||
<DescriptionListTerm>URI</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
<ArtifactUriLink uri={artifact.uri} /> | ||
</DescriptionListDescription> | ||
</> | ||
)} | ||
</DescriptionListGroup> | ||
</DescriptionList> | ||
</Stack> | ||
</FlexItem> | ||
|
||
{!!artifact?.propertiesMap.length && ( | ||
<FlexItem> | ||
<Stack hasGutter> | ||
<Title headingLevel="h3">Properties</Title> | ||
<DescriptionList isHorizontal data-testid="props-description-list"> | ||
<DescriptionListGroup> | ||
{artifact.propertiesMap.map(([propKey, propValue]) => ( | ||
<React.Fragment key={propKey}> | ||
<DescriptionListTerm>{propKey}</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{getPropertyValue(propValue)} | ||
</DescriptionListDescription> | ||
</React.Fragment> | ||
))} | ||
</DescriptionListGroup> | ||
</DescriptionList> | ||
</Stack> | ||
</FlexItem> | ||
)} | ||
|
||
{!!artifact?.customPropertiesMap.length && ( | ||
<FlexItem> | ||
<Stack hasGutter> | ||
<Title headingLevel="h3">Custom properties</Title> | ||
<DescriptionList isHorizontal data-testid="custom-props-description-list"> | ||
<DescriptionListGroup> | ||
{artifact.customPropertiesMap.map(([customPropKey, customPropValue]) => ( | ||
<React.Fragment key={customPropKey}> | ||
<DescriptionListTerm>{customPropKey}</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{getPropertyValue(customPropValue)} | ||
</DescriptionListDescription> | ||
</React.Fragment> | ||
))} | ||
</DescriptionListGroup> | ||
</DescriptionList> | ||
</Stack> | ||
</FlexItem> | ||
)} | ||
</Flex> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
frontend/src/pages/pipelines/global/experiments/artifacts/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,55 @@ | ||
/** URI related utils source: https://github.com/kubeflow/pipelines/blob/master/frontend/src/lib/Utils.tsx */ | ||
import { Artifact } from '~/third_party/mlmd'; | ||
|
||
export const getArtifactName = (artifact: Artifact.AsObject | undefined): string | undefined => | ||
artifact?.name || | ||
artifact?.customPropertiesMap.find(([name]) => name === 'display_name')?.[1].stringValue; | ||
|
||
export function buildQuery(queriesMap?: { [key: string]: string | number | undefined }): string { | ||
const queryContent = Object.entries(queriesMap || {}) | ||
.filter((entry): entry is [string, string | number] => entry[1] != null) | ||
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`) | ||
.join('&'); | ||
if (!queryContent) { | ||
return ''; | ||
} | ||
return `?${queryContent}`; | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
export function generateGcsConsoleUri(uri: string): string { | ||
const gcsPrefix = 'gs://'; | ||
return `https://console.cloud.google.com/storage/browser/${uri.substring(gcsPrefix.length)}`; | ||
} | ||
|
||
/** | ||
* Generates an HTTPS API URL from minio:// uri | ||
* | ||
* @param uri Minio uri that starts with minio://, like minio://ml-pipeline/path/file | ||
* @returns A URL that leads to the artifact data. Returns undefined when minioUri is not valid. | ||
*/ | ||
export function generateMinioArtifactUrl(uri: string, peek?: number): string | undefined { | ||
const matches = uri.match(/^minio:\/\/([^/]+)\/(.+)$/); | ||
|
||
return matches | ||
? `artifacts/minio/${matches[1]}/${matches[2]}${buildQuery({ | ||
peek, | ||
})}` | ||
: undefined; | ||
} | ||
|
||
/** | ||
* Generates an HTTPS API URL from s3:// uri | ||
* | ||
* @param uri S3 uri that starts with s3://, like s3://ml-pipeline/path/file | ||
* @returns A URL that leads to the artifact data. Returns undefined when s3Uri is not valid. | ||
*/ | ||
export function generateS3ArtifactUrl(uri: string): string | undefined { | ||
const matches = uri.match(/^s3:\/\/([^/]+)\/(.+)$/); | ||
return matches ? `artifacts/s3/${matches[1]}/${matches[2]}${buildQuery()}` : undefined; | ||
} |