feat: Add delete functionality to DataSourceSelector and ElementEditor components

This commit is contained in:
Nalvazhuthi
2025-12-18 17:55:01 +05:30
parent 5a1d1bdeaf
commit 3b645336bf
3 changed files with 46 additions and 16 deletions

View File

@@ -620,7 +620,7 @@ const ElementEditor: React.FC<ElementEditorProps> = ({
showEyeDropper={field.showEyeDropper} showEyeDropper={field.showEyeDropper}
/> />
))} ))}
{/* add delete */}
{singleValueFields.map((field, index) => ( {singleValueFields.map((field, index) => (
<DataSourceSelector <DataSourceSelector
key={field.id} key={field.id}
@@ -636,6 +636,13 @@ const ElementEditor: React.FC<ElementEditorProps> = ({
updateDataValue(selectedBlock, selectedElement, newDataValue); updateDataValue(selectedBlock, selectedElement, newDataValue);
}} }}
showEyeDropper={field.showEyeDropper} showEyeDropper={field.showEyeDropper}
showDeleteBtn={true}
onDelete={() => {
const current = Array.isArray(element.dataBinding?.dataValue) ? element.dataBinding!.dataValue : [];
const next = [...current];
next.splice(index, 1);
updateDataValue(selectedBlock, selectedElement, next);
}}
/> />
))} ))}
@@ -662,7 +669,7 @@ const ElementEditor: React.FC<ElementEditorProps> = ({
showEyeDropper={field.showEyeDropper} showEyeDropper={field.showEyeDropper}
/> />
))} ))}
{/* add delete */}
{multipleSourceFields.map((field, index) => ( {multipleSourceFields.map((field, index) => (
<DataSourceSelector <DataSourceSelector
key={field.id} key={field.id}
@@ -678,6 +685,13 @@ const ElementEditor: React.FC<ElementEditorProps> = ({
updateDataSource(selectedBlock, selectedElement, next); updateDataSource(selectedBlock, selectedElement, next);
}} }}
showEyeDropper={field.showEyeDropper} showEyeDropper={field.showEyeDropper}
showDeleteBtn={true}
onDelete={() => {
const current = Array.isArray(element.dataBinding?.dataSource) ? element.dataBinding!.dataSource : [];
const next = [...current];
next.splice(index, 1);
updateDataSource(selectedBlock, selectedElement, next);
}}
/> />
))} ))}

View File

@@ -1,6 +1,7 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { EyeDroperIcon } from "../../icons/ExportCommonIcons"; import { EyeDroperIcon } from "../../icons/ExportCommonIcons";
import RegularDropDownID from "./RegularDropDownID"; import RegularDropDownID from "./RegularDropDownID";
import { DeleteIcon } from "../../icons/ContextMenuIcons";
type DataSourceSelectorProps = { type DataSourceSelectorProps = {
label?: string; label?: string;
@@ -12,9 +13,11 @@ type DataSourceSelectorProps = {
onSelect: (value: { id: string; label: string }) => void; onSelect: (value: { id: string; label: string }) => void;
eyeDropperActive?: boolean; // initial state eyeDropperActive?: boolean; // initial state
showEyeDropper?: boolean; showEyeDropper?: boolean;
showDeleteBtn?: boolean;
onDelete?: () => void;
}; };
const DataSourceSelector: React.FC<DataSourceSelectorProps> = ({ label = "Data Source", options, selected, onSelect, showEyeDropper = true }) => { const DataSourceSelector: React.FC<DataSourceSelectorProps> = ({ label = "Data Source", options, selected, onSelect, showEyeDropper = true, showDeleteBtn, onDelete }) => {
// Local state to toggle EyeDropper // Local state to toggle EyeDropper
const [isEyeActive, setIsEyeActive] = useState(false); const [isEyeActive, setIsEyeActive] = useState(false);
@@ -31,6 +34,12 @@ const DataSourceSelector: React.FC<DataSourceSelectorProps> = ({ label = "Data S
<EyeDroperIcon isActive={isEyeActive} /> <EyeDroperIcon isActive={isEyeActive} />
</div> </div>
)} )}
{showDeleteBtn && (
<div className="delete" onClick={() => onDelete?.()} style={{ cursor: onDelete ? "pointer" : "default" }}>
<DeleteIcon />
</div>
)}
</div> </div>
</div> </div>
); );

View File

@@ -287,6 +287,7 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
z-index: 100; z-index: 100;
svg { svg {
cursor: grab; cursor: grab;
} }
@@ -651,6 +652,7 @@
display: flex; display: flex;
padding: 3px; padding: 3px;
border-radius: 2px; border-radius: 2px;
cursor: pointer;
&.active { &.active {
@@ -658,6 +660,10 @@
} }
} }
.delete {
cursor: pointer;
}
.regularDropdown-container { .regularDropdown-container {
.icon { .icon {
padding: 0; padding: 0;
@@ -696,6 +702,7 @@
position: fixed; position: fixed;
top: 80px; top: 80px;
right: 40px; right: 40px;
.appearance { .appearance {
.design-datas-wrapper { .design-datas-wrapper {