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

chore: fix blueprint operation inconsistency for zone #36980

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
.markdown {
color: var(--color-fg);

&::after,
riodeuno marked this conversation as resolved.
Show resolved Hide resolved
&::before {
/* This is required to remove the compensators of capsizing that comes up due to use of `wds-body-text` class */
content: none !important;
}

table {
border: var(--border-width-1) solid var(--color-bd);
border-collapse: separate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import log from "loglevel";
import { generateDefaultLayoutPreset } from "layoutSystems/anvil/layoutComponents/presets/DefaultLayoutPreset";
import { addWidgetsToPreset } from "layoutSystems/anvil/utils/layouts/update/additionUtils";
import { addNewAnvilWidgetToDSL } from "./helpers";
import { klona } from "klona";

// The suggested widget functionality allows users to bind data from the Query pane
// to a new or existing widget on the Canvas.
Expand Down Expand Up @@ -109,7 +110,8 @@ export function* getUpdatedListOfWidgetsAfterAddingNewWidget(
isSection: boolean, // Indicates if the drop zone is a section
) {
const { alignment, canvasId } = highlight;
const allWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
const allWidgetsFromRedux: CanvasWidgetsReduxState = yield select(getWidgets);
const allWidgets = klona(allWidgetsFromRedux) as CanvasWidgetsReduxState;
Copy link
Contributor Author

@jsartisan jsartisan Oct 22, 2024

Choose a reason for hiding this comment

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

@riodeuno Is this safe? The use case is aichatwidget wants to modify the parent zone's elevatedBackground to false. ( that code is written in aichatbot blueprint operation ).
So the problem I was facing is if there is an existing zone that is empty and I drop aichatwidget into it, I was not able to modify the zone elevated background, as the redux state was coming from immer reducer and it was immutable, due to which the property was readonly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jsartisan This is a problem because we will quickly lose track of where the original values were updated. Ideally, we should let the functions return what needs to be updated, then in this function we should use something like produce from immer to update the appropriate paths.

I'm not a 100% sure of what is happening in this PR, so I can't provide an alternative. Could you elaborate in the description on "how" we're going about changing the zone's elevatedBackground property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@riodeuno Updated the description. Let me know if you need more info.


const parentWidgetWithLayout = allWidgets[canvasId];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { addNewAnvilWidgetToDSL } from "layoutSystems/anvil/integrations/sagas/a
export function* createSectionAndAddWidget(
allWidgets: CanvasWidgetsReduxState,
highlight: AnvilHighlightInfo,
widgets: WidgetLayoutProps[],
draggedWidgets: WidgetLayoutProps[],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

used better contextual name to avoid confusion.
widgets felt like it is all the widgets but it is only the dragged widgets.

parentId: string,
) {
/**
Expand Down Expand Up @@ -48,7 +48,7 @@ export function* createSectionAndAddWidget(
yield call(
addWidgetsToSection,
updatedWidgets,
widgets,
draggedWidgets,
highlight,
sectionProps,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function* createZoneAndAddWidgets(
updatedWidgets,
draggedWidgets,
highlight,
zoneProps,
zoneProps.widgetId,
);

return res;
Expand All @@ -68,13 +68,11 @@ export function* addWidgetsToZone(
allWidgets: CanvasWidgetsReduxState,
draggedWidgets: WidgetLayoutProps[],
highlight: AnvilHighlightInfo,
zone: WidgetProps,
zoneWidgetId: string,
) {
let updatedWidgets: CanvasWidgetsReduxState = { ...allWidgets };
const zoneProps = { ...zone };
const preset: LayoutProps[] = zoneProps.layout;
const preset: LayoutProps[] = updatedWidgets[zoneWidgetId].layout;
let zoneLayout: LayoutProps = preset[0];
const { widgetId: zoneWidgetId } = zoneProps;

/**
* If dragged widget is a new widget,
Expand All @@ -86,7 +84,6 @@ export function* addWidgetsToZone(
zoneWidgetId,
draggedWidgets,
);
zoneProps.children = updatedWidgets[zoneWidgetId].children;

/**
* Split new widgets based on type.
Expand Down Expand Up @@ -127,14 +124,11 @@ export function* addWidgetsToZone(
/**
* Update zone widget with the updated preset.
*/
zoneProps.layout = [zoneLayout];
updatedWidgets[zoneWidgetId].layout = [zoneLayout];

return {
canvasWidgets: {
...updatedWidgets,
[zoneProps.widgetId]: zoneProps,
},
zone: zoneProps,
canvasWidgets: updatedWidgets,
zone: updatedWidgets[zoneWidgetId],
};
}

Expand Down Expand Up @@ -219,7 +213,7 @@ function* moveWidgetsToNewLayout(
widgets,
transformMovedWidgets(widgets, movedWidgets, highlight),
highlight,
zone,
zone.widgetId,
);

return canvasWidgets;
Expand Down
Loading