andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From 108dd02791da19915beb29c872516c52a74fc637 Mon Sep 17 00:00:00 2001
From: Simon Pichugin <spichugi@redhat.com>
Date: Fri, 5 Aug 2022 10:08:45 -0700
Subject: [PATCH 3/5] Issue 5399 - UI - LDAP Editor is not updated when we
 switch instances (#5400)

Description: We don't refresh LDAP Editor when we switch instances.
It may lead to unpleasant errors.

Add componentDidUpdate function with the appropriate processing and
properties.

Fixes: https://github.com/389ds/389-ds-base/issues/5399

Reviewed by: @mreynolds389 (Thanks!)
---
 src/cockpit/389-console/src/LDAPEditor.jsx | 19 +++++++++++++++++++
 src/cockpit/389-console/src/ds.jsx         |  1 +
 2 files changed, 20 insertions(+)

diff --git a/src/cockpit/389-console/src/LDAPEditor.jsx b/src/cockpit/389-console/src/LDAPEditor.jsx
index 70324be39..04fc97d41 100644
--- a/src/cockpit/389-console/src/LDAPEditor.jsx
+++ b/src/cockpit/389-console/src/LDAPEditor.jsx
@@ -60,6 +60,7 @@ export class LDAPEditor extends React.Component {
 
         this.state = {
             activeTabKey: 0,
+            firstLoad: true,
             keyIndex: 0,
             suffixList: [],
             changeLayout: false,
@@ -249,6 +250,12 @@ export class LDAPEditor extends React.Component {
             baseDn: this.state.baseDN
         };
 
+        if (this.state.firstLoad) {
+            this.setState({
+                firstLoad: false
+            });
+        }
+
         this.setState({
             searching: true,
             loading: refresh
@@ -361,6 +368,18 @@ export class LDAPEditor extends React.Component {
         });
     }
 
+    componentDidUpdate(prevProps) {
+        if (this.props.wasActiveList.includes(7)) {
+            if (this.state.firstLoad) {
+                this.handleReload(true);
+            } else {
+                if (this.props.serverId !== prevProps.serverId) {
+                    this.handleReload(true);
+                }
+            }
+        }
+    }
+
     getPageData (page, perPage) {
         if (page === 1) {
             const pagedRows = this.state.rows.slice(0, 2 * perPage); // Each parent has a single child.
diff --git a/src/cockpit/389-console/src/ds.jsx b/src/cockpit/389-console/src/ds.jsx
index e88915e41..de4385292 100644
--- a/src/cockpit/389-console/src/ds.jsx
+++ b/src/cockpit/389-console/src/ds.jsx
@@ -764,6 +764,7 @@ export class DSInstance extends React.Component {
                                     key="ldap-editor"
                                     addNotification={this.addNotification}
                                     serverId={this.state.serverId}
+                                    wasActiveList={this.state.wasActiveList}
                                     setPageSectionVariant={this.setPageSectionVariant}
                                 />
                             </Tab>
-- 
2.37.1