/* Copyright (c) Microsoft Corporation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import * as React from 'react'; import './colors.css'; import './common.css'; import * as icons from './icons'; import { AutoChip } from './chip'; import './reportView.css'; import './theme.css'; export type Metainfo = { 'revision.id'?: string; 'revision.author'?: string; 'revision.email'?: string; 'revision.subject'?: string; 'revision.timestamp'?: number | Date; 'revision.link'?: string; 'ci.link'?: string; 'timestamp'?: number }; class ErrorBoundary extends React.Component, { error: Error | null, errorInfo: React.ErrorInfo | null }> { state: { error: Error | null, errorInfo: React.ErrorInfo | null } = { error: null, errorInfo: null, }; componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { this.setState({ error, errorInfo }); } render() { if (this.state.error || this.state.errorInfo) { return (

An error was encountered when trying to render Commit Metainfo. Please file a GitHub issue to report this error.

{this.state.error?.message}
{this.state.error?.stack}
{this.state.errorInfo?.componentStack}

); } return this.props.children; } } export const MetadataView: React.FC = metadata => ; const InnerMetadataView: React.FC = metadata => { if (!Object.keys(metadata).find(k => k.startsWith('revision.') || k.startsWith('ci.'))) return null; return ( {metadata['revision.id'] && {metadata['revision.id'].slice(0, 7)} } {metadata['revision.subject'] || 'Commit Metainfo'} } initialExpanded={false} dataTestId='metadata-chip'> {metadata['revision.subject'] && {metadata['revision.subject']}} /> } {metadata['revision.id'] && {metadata['revision.id']}} href={metadata['revision.link']} icon='commit' /> } {(metadata['revision.author'] || metadata['revision.email']) && } {metadata['revision.timestamp'] && {Intl.DateTimeFormat(undefined, { dateStyle: 'full' }).format(metadata['revision.timestamp'])} {' '} {Intl.DateTimeFormat(undefined, { timeStyle: 'long' }).format(metadata['revision.timestamp'])} } icon='calendar' /> } {metadata['ci.link'] && } {metadata['timestamp'] && Report generated on {Intl.DateTimeFormat(undefined, { dateStyle: 'full', timeStyle: 'long' }).format(metadata['timestamp'])} }> } ); }; const MetadatViewItem: React.FC<{ content: JSX.Element | string; icon?: keyof typeof icons, href?: string, testId?: string }> = ({ content, icon, href, testId }) => { return (
{icons[icon || 'blank']()}
{href ? {content} : content}
); };