Skip to content

Commit

Permalink
fix(wab): Code component variants in model
Browse files Browse the repository at this point in the history
Change-Id: I8b6792b7fcad6f08f04b9a1ba4f06b435f2ef4a2
GitOrigin-RevId: 322cead51a032675c2b5271ebc1b17863d917b70
  • Loading branch information
sarahsga authored and actions-user committed Dec 13, 2024
1 parent 3358b8d commit 7831aa3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
22 changes: 11 additions & 11 deletions platform/wab/src/wab/client/ProjectDependencyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ export class ProjectDependencyManager {
});

// We no longer plan to make any updates to plume site. So its unnecessary to re-fetch it if it has already been fetched.
if (!this.plumeSite) {
const bundler = new FastBundler();
// Get Plume site
const plumePkg = await this._sc.appCtx.api.getPlumePkg();
const plumeSite = unbundleProjectDependency(
bundler,
plumePkg.pkg,
plumePkg.depPkgs
).projectDependency.site;
this.plumeSite = this.inlineAssets(plumeSite);
}
// if (!this.plumeSite) {
// const bundler = new FastBundler();
// // Get Plume site
// const plumePkg = await this._sc.appCtx.api.getPlumePkg();
// const plumeSite = unbundleProjectDependency(
// bundler,
// plumePkg.pkg,
// plumePkg.depPkgs
// ).projectDependency.site;
// this.plumeSite = this.inlineAssets(plumeSite);
// }
}

/**
Expand Down
7 changes: 5 additions & 2 deletions platform/wab/src/wab/client/components/canvas/site-ops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1494,8 +1494,11 @@ export class SiteOps {
);
}

removeStyleVariantIfEmptyAndUnused(component: Component, variant: Variant) {
this.tplMgr.removeStyleVariantIfEmptyAndUnused(component, variant);
removeRegisteredVariantIfEmptyAndUnused(
component: Component,
variant: Variant
) {
this.tplMgr.removeRegisteredVariantIfEmptyAndUnused(component, variant);
this.studioCtx.ensureComponentStackFramesHasOnlyValidVariants(component);
this.studioCtx.pruneInvalidViewCtxs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const PrivateStyleVariantsPanel = observer(
studioCtx.changeUnsafe(() => {
studioCtx
.siteOps()
.removeStyleVariantIfEmptyAndUnused(
.removeRegisteredVariantIfEmptyAndUnused(
component,
variant
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ const ComponentStyleVariantRow = observer(
studioCtx.change(({ success }) => {
studioCtx
.siteOps()
.removeStyleVariantIfEmptyAndUnused(component, variant);
.removeRegisteredVariantIfEmptyAndUnused(component, variant);
return success();
})
}
Expand Down
17 changes: 16 additions & 1 deletion platform/wab/src/wab/client/components/variants/variant-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ClickStopper } from "@/wab/client/components/widgets";
import { StudioCtx } from "@/wab/client/studio-ctx/StudioCtx";
import { ensure, spawn } from "@/wab/shared/common";
import {
allCodeComponentVariants,
allComponentStyleVariants,
allPrivateStyleVariants,
} from "@/wab/shared/core/components";
Expand Down Expand Up @@ -33,6 +34,7 @@ import {
import {
getBaseVariant,
isBaseVariant,
isCodeComponentVariant,
isPrivateStyleVariant,
isScreenVariantGroup,
isStandaloneVariantGroup,
Expand Down Expand Up @@ -86,7 +88,10 @@ export function makeVariantMenu(opts: {
builder.genSection(undefined, (push) => {
push(
<Menu.Item key="edit-selectors" onClick={onEditSelectors}>
Edit interaction selectors
Edit{" "}
{isCodeComponentVariant(variant)
? "registered keys"
: "interaction selectors"}
</Menu.Item>
);
});
Expand Down Expand Up @@ -189,6 +194,10 @@ function genCopyToVariantMenu(
>
{isStyleVariant(variant) ? (
<div className="ml-lg">{variant.selectors.join(", ")}</div>
) : isCodeComponentVariant(variant) ? (
<div className="ml-lg">
{variant.codeComponentVariantKeys.join(", ")}
</div>
) : (
variant.name
)}
Expand Down Expand Up @@ -227,6 +236,12 @@ function genCopyToVariantMenu(
);
});

builder.genSection(`Registered Variants`, (push2) => {
allCodeComponentVariants(component).forEach((v) =>
genMenuForVariant(v, push2)
);
});

component.variantGroups.forEach((vg) => genMenuForVariantGroup(vg, push));
});
}
Expand Down
23 changes: 18 additions & 5 deletions platform/wab/src/wab/shared/TplMgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
hasScreenVariant,
hasStyleVariant,
isBaseVariant,
isCodeComponentVariant,
isGlobalVariant,
isGlobalVariantGroup,
isRegisteredVariant,
Expand Down Expand Up @@ -601,10 +602,22 @@ export class TplMgr {
});
}

removeStyleVariantIfEmptyAndUnused(component: Component, variant: Variant) {
assert(isStyleVariant(variant), "Given variant should be a style variant");
removeRegisteredVariantIfEmptyAndUnused(
component: Component,
variant: Variant
) {
assert(
isRegisteredVariant(variant),
"Given variant should be a registered variant"
);

if (isStyleVariant(variant) && variant.selectors.length > 0) {
return;
}

if (
ensure(variant.selectors, "Style variant must have selectors").length > 0
isCodeComponentVariant(variant) &&
variant.codeComponentVariantKeys.length > 0
) {
return;
}
Expand Down Expand Up @@ -2257,8 +2270,8 @@ export class TplMgr {
this.renameVariant(newVariant, newVariant.name);
} else {
assert(
isStyleVariant(variant),
"Variant with no parent is expected to be a style variant"
isRegisteredVariant(variant),
"Variant with no parent is expected to be a registered variant"
);
component.variants.push(newVariant);
}
Expand Down

0 comments on commit 7831aa3

Please sign in to comment.