fix the entity collapsable right panel (#21317)

* fix the entity collapsable right panel

* minor condition fix

* optimize the code
This commit is contained in:
Ashish Gupta 2025-05-20 18:52:03 +05:30 committed by GitHub
parent 4dab2be0ab
commit 25a00c6d1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,7 @@
* limitations under the License.
*/
import { AxiosError } from 'axios';
import { isEmpty, once } from 'lodash';
import { once } from 'lodash';
import React, {
useCallback,
useContext,
@ -152,30 +152,40 @@ export const GenericProvider = <T extends Omit<EntityReference, 'type'>>({
// Handle the left side panel expand collapse
useEffect(() => {
setLayout((prev) => {
if (!prev || !leftPanelWidget) {
// If layout is empty or no left panel widget, return as is
if (!prev?.length || !leftPanelWidget) {
return prev;
}
// Check if we need to update the layout
const currentLeftPanel = prev.find((widget) =>
widget.i.startsWith(DetailPageWidgetKeys.LEFT_PANEL)
);
const targetWidth = isTabExpanded ? 8 : 6;
// If the width is already what we want, don't update
if (currentLeftPanel?.w === targetWidth) {
return prev;
}
if (isTabExpanded) {
const widget = leftPanelWidget;
widget.w = 8;
// Store the expanded layout
expandedLayout.current = prev;
return [widget];
} else {
const leftPanelWidget = expandedLayout.current.find((widget) =>
widget.i.startsWith(DetailPageWidgetKeys.LEFT_PANEL)
);
if (leftPanelWidget) {
leftPanelWidget.w = 6;
}
// Restore the collapsed layout
return isEmpty(expandedLayout.current) ? prev : expandedLayout.current;
// Store the current layout before modifying
expandedLayout.current = [...prev];
}
// Get the source layout to modify
const sourceLayout = isTabExpanded
? prev
: expandedLayout.current || prev;
// Update the layout with new width
return sourceLayout.map((widget) => ({
...widget,
w: widget.i.startsWith(DetailPageWidgetKeys.LEFT_PANEL)
? targetWidth
: widget.w,
}));
});
}, [isTabExpanded, leftPanelWidget]);