Skip to content

Commit

Permalink
add JobRelatedInformation to the context
Browse files Browse the repository at this point in the history
  • Loading branch information
uidoyen committed Aug 31, 2023
1 parent 857cbf5 commit 7f8fbe3
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react';
import { Text, TextVariants } from '@patternfly/react-core';
import { getPipelineJobExecutionCount } from '~/concepts/pipelines/content/tables/utils';
import { PipelineCoreResourceKF } from '~/concepts/pipelines/kfTypes';
import useJobRelatedInformation from '~/concepts/pipelines/content/tables/pipelineRun/useJobRelatedInformation';
import { usePipelinesAPI } from '~/concepts/pipelines/context';

type PipelineJobReferenceNameProps = {
resource: PipelineCoreResourceKF;
};

const PipelineJobReferenceName: React.FC<PipelineJobReferenceNameProps> = ({ resource }) => {
const { getJobInformation } = useJobRelatedInformation();
const { getJobInformation } = usePipelinesAPI();
const { data, loading } = getJobInformation(resource);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
renderDetailItems,
} from '~/concepts/pipelines/content/pipelinesDetails/pipelineRun/utils';
import PipelineDetailsTitle from '~/concepts/pipelines/content/pipelinesDetails/PipelineDetailsTitle';
import useJobRelatedInformation from '~/concepts/pipelines/content/tables/pipelineRun/useJobRelatedInformation';
import PipelineRunTypeLabel from '~/concepts/pipelines/content/PipelineRunTypeLabel';
import PipelineJobReferenceName from '~/concepts/pipelines/content/PipelineJobReferenceName';

Expand All @@ -35,8 +34,7 @@ const PipelineRunTabDetails: React.FC<PipelineRunTabDetailsProps> = ({
pipelineRunKF,
workflowName,
}) => {
const { namespace, project } = usePipelinesAPI();
const { getJobInformation } = useJobRelatedInformation();
const { namespace, project, getJobInformation } = usePipelinesAPI();

if (!pipelineRunKF || !workflowName) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ import usePipelineRunFilter from '~/concepts/pipelines/content/tables/pipelineRu
import PipelineRunTableToolbar from '~/concepts/pipelines/content/tables/pipelineRun/PipelineRunTableToolbar';
import DeletePipelineCoreResourceModal from '~/concepts/pipelines/content/DeletePipelineCoreResourceModal';
import { usePipelinesAPI } from '~/concepts/pipelines/context';
import useJobRelatedInformation from '~/concepts/pipelines/content/tables/pipelineRun/useJobRelatedInformation';
import { PipelineType } from '~/concepts/pipelines/content/tables/utils';

type PipelineRunTableProps = {
runs: PipelineRunKF[];
};

const PipelineRunTable: React.FC<PipelineRunTableProps> = ({ runs }) => {
const { refreshAllAPI } = usePipelinesAPI();
const { refreshAllAPI, getJobInformation } = usePipelinesAPI();
const [filteredRuns, toolbarProps] = usePipelineRunFilter(runs);
const { selections, tableProps, toggleSelection, isSelected } = useCheckboxTable(
filteredRuns.map(({ id }) => id),
);
const [deleteResources, setDeleteResources] = React.useState<PipelineCoreResourceKF[]>([]);
const { getJobInformation } = useJobRelatedInformation();

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '~/concepts/pipelines/content/tables/renderUtils';
import { usePipelinesAPI } from '~/concepts/pipelines/context';
import CheckboxTd from '~/components/table/CheckboxTd';
import { GetJobInformation } from '~/concepts/pipelines/content/tables/pipelineRun/useJobRelatedInformation';
import { GetJobInformation } from '~/concepts/pipelines/context/useJobRelatedInformation';
import PipelineRunTableRowTitle from '~/concepts/pipelines/content/tables/pipelineRun/PipelineRunTableRowTitle';

type PipelineRunTableRowProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Skeleton } from '@patternfly/react-core';
import { Link } from 'react-router-dom';
import TableRowTitleDescription from '~/components/table/TableRowTitleDescription';
import { PipelineCoreResourceKF } from '~/concepts/pipelines/kfTypes';
import useJobRelatedInformation from '~/concepts/pipelines/content/tables/pipelineRun/useJobRelatedInformation';
import { usePipelinesAPI } from '~/concepts/pipelines/context';
import PipelineJobReferenceName from '~/concepts/pipelines/content/PipelineJobReferenceName';
import PipelineRunTypeLabel from '~/concepts/pipelines/content/PipelineRunTypeLabel';
Expand All @@ -13,8 +12,7 @@ type PipelineRunTableRowTitleProps = {
};

const PipelineRunTableRowTitle: React.FC<PipelineRunTableRowTitleProps> = ({ resource }) => {
const { namespace } = usePipelinesAPI();
const { getJobInformation } = useJobRelatedInformation();
const { namespace, getJobInformation } = usePipelinesAPI();
const { data, loading } = getJobInformation(resource);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import {
PipelineRunStatusUnknown,
} from '~/concepts/pipelines/kfTypes';
import { computeRunStatus } from '~/concepts/pipelines/content/utils';
import { FilterOptions, FilterProps } from './PipelineRunTableToolbar';
// import useJobRelatedInformation from './useJobRelatedInformation';
import { usePipelinesAPI } from '~/concepts/pipelines/context';
import { FilterOptions, FilterProps } from './PipelineRunTableToolbar';

type FilterData = Record<FilterOptions, string>;
const DEFAULT_FILTER_DATA: FilterData = {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/concepts/pipelines/context/PipelinesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import ViewPipelineServerModal from '~/concepts/pipelines/content/ViewPipelineSe
import useSyncPreferredProject from '~/concepts/projects/useSyncPreferredProject';
import useManageElyraSecret from '~/concepts/pipelines/context/useManageElyraSecret';
import { deleteServer } from '~/concepts/pipelines/utils';
import useJobRelatedInformation from '~/concepts/pipelines/context/useJobRelatedInformation';
import useAPIState, { APIState } from './useAPIState';
import usePipelineNamespaceCR, { dspaLoaded, hasServerTimedOut } from './usePipelineNamespaceCR';
import usePipelinesAPIRoute from './usePipelinesAPIRoute';
import useJobRelatedInformation from '~/concepts/pipelines/content/tables/pipelineRun/useJobRelatedInformation';

type JobStatus = {
loading: boolean;
data: PipelineRunJobKF | null;
};

export type GetJobInformation = (resource: PipelineCoreResourceKF) => JobStatus;
type GetJobInformation = (resource: PipelineCoreResourceKF) => JobStatus;
type PipelineContext = {
hasCR: boolean;
crInitializing: boolean;
Expand Down Expand Up @@ -83,7 +83,7 @@ export const PipelineContextProvider: React.FC<PipelineContextProviderProps> = (
isCRReady,
namespace,
);
const { getJobInformation } = useJobRelatedInformation();

const hostPath = routeLoaded && pipelineAPIRouteHost ? pipelineAPIRouteHost : null;
useManageElyraSecret(namespace, pipelineNamespaceCR, hostPath);

Expand All @@ -93,6 +93,7 @@ export const PipelineContextProvider: React.FC<PipelineContextProviderProps> = (
);

const [apiState, refreshAPIState] = useAPIState(hostPath);
const { getJobInformation } = useJobRelatedInformation(apiState);
let error = crLoadError || routeLoadError;
if (error || !project) {
error = error || new Error('Project not found');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { PipelineCoreResourceKF, PipelineRunJobKF } from '~/concepts/pipelines/kfTypes';
import { usePipelinesAPI } from '~/concepts/pipelines/context';
import { getPipelineCoreResourceJobReference } from '~/concepts/pipelines/content/tables/utils';
import { APIState } from '~/concepts/pipelines/context/useAPIState';

type JobStatus = {
loading: boolean;
Expand All @@ -10,14 +10,16 @@ type JobStatus = {

export type GetJobInformation = (resource: PipelineCoreResourceKF) => JobStatus;

const useJobRelatedInformation = (): { getJobInformation: GetJobInformation } => {
const { api } = usePipelinesAPI();
const useJobRelatedInformation = (apiState: APIState): { getJobInformation: GetJobInformation } => {
const [jobStorage, setJobStorage] = React.useState<{ [jobId: string]: JobStatus }>({});
const loadedIds = React.useRef<string[]>([]);

return {
getJobInformation: React.useCallback<GetJobInformation>(
(resource) => {
if (apiState.apiAvailable) {
return { loading: false, data: null };
}
const jobReference = getPipelineCoreResourceJobReference(resource);
if (!jobReference) {
return { loading: false, data: null };
Expand All @@ -31,7 +33,7 @@ const useJobRelatedInformation = (): { getJobInformation: GetJobInformation } =>
}
loadedIds.current.push(jobId);

api
apiState.api
.getPipelineRunJob({}, jobId)
.then((job) => {
setJobStorage((jobState) => ({ ...jobState, [jobId]: { loading: false, data: job } }));
Expand All @@ -45,7 +47,7 @@ const useJobRelatedInformation = (): { getJobInformation: GetJobInformation } =>

return { loading: true, data: null };
},
[api, jobStorage],
[apiState, jobStorage],
),
};
};
Expand Down

0 comments on commit 7f8fbe3

Please sign in to comment.