Skip to content

Commit

Permalink
add getJobInformation to usePipelineAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
uidoyen committed Aug 31, 2023
1 parent 58557e4 commit 857cbf5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
} from '~/concepts/pipelines/kfTypes';
import { computeRunStatus } from '~/concepts/pipelines/content/utils';
import { FilterOptions, FilterProps } from './PipelineRunTableToolbar';
import useJobRelatedInformation from './useJobRelatedInformation';
// import useJobRelatedInformation from './useJobRelatedInformation';
import { usePipelinesAPI } from '~/concepts/pipelines/context';

type FilterData = Record<FilterOptions, string>;
const DEFAULT_FILTER_DATA: FilterData = {
Expand All @@ -26,7 +27,7 @@ const usePipelineRunFilter = (
runs: PipelineRunKF[],
): [filterJobs: PipelineRunKF[], toolbarProps: FilterProps] => {
const [filterData, setFilterData] = React.useState<FilterData>(DEFAULT_FILTER_DATA);
const { getJobInformation } = useJobRelatedInformation();
const { getJobInformation } = usePipelinesAPI();

const filteredRuns = runs.filter((run) => {
const runValue = filterData[FilterOptions.NAME];
Expand Down
27 changes: 26 additions & 1 deletion frontend/src/concepts/pipelines/context/PipelinesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
StackItem,
} from '@patternfly/react-core';
import { ProjectKind } from '~/k8sTypes';
import { PipelineCoreResourceKF, PipelineRunJobKF } from '~/concepts/pipelines/kfTypes';
import { byName, ProjectsContext } from '~/concepts/projects/ProjectsContext';
import DeletePipelineServerModal from '~/concepts/pipelines/content/DeletePipelineServerModal';
import { ConfigurePipelinesServerModal } from '~/concepts/pipelines/content/configurePipelinesServer/ConfigurePipelinesServerModal';
Expand All @@ -19,7 +20,14 @@ import { deleteServer } from '~/concepts/pipelines/utils';
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 PipelineContext = {
hasCR: boolean;
crInitializing: boolean;
Expand All @@ -30,6 +38,7 @@ type PipelineContext = {
refreshState: () => Promise<undefined>;
refreshAPIState: () => void;
apiState: APIState;
getJobInformation: GetJobInformation;
};

const PipelinesContext = React.createContext<PipelineContext>({
Expand All @@ -41,6 +50,10 @@ const PipelinesContext = React.createContext<PipelineContext>({
project: null as unknown as ProjectKind,
refreshState: async () => undefined,
refreshAPIState: () => undefined,
getJobInformation: () => ({
loading: false,
data: null,
}),
apiState: { apiAvailable: false, api: null as unknown as APIState['api'] },
});

Expand Down Expand Up @@ -70,6 +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 @@ -79,7 +93,6 @@ export const PipelineContextProvider: React.FC<PipelineContextProviderProps> = (
);

const [apiState, refreshAPIState] = useAPIState(hostPath);

let error = crLoadError || routeLoadError;
if (error || !project) {
error = error || new Error('Project not found');
Expand All @@ -104,6 +117,7 @@ export const PipelineContextProvider: React.FC<PipelineContextProviderProps> = (
namespace,
refreshState,
refreshAPIState,
getJobInformation,
}}
>
{children}
Expand All @@ -122,6 +136,7 @@ type UsePipelinesAPI = APIState & {
* Allows agnostic functionality to request all watched API to be reacquired.
* Triggering this will invalidate the memo for API - pay attention to only calling it once per need.
*/
getJobInformation: GetJobInformation;
refreshAllAPI: () => void;
};

Expand All @@ -142,11 +157,21 @@ export const usePipelinesAPI = (): UsePipelinesAPI => {
timedOut: serverTimedOut,
};

const getJobInformation: GetJobInformation = () => {
const jobStatus: JobStatus = {
loading: true,
data: null,
};

return jobStatus;
};

return {
pipelinesServer,
namespace,
project,
refreshAllAPI,
getJobInformation,
...apiState,
};
};
Expand Down

0 comments on commit 857cbf5

Please sign in to comment.