import * as React from 'react'; import { useParams } from 'react-router-dom'; import { Bullseye, Spinner, Title } from '@patternfly/react-core'; import { getErrorState } from '~/shared/utils/error-utils'; import { INTEGRATION_TEST_PIPELINE_RUN_COLUMNS_DEFINITIONS, DEFAULT_VISIBLE_PIPELINE_RUN_COLUMNS_NO_VULNERABILITIES, NON_HIDABLE_PIPELINE_RUN_COLUMNS, PipelineRunColumnKeys, } from '../../../../consts/pipeline'; import { PipelineRunLabel } from '../../../../consts/pipelinerun'; import { FeatureFlagIndicator } from '../../../../feature-flags/FeatureFlagIndicator'; import { usePipelineRunsV2 } from '../../../../hooks/usePipelineRunsV2'; import { RouterParams } from '../../../../routes/utils'; import { Table } from '../../../../shared'; import ColumnManagement from '../../../../shared/components/table/ColumnManagement'; import { useLocalStorage } from '../../../../shared/hooks/useLocalStorage'; import { useNamespace } from '../../../../shared/providers/Namespace'; import { PipelineRunKind } from '../../../../types'; import { BaseTextFilterToolbar } from '../../../Filter/toolbars/BaseTextFIlterToolbar'; import PipelineRunEmptyState from '../../../PipelineRun/PipelineRunEmptyState'; import { getPipelineRunListHeader } from '../../../PipelineRun/PipelineRunListView/PipelineRunListHeader'; import { PipelineRunListRowWithColumns } from '../../../PipelineRun/PipelineRunListView/PipelineRunListRow'; import { IntegrationTestLabels } from '../../IntegrationTestForm/types'; const IntegrationTestPipelineRunTab: React.FC = () => { const { applicationName, integrationTestName } = useParams(); const namespace = useNamespace(); // Todo add errors here const [pipelineRuns, loaded, error, getNextPage, { isFetchingNextPage, hasNextPage }] = usePipelineRunsV2( namespace, React.useMemo( () => ({ selector: { matchLabels: { [PipelineRunLabel.APPLICATION]: applicationName, [IntegrationTestLabels.SCENARIO]: integrationTestName, }, }, }), [applicationName, integrationTestName], ), ); const [isColumnManagementOpen, setIsColumnManagementOpen] = React.useState(false); const [persistedColumns, setPersistedColumns] = useLocalStorage( `integration-test-pipeline-runs-columns-${applicationName}-${integrationTestName}`, ); const safeVisibleColumns = React.useMemo((): Set => { if (Array.isArray(persistedColumns) && persistedColumns.length > 0) { return new Set(persistedColumns as PipelineRunColumnKeys[]); } return new Set(DEFAULT_VISIBLE_PIPELINE_RUN_COLUMNS_NO_VULNERABILITIES); }, [persistedColumns]); if (error) { return getErrorState(error, loaded, 'pipeline runs'); } if (!loaded) { return ( ); } if (!pipelineRuns || pipelineRuns.length === 0) { return ; } return ( <> Pipeline runs <FeatureFlagIndicator flags={['pipelineruns-kubearchive']} /> {pipelineRuns && pipelineRuns.length > 0 && ( {}} onClearFilters={() => {}} showSearchInput={false} openColumnManagement={() => setIsColumnManagementOpen(true)} totalColumns={INTEGRATION_TEST_PIPELINE_RUN_COLUMNS_DEFINITIONS.length} /> )} ( )} loaded={loaded} getRowProps={(obj: PipelineRunKind) => ({ id: obj.metadata.name, })} onRowsRendered={({ stopIndex }) => { if ( loaded && stopIndex === pipelineRuns.length - 1 && hasNextPage && !isFetchingNextPage ) { getNextPage?.(); } }} customData={{ vulnerabilities: {}, fetchedPipelineRuns: [], integrationTestName, }} /> isOpen={isColumnManagementOpen} onClose={() => setIsColumnManagementOpen(false)} visibleColumns={safeVisibleColumns} onVisibleColumnsChange={(cols) => setPersistedColumns(Array.from(cols))} columns={INTEGRATION_TEST_PIPELINE_RUN_COLUMNS_DEFINITIONS} defaultVisibleColumns={DEFAULT_VISIBLE_PIPELINE_RUN_COLUMNS_NO_VULNERABILITIES} nonHidableColumns={NON_HIDABLE_PIPELINE_RUN_COLUMNS} title="Manage pipeline run columns" description="Selected columns will be displayed in the pipeline runs table." /> ); }; export default IntegrationTestPipelineRunTab;