Skip to content

Commit

Permalink
fix: remove "show" toggles on descendant component
Browse files Browse the repository at this point in the history
Closes #4670
  • Loading branch information
TrySound committed Jan 4, 2025
1 parent d577a1f commit abf92be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
19 changes: 12 additions & 7 deletions apps/builder/app/builder/features/navigator/navigator-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
showAttribute,
WsComponentMeta,
blockTemplateComponent,
descendantComponent,
} from "@webstudio-is/react-sdk";
import { ROOT_INSTANCE_ID, type Instance } from "@webstudio-is/sdk";
import {
Expand Down Expand Up @@ -281,22 +282,28 @@ const handleExpand = (item: TreeItem, isExpanded: boolean, all: boolean) => {
};

const ShowToggle = ({
instanceId,
instance,
value,
}: {
instanceId: Instance["id"];
instance: Instance;
value: boolean;
}) => {
// descendant component is not actually rendered
// but affects styling of nested elements
// hiding descendant does not hide nested elements and confuse users
if (instance.component === descendantComponent) {
return;
}
const toggleShow = () => {
const newValue = value === false;
serverSyncStore.createTransaction([$props], (props) => {
const { propsByInstanceId } = $propsIndex.get();
const instanceProps = propsByInstanceId.get(instanceId);
const instanceProps = propsByInstanceId.get(instance.id);
let showProp = instanceProps?.find((prop) => prop.name === showAttribute);
if (showProp === undefined) {
showProp = {
id: nanoid(),
instanceId,
instanceId: instance.id,
name: showAttribute,
type: "boolean",
value: newValue,
Expand Down Expand Up @@ -660,9 +667,7 @@ export const NavigatorTree = () => {
}
},
}}
action={
<ShowToggle instanceId={item.instance.id} value={show} />
}
action={<ShowToggle instance={item.instance} value={show} />}
>
<TreeNodeContent
meta={meta}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
showAttribute,
textContentAttribute,
collectionComponent,
descendantComponent,
} from "@webstudio-is/react-sdk";
import type { PropValue } from "../shared";
import { useStore } from "@nanostores/react";
Expand Down Expand Up @@ -195,19 +196,32 @@ export const usePropsLogic = ({

const initialPropsNames = new Set(meta.initialProps ?? []);

const systemProps: PropAndMeta[] = systemPropsMeta.map(({ name, meta }) => {
let saved = getAndDelete<Prop>(unprocessedSaved, name);
if (saved === undefined && meta.defaultValue !== undefined) {
saved = getStartingProp(instance.id, meta, name);
}
getAndDelete(unprocessedKnown, name);
initialPropsNames.delete(name);
return {
prop: saved,
propName: name,
meta,
};
});
const systemProps: PropAndMeta[] = systemPropsMeta
.filter(({ name }) => {
// descendant component is not actually rendered
// but affects styling of nested elements
// hiding descendant does not hide nested elements and confuse users
if (
instance.component === descendantComponent &&
name === showAttribute
) {
return false;
}
return true;
})
.map(({ name, meta }) => {
let saved = getAndDelete<Prop>(unprocessedSaved, name);
if (saved === undefined && meta.defaultValue !== undefined) {
saved = getStartingProp(instance.id, meta, name);
}
getAndDelete(unprocessedKnown, name);
initialPropsNames.delete(name);
return {
prop: saved,
propName: name,
meta,
};
});

const canHaveTextContent =
instanceMeta?.type === "container" &&
Expand Down

0 comments on commit abf92be

Please sign in to comment.