go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/test_verdict/pages/invocation_page/invocation_page.tsx (about)

     1  // Copyright 2024 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { LinearProgress } from '@mui/material';
    16  import { useQuery } from '@tanstack/react-query';
    17  import { useParams } from 'react-router-dom';
    18  
    19  import { RecoverableErrorBoundary } from '@/common/components/error_handling';
    20  import { PageMeta } from '@/common/components/page_meta/page_meta';
    21  import { AppRoutedTab, AppRoutedTabs } from '@/common/components/routed_tabs';
    22  import { useResultDbClient } from '@/test_verdict/hooks/prpc_clients';
    23  
    24  import { InvocationIdBar } from './invocation_id_bar';
    25  import { VerdictCountIndicator } from './verdict_count_indicator';
    26  
    27  export function InvocationPage() {
    28    const { invId } = useParams();
    29    if (!invId) {
    30      throw new Error('invariant violated: invId should be set');
    31    }
    32  
    33    const invName = 'invocations/' + invId;
    34  
    35    const client = useResultDbClient();
    36    const { data, error, isError, isLoading } = useQuery(
    37      client.GetInvocation.query({ name: invName }),
    38    );
    39    if (isError) {
    40      throw error;
    41    }
    42  
    43    const project = data?.realm.split(':', 2)[0] || '';
    44  
    45    return (
    46      <>
    47        <PageMeta project={project} title={`inv: ${invId}`} />
    48        <InvocationIdBar invName={invName} />
    49        <LinearProgress
    50          value={100}
    51          variant={isLoading ? 'indeterminate' : 'determinate'}
    52        />
    53        <AppRoutedTabs>
    54          <AppRoutedTab
    55            label="Test Results"
    56            value="test-results"
    57            to="test-results"
    58            icon={<VerdictCountIndicator invName={invName} />}
    59            iconPosition="end"
    60          />
    61          <AppRoutedTab
    62            label="Invocation Details"
    63            value="invocation-details"
    64            to="invocation-details"
    65          />
    66        </AppRoutedTabs>
    67      </>
    68    );
    69  }
    70  
    71  export const element = (
    72    // See the documentation for `<LoginPage />` for why we handle error this way.
    73    <RecoverableErrorBoundary key="invocation">
    74      <InvocationPage />
    75    </RecoverableErrorBoundary>
    76  );