Skip to content

Commit bee9615

Browse files
authored
feat: remove "delete" button from props asset (#5004)
In image and link components we allow to delete added asset. Though with tooltip and "reset/delete" we no longer need additional controls. <img width="287" alt="Screenshot 2025-03-15 at 13 36 02" src="https://github.com/user-attachments/assets/d9923253-2ef6-4628-be2f-699278a63ddc" /> <img width="246" alt="Screenshot 2025-03-15 at 13 37 28" src="https://github.com/user-attachments/assets/b2808dcb-69d9-4a17-ba0a-3dbae76f2cd6" />
1 parent 2bb6e9d commit bee9615

File tree

7 files changed

+5
-74
lines changed

7 files changed

+5
-74
lines changed

apps/builder/app/builder/features/settings-panel/controls/file.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const FileControl = ({
4848
propName,
4949
computedValue,
5050
onChange,
51-
onDelete,
5251
}: ControlProps<"file">) => {
5352
const id = useId();
5453

@@ -61,8 +60,6 @@ export const FileControl = ({
6160
(value) => {
6261
if (value === undefined) {
6362
return;
64-
} else if (value === "") {
65-
onDelete();
6663
} else if (prop?.type === "expression") {
6764
updateExpressionValue(prop.value, value);
6865
} else {
@@ -110,7 +107,6 @@ export const FileControl = ({
110107
prop={prop?.type === "asset" ? prop : undefined}
111108
accept={meta.accept}
112109
onChange={onChange}
113-
onDelete={onDelete}
114110
/>
115111
</Flex>
116112
</VerticalLayout>

apps/builder/app/builder/features/settings-panel/controls/select-asset.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { useMemo } from "react";
22
import { computed } from "nanostores";
33
import { useStore } from "@nanostores/react";
4-
import {
5-
Button,
6-
Flex,
7-
SmallIconButton,
8-
Text,
9-
FloatingPanel,
10-
} from "@webstudio-is/design-system";
11-
import { TrashIcon } from "@webstudio-is/icons";
4+
import { Button, Flex, Text, FloatingPanel } from "@webstudio-is/design-system";
125
import type { Prop } from "@webstudio-is/sdk";
136
import { $assets } from "~/shared/nano-states";
147
import { ImageManager } from "~/builder/shared/image-manager";
@@ -30,10 +23,9 @@ type Props = {
3023
accept?: string;
3124
prop?: Extract<Prop, { type: "asset" }>;
3225
onChange: AssetControlProps["onChange"];
33-
onDelete: AssetControlProps["onDelete"];
3426
};
3527

36-
export const SelectAsset = ({ prop, onChange, onDelete, accept }: Props) => {
28+
export const SelectAsset = ({ prop, onChange, accept }: Props) => {
3729
const $asset = useMemo(
3830
() =>
3931
computed($assets, (assets) =>
@@ -63,13 +55,6 @@ export const SelectAsset = ({ prop, onChange, onDelete, accept }: Props) => {
6355
{asset?.name ?? "Choose source"}
6456
</Button>
6557
</FloatingPanel>
66-
{prop ? (
67-
<SmallIconButton
68-
icon={<TrashIcon />}
69-
onClick={onDelete}
70-
variant="destructive"
71-
/>
72-
) : null}
7358
</Flex>
7459
);
7560
};

apps/builder/app/builder/features/settings-panel/controls/url.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ type BaseControlProps = {
5353
prop: UrlControlProps["prop"];
5454
value: string;
5555
onChange: UrlControlProps["onChange"];
56-
onDelete: UrlControlProps["onDelete"];
5756
};
5857

5958
const Row = ({ children }: { children: ReactNode }) => (
@@ -405,12 +404,11 @@ const BasePage = ({ prop, onChange }: BaseControlProps) => {
405404
);
406405
};
407406

408-
const BaseAttachment = ({ prop, onChange, onDelete }: BaseControlProps) => (
407+
const BaseAttachment = ({ prop, onChange }: BaseControlProps) => (
409408
<Row>
410409
<SelectAsset
411410
prop={prop?.type === "asset" ? prop : undefined}
412411
onChange={onChange}
413-
onDelete={onDelete}
414412
/>
415413
</Row>
416414
);
@@ -463,7 +461,6 @@ export const UrlControl = ({
463461
propName,
464462
computedValue,
465463
onChange,
466-
onDelete,
467464
}: UrlControlProps) => {
468465
const value = String(computedValue ?? "");
469466
const { value: mode, set: setMode } = useLocalValue<Mode>(
@@ -520,7 +517,6 @@ export const UrlControl = ({
520517
prop={prop}
521518
value={value}
522519
onChange={onChange}
523-
onDelete={onDelete}
524520
/>
525521
<BindingPopover
526522
scope={scope}

apps/builder/app/builder/features/settings-panel/props-section/props-section.stories.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,6 @@ const startingProps: Prop[] = [
370370
export const Story = () => {
371371
const [props, setProps] = useState(startingProps);
372372

373-
const handleDelete = (id: Prop["id"]) => {
374-
setProps((current) => current.filter((prop) => prop.id !== id));
375-
};
376-
377373
const handleUpdate = (prop: Prop) => {
378374
setProps((current) => {
379375
const exists = current.find((item) => item.id === prop.id) !== undefined;
@@ -387,7 +383,6 @@ export const Story = () => {
387383
instance,
388384
props,
389385
updateProp: handleUpdate,
390-
deleteProp: handleDelete,
391386
});
392387

393388
return (

apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ const matchOrSuggestToCreate = (
5858

5959
const renderProperty = (
6060
{ propsLogic: logic, propValues, component, instanceId }: PropsSectionProps,
61-
{ prop, propName, meta }: PropAndMeta,
62-
{ deletable }: { deletable?: boolean } = {}
61+
{ prop, propName, meta }: PropAndMeta
6362
) =>
6463
renderControl({
6564
key: propName,
@@ -68,20 +67,6 @@ const renderProperty = (
6867
prop,
6968
computedValue: propValues.get(propName) ?? meta.defaultValue,
7069
propName,
71-
deletable:
72-
deletable ??
73-
((meta.defaultValue === undefined || meta.defaultValue !== prop?.value) &&
74-
meta.required === false &&
75-
prop !== undefined),
76-
onDelete: () => {
77-
if (prop) {
78-
logic.handleDelete(prop);
79-
if (component === "Image" && propName === "src") {
80-
logic.handleDeleteByPropName("width");
81-
logic.handleDeleteByPropName("height");
82-
}
83-
}
84-
},
8570
onChange: (propValue) => {
8671
logic.handleChange({ prop, propName }, propValue);
8772

@@ -221,9 +206,7 @@ export const PropsSection = (props: PropsSectionProps) => {
221206
}}
222207
/>
223208
)}
224-
{logic.addedProps.map((item) =>
225-
renderProperty(props, item, { deletable: true })
226-
)}
209+
{logic.addedProps.map((item) => renderProperty(props, item))}
227210
{logic.initialProps.map((item) => renderProperty(props, item))}
228211
</Flex>
229212
</CollapsibleSectionWithAddButton>
@@ -265,12 +248,6 @@ export const PropsSectionContainer = ({
265248
props.set(update.id, update);
266249
});
267250
},
268-
269-
deleteProp: (propId) => {
270-
serverSyncStore.createTransaction([$props], (props) => {
271-
props.delete(propId);
272-
});
273-
},
274251
});
275252

276253
const hasMetaProps = Object.keys(logic.meta.props).length !== 0;

apps/builder/app/builder/features/settings-panel/props-section/use-props-logic.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ type UsePropsLogicInput = {
124124
instance: Instance;
125125
props: Prop[];
126126
updateProp: (update: Prop) => void;
127-
deleteProp: (id: Prop["id"]) => void;
128127
};
129128

130129
const getAndDelete = <Value>(map: Map<string, Value>, key: string) => {
@@ -138,7 +137,6 @@ export const usePropsLogic = ({
138137
instance,
139138
props,
140139
updateProp,
141-
deleteProp,
142140
}: UsePropsLogicInput) => {
143141
const isContentMode = useStore($isContentMode);
144142

@@ -301,24 +299,10 @@ export const usePropsLogic = ({
301299
);
302300
};
303301

304-
const handleDeleteByPropName = (propName: string) => {
305-
const prop = props.find((prop) => prop.name === propName);
306-
307-
if (prop) {
308-
deleteProp(prop.id);
309-
}
310-
};
311-
312-
const handleDelete = (prop: Prop) => {
313-
deleteProp(prop.id);
314-
};
315-
316302
return {
317303
handleAdd,
318304
handleChange,
319-
handleDelete,
320305
handleChangeByPropName,
321-
handleDeleteByPropName,
322306
meta,
323307
/** Similar to Initial, but displayed as a separate group in UI etc.
324308
* Currentrly used only for the ID prop. */

apps/builder/app/builder/features/settings-panel/shared.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ export type ControlProps<Control> = {
7878
prop: Prop | undefined;
7979
propName: string;
8080
computedValue: unknown;
81-
deletable: boolean;
8281
onChange: (value: PropValue) => void;
83-
onDelete: () => void;
8482
};
8583

8684
const SimpleLabel = ({

0 commit comments

Comments
 (0)