Skip to content

Commit

Permalink
rerender only the schedules which toggled
Browse files Browse the repository at this point in the history
  • Loading branch information
pnaik1 committed Sep 24, 2024
1 parent a509cf4 commit 0b6b1c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PipelineRecurringRunTableToolbar from './PipelineRecurringRunTableToolbar

type PipelineRecurringRunTableProps = {
recurringRuns: PipelineRecurringRunKFv2[];
refreshSingleRecurringRun: (recurringRun: PipelineRecurringRunKFv2) => void;
loading?: boolean;
totalSize: number;
page: number;
Expand All @@ -33,6 +34,7 @@ type PipelineRecurringRunTableProps = {

const PipelineRecurringRunTable: React.FC<PipelineRecurringRunTableProps> = ({
recurringRuns,
refreshSingleRecurringRun,
loading,
totalSize,
page,
Expand Down Expand Up @@ -122,6 +124,7 @@ const PipelineRecurringRunTable: React.FC<PipelineRecurringRunTableProps> = ({
rowRenderer={(recurringRun) => (
<PipelineRecurringRunTableRow
key={recurringRun.recurring_run_id}
refreshSingleRecurringRun={refreshSingleRecurringRun}
isChecked={isSelected(recurringRun.recurring_run_id)}
onToggleCheck={() => toggleSelection(recurringRun.recurring_run_id)}
onDelete={() => setDeleteResources([recurringRun])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ import useExperimentById from '~/concepts/pipelines/apiHooks/useExperimentById';

type PipelineRecurringRunTableRowProps = {
isChecked: boolean;
refreshSingleRecurringRun: (recurringRun: PipelineRecurringRunKFv2) => void;
onToggleCheck: () => void;
onDelete: () => void;
recurringRun: PipelineRecurringRunKFv2;
};

const PipelineRecurringRunTableRow: React.FC<PipelineRecurringRunTableRowProps> = ({
isChecked,
refreshSingleRecurringRun,
onToggleCheck,
onDelete,
recurringRun,
}) => {
const navigate = useNavigate();
const { experimentId, pipelineId, pipelineVersionId } = useParams();
const { namespace, api, refreshAllAPI } = usePipelinesAPI();
const { namespace, api } = usePipelinesAPI();
const { version, loaded, error } = usePipelineRunVersionInfo(recurringRun);
const isExperimentsAvailable = useIsAreaAvailable(SupportedArea.PIPELINE_EXPERIMENTS).status;
const isExperimentsContext = isExperimentsAvailable && experimentId;
Expand Down Expand Up @@ -98,7 +100,7 @@ const PipelineRecurringRunTableRow: React.FC<PipelineRecurringRunTableRowProps>
onToggle={(checked) =>
api
.updatePipelineRecurringRun({}, recurringRun.recurring_run_id, checked)
.then(refreshAllAPI)
.then(() => refreshSingleRecurringRun(recurringRun))
}
/>
</Td>
Expand Down
22 changes: 21 additions & 1 deletion frontend/src/pages/pipelines/global/runs/ScheduledRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,32 @@ import CreateScheduleButton from '~/pages/pipelines/global/runs/CreateScheduleBu
import { useContextExperimentArchived as useIsExperimentArchived } from '~/pages/pipelines/global/experiments/ExperimentContext';
import { usePipelineRecurringRunsTable } from '~/concepts/pipelines/content/tables/pipelineRecurringRun/usePipelineRecurringRunTable';
import PipelineRecurringRunTable from '~/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTable';
import { PipelineRecurringRunKFv2 } from '~/concepts/pipelines/kfTypes';
import { usePipelinesAPI } from '~/concepts/pipelines/context';

const ScheduledRuns: React.FC = () => {
const { experimentId, pipelineVersionId } = useParams();
const [[{ items: recurringRuns, totalSize }, loaded, error], { initialLoaded, ...tableProps }] =
usePipelineRecurringRunsTable({ experimentId, pipelineVersionId });
const isExperimentArchived = useIsExperimentArchived();

const { api } = usePipelinesAPI();
const [updatedRecurringRuns, setUpdatedRecurringRuns] = React.useState<
PipelineRecurringRunKFv2[]
>([]);

React.useEffect(() => setUpdatedRecurringRuns(recurringRuns), [recurringRuns]);

const refreshSingleRecurringRun = (recurringRun: PipelineRecurringRunKFv2) => {
api.getPipelineRecurringRun({}, recurringRun.recurring_run_id).then((newState) => {
setUpdatedRecurringRuns((prevState) =>
prevState.map((run) =>
run.recurring_run_id === recurringRun.recurring_run_id ? newState : run,

Check warning on line 39 in frontend/src/pages/pipelines/global/runs/ScheduledRuns.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/pipelines/global/runs/ScheduledRuns.tsx#L36-L39

Added lines #L36 - L39 were not covered by tests
),
);
});
};

if (error) {
return (
<Bullseye>
Expand Down Expand Up @@ -73,7 +92,8 @@ const ScheduledRuns: React.FC = () => {

return (
<PipelineRecurringRunTable
recurringRuns={recurringRuns}
refreshSingleRecurringRun={refreshSingleRecurringRun}
recurringRuns={updatedRecurringRuns}
loading={!loaded}
totalSize={totalSize}
{...tableProps}
Expand Down

0 comments on commit 0b6b1c6

Please sign in to comment.