Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rerender only the schedule which got toggled #3244

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

pnaik1
Copy link
Contributor

@pnaik1 pnaik1 commented Sep 24, 2024

https://issues.redhat.com/browse/RHOAIENG-11858

Description

ggle one of the schedules to enable or disable it, and that should only trigger and re-render of that particular schedule

How Has This Been Tested?

  1. Use a pipeline version to create some schedules
  2. View schedules for that pipeline version
  3. Try to toggle the "Status" column for any row
    Check if It will only trigger re-render of the current row and re-fetch the current schedule

Test Impact

N/A

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.91%. Comparing base (a509cf4) to head (78872dc).
Report is 21 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3244      +/-   ##
==========================================
- Coverage   85.07%   84.91%   -0.17%     
==========================================
  Files        1292     1299       +7     
  Lines       28814    29006     +192     
  Branches     7749     7807      +58     
==========================================
+ Hits        24514    24629     +115     
- Misses       4300     4377      +77     
Files with missing lines Coverage Δ
...pipelineRecurringRun/PipelineRecurringRunTable.tsx 100.00% <100.00%> (ø)
...elineRecurringRun/PipelineRecurringRunTableRow.tsx 100.00% <100.00%> (ø)
.../src/pages/pipelines/global/runs/ScheduledRuns.tsx 100.00% <100.00%> (ø)

... and 67 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a509cf4...78872dc. Read the comment docs.

Copy link
Member

@DaoDaoNoCode DaoDaoNoCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, works well
/lgtm

@Gkrumbach07
Copy link
Member

Ok i think this is a bit more complicated then it should be. The tables data fetching hook can return a refresh function which only refreshes the recurring run data and not all data. and it will still not force update the whole thing

this is the old (in main now)

old.mov

This is the new

new.mov
diff --git a/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTable.tsx b/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTable.tsx
index d8fc9e75c..50036f023 100644
--- a/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTable.tsx
+++ b/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTable.tsx
@@ -18,7 +18,7 @@ import PipelineRecurringRunTableToolbar from './PipelineRecurringRunTableToolbar
 
 type PipelineRecurringRunTableProps = {
   recurringRuns: PipelineRecurringRunKFv2[];
-  refreshSingleRecurringRun: (recurringRun: PipelineRecurringRunKFv2) => void;
+  refresh: () => void;
   loading?: boolean;
   totalSize: number;
   page: number;
@@ -34,7 +34,7 @@ type PipelineRecurringRunTableProps = {
 
 const PipelineRecurringRunTable: React.FC<PipelineRecurringRunTableProps> = ({
   recurringRuns,
-  refreshSingleRecurringRun,
+  refresh,
   loading,
   totalSize,
   page,
@@ -124,7 +124,7 @@ const PipelineRecurringRunTable: React.FC<PipelineRecurringRunTableProps> = ({
         rowRenderer={(recurringRun) => (
           <PipelineRecurringRunTableRow
             key={recurringRun.recurring_run_id}
-            refreshSingleRecurringRun={refreshSingleRecurringRun}
+            refresh={refresh}
             isChecked={isSelected(recurringRun.recurring_run_id)}
             onToggleCheck={() => toggleSelection(recurringRun.recurring_run_id)}
             onDelete={() => setDeleteResources([recurringRun])}
diff --git a/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTableRow.tsx b/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTableRow.tsx
index 1787dbecc..c08e61c50 100644
--- a/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTableRow.tsx
+++ b/frontend/src/concepts/pipelines/content/tables/pipelineRecurringRun/PipelineRecurringRunTableRow.tsx
@@ -19,7 +19,7 @@ import useExperimentById from '~/concepts/pipelines/apiHooks/useExperimentById';
 
 type PipelineRecurringRunTableRowProps = {
   isChecked: boolean;
-  refreshSingleRecurringRun: (recurringRun: PipelineRecurringRunKFv2) => void;
+  refresh: () => void;
   onToggleCheck: () => void;
   onDelete: () => void;
   recurringRun: PipelineRecurringRunKFv2;
@@ -27,7 +27,7 @@ type PipelineRecurringRunTableRowProps = {
 
 const PipelineRecurringRunTableRow: React.FC<PipelineRecurringRunTableRowProps> = ({
   isChecked,
-  refreshSingleRecurringRun,
+  refresh,
   onToggleCheck,
   onDelete,
   recurringRun,
@@ -100,7 +100,7 @@ const PipelineRecurringRunTableRow: React.FC<PipelineRecurringRunTableRowProps>
           onToggle={(checked) =>
             api
               .updatePipelineRecurringRun({}, recurringRun.recurring_run_id, checked)
-              .then(() => refreshSingleRecurringRun(recurringRun))
+              .then(() => refresh())
           }
         />
       </Td>
diff --git a/frontend/src/pages/pipelines/global/runs/ScheduledRuns.tsx b/frontend/src/pages/pipelines/global/runs/ScheduledRuns.tsx
index 2639db627..350416ae4 100644
--- a/frontend/src/pages/pipelines/global/runs/ScheduledRuns.tsx
+++ b/frontend/src/pages/pipelines/global/runs/ScheduledRuns.tsx
@@ -16,32 +16,15 @@ 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 [
+    [{ items: recurringRuns, totalSize }, loaded, error, refresh],
+    { 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,
-        ),
-      );
-    });
-  };
-
   if (error) {
     return (
       <Bullseye>
@@ -92,8 +75,8 @@ const ScheduledRuns: React.FC = () => {
 
   return (
     <PipelineRecurringRunTable
-      refreshSingleRecurringRun={refreshSingleRecurringRun}
-      recurringRuns={updatedRecurringRuns}
+      refresh={refresh}
+      recurringRuns={recurringRuns}
       loading={!loaded}
       totalSize={totalSize}
       {...tableProps}

@pnaik1
Copy link
Contributor Author

pnaik1 commented Sep 26, 2024

@Gkrumbach07, I did notice the refresh coming from tables data fetching hook, However, I noted the mention in issue-11858 regarding refreshing and re-fetching only the updated recurring runs , rather than all of the recurring runs, I opted for this approach, but I am open to making changes, Please let me know your thoughts here

@Gkrumbach07
Copy link
Member

I did notice the refresh coming from tables data fetching hook, However, I noted the mention in issue-11858 regarding refreshing and re-fetching only the updated recurring runs , rather than all of the recurring runs, I opted for this approach, but I am open to making changes, Please let me know your thoughts here

The big issue was that it was re fetching the whole api and not just recurring runs. Just fetching recurring runs is one call and not that big of a deal. Optimizing it further to instead fetching just the the changed run is still just one call so there is not any gain. Plus the added complexity of having have another state variable and needing to search though it and replace the singular item in the list. I think we should keep it simple and use the refresh from the table hook

@pnaik1
Copy link
Contributor Author

pnaik1 commented Sep 26, 2024

Made the changes accordingly

Copy link
Member

@Gkrumbach07 Gkrumbach07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect! thank you
/lgtm

@Gkrumbach07
Copy link
Member

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold This PR is hold for some reason label Sep 26, 2024
Copy link
Member

@DaoDaoNoCode DaoDaoNoCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/unhold
/lgtm
This is a nice solution, I totally forgot we have refresh function for the table 😅

@openshift-ci openshift-ci bot removed the do-not-merge/hold This PR is hold for some reason label Sep 26, 2024
Copy link
Contributor

openshift-ci bot commented Sep 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DaoDaoNoCode, Gkrumbach07

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Gkrumbach07
Copy link
Member

/unhold

@openshift-merge-bot openshift-merge-bot bot merged commit 063d974 into opendatahub-io:main Sep 26, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants