Copilot commented on code in PR #710:
URL: https://github.com/apache/shenyu-dashboard/pull/710#discussion_r4229372514
##########
src/routes/Plugin/Discovery/index.js:
##########
@@ -104,6 +108,21 @@ export default class DiscoveryProxy extends Component {
});
}
+ componentDidUpdate(prevProps) {
+ const { plugins } = this.props;
+ if (plugins && plugins !== prevProps.plugins) {
+ this.syncPluginEnabled(plugins);
+ }
+ }
+
+ syncPluginEnabled = (plugins) => {
+ const { pluginName } = this.state;
+ const plugin = this.getPlugin(plugins, pluginName);
+ if (plugin) {
+ this.setState({ isPluginEnabled: plugin.enabled ?? false });
Review Comment:
Syncing only when `plugins !== prevProps.plugins` relies on the array
reference changing; if the store mutates the array in place (or reuses
references), enabled-state changes could be missed. A more robust approach is
to compare the derived enabled value (or compare previous vs current plugin’s
`enabled` field) and only call `setState` when that derived value changes.
##########
src/routes/Plugin/Discovery/index.js:
##########
@@ -104,6 +108,21 @@ export default class DiscoveryProxy extends Component {
});
}
+ componentDidUpdate(prevProps) {
+ const { plugins } = this.props;
+ if (plugins && plugins !== prevProps.plugins) {
+ this.syncPluginEnabled(plugins);
+ }
+ }
+
+ syncPluginEnabled = (plugins) => {
+ const { pluginName } = this.state;
+ const plugin = this.getPlugin(plugins, pluginName);
+ if (plugin) {
+ this.setState({ isPluginEnabled: plugin.enabled ?? false });
+ }
+ };
Review Comment:
`syncPluginEnabled` only updates state when the plugin is found. If
`plugins` is empty (or the plugin is missing after a namespace switch / data
refresh), `isPluginEnabled` will remain stale (e.g., stay `true`). Consider
always setting `isPluginEnabled` based on the lookup result (set `false` when
`plugin` is not found), and remove the `plugins.length > 0` guard in
`componentDidMount` so the state is correctly derived even when the list is
empty.
##########
src/routes/Plugin/Discovery/index.js:
##########
@@ -78,7 +78,11 @@ export default class DiscoveryProxy extends Component {
}
componentDidMount() {
- const { dispatch, currentPage, pageSize, currentNamespaceId } = this.props;
+ const { dispatch, currentPage, pageSize, currentNamespaceId, plugins } =
+ this.props;
+ if (plugins && plugins.length > 0) {
+ this.syncPluginEnabled(plugins);
+ }
Review Comment:
`syncPluginEnabled` only updates state when the plugin is found. If
`plugins` is empty (or the plugin is missing after a namespace switch / data
refresh), `isPluginEnabled` will remain stale (e.g., stay `true`). Consider
always setting `isPluginEnabled` based on the lookup result (set `false` when
`plugin` is not found), and remove the `plugins.length > 0` guard in
`componentDidMount` so the state is correctly derived even when the list is
empty.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]