Skip to content

Commit

Permalink
fix: remove "show" toggles on descendant component (#4711)
Browse files Browse the repository at this point in the history
Closes #4670
  • Loading branch information
TrySound authored Jan 4, 2025
1 parent 44ca2d2 commit 85147c8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/fixtures-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
- name: Testing cli build command
run: pnpm --filter='./fixtures/*' run --parallel fixtures:build

- name: Prepare for diffing
run: find . -type f -path "./fixtures/*/.webstudio/data.json" -exec sed 's|"origin": ".*"|"origin": "https://main.development.webstudio.is"|g' {} +

- name: Test git diff
# This command will fail if there are uncommitted changes, i.e something has broken
run: git diff --name-only HEAD --exit-code
Expand Down
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 85147c8

Please sign in to comment.