Skip to content

Commit

Permalink
fix(wab): Force install new copy of a template component
Browse files Browse the repository at this point in the history
Change-Id: I08183511fe716655b01381989830a76e5d7eecf2
GitOrigin-RevId: 261ff399b13e8cb019755cdcc27a19de53213df2
  • Loading branch information
sarahsga authored and actions-user committed Dec 17, 2024
1 parent e4a30ae commit f6a82b8
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 285 deletions.
11 changes: 8 additions & 3 deletions platform/wab/src/wab/client/Dnd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
Side,
sideToOrient,
} from "@/wab/shared/geom";
import { CloneOpts } from "@/wab/shared/insertable-templates/types";
import {
ContainerLayoutType,
ContainerType,
Expand Down Expand Up @@ -785,11 +786,15 @@ export class DragInsertManager {

public static async build(
studioCtx: StudioCtx,
spec: AddTplItem
spec: AddTplItem,
opts?: CloneOpts
): Promise<DragInsertManager> {
const targeters: NodeTargeter[] = [];
const extraInfo = spec.asyncExtraInfo
? await spec.asyncExtraInfo(studioCtx, { isDragging: true })
? await spec.asyncExtraInfo(studioCtx, {
isDragging: true,
...(opts ?? {}),
})
: undefined;
for (const vc of studioCtx.viewCtxs) {
// Ignore ViewCtx whose root is invisible.
Expand Down Expand Up @@ -839,7 +844,7 @@ export class DragInsertManager {
this.tentativeInsertion &&
this.tentativeInsertion.type !== "ErrorInsertion"
) {
const tpl = spec?.factory(this.tentativeVc, extraInfo, undefined);
const tpl = spec?.factory(this.tentativeVc, extraInfo);
if (tpl) {
this.studioCtx.setStudioFocusOnFrameContents(
this.tentativeVc.arenaFrame()
Expand Down
7 changes: 5 additions & 2 deletions platform/wab/src/wab/client/ProjectDependencyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ export class ProjectDependencyManager {
*/
getInsertableTemplate(meta: {
projectId: string;
componentName: string;
componentName?: string;
componentId?: string;
}): { component: Component; site: Site } | undefined {
const projectId = meta.projectId;
if (!this.insertableSites[projectId]) {
Expand All @@ -574,7 +575,9 @@ export class ProjectDependencyManager {

const site = this.insertableSites[projectId];
const components = site.components.filter((c) => !isFrameComponent(c));
const component = components.find((c) => c.name === meta.componentName);
const component = components.find(
(c) => c.name === meta.componentName || c.uuid === meta.componentId
);
return !component
? undefined
: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,7 @@ function insertFreestyleAsWrapper(viewCtx: ViewCtx, e: React.MouseEvent): void {
$(targetElt as HTMLElement)
);
if (tplToWrap && (isTplTagOrComponent(tplToWrap) || isTplSlot(tplToWrap))) {
const newNode = freestyleState.spec.factory(
viewOps.viewCtx(),
undefined,
undefined
);
const newNode = freestyleState.spec.factory(viewOps.viewCtx(), undefined);
if (newNode && isTplTag(newNode)) {
const wrapper = ensureKnownTplTag($$$(newNode).clear().one());
viewOps.insertAsParent(wrapper, tplToWrap);
Expand Down
8 changes: 2 additions & 6 deletions platform/wab/src/wab/client/components/canvas/view-ops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4720,11 +4720,7 @@ export class ViewOps {
tryInsertInsertableSpec<T>(
spec: {
key?: AddItemKey | string;
factory: (
viewCtx: ViewCtx,
extraInfo: T,
drawnRect?: Rect
) => TplNode | undefined;
factory: (viewCtx: ViewCtx, extraInfo: T) => TplNode | undefined;
},
loc: InsertRelLoc,
extraInfo: T,
Expand All @@ -4741,7 +4737,7 @@ export class ViewOps {
if (!tpl) {
return;
}
const cmptTpl = spec.factory(this.viewCtx(), extraInfo, undefined);
const cmptTpl = spec.factory(this.viewCtx(), extraInfo);
if (!cmptTpl) {
return;
}
Expand Down
Loading

0 comments on commit f6a82b8

Please sign in to comment.