Skip to content

Commit 85f5230

Browse files
feat: improve delete blueprint visibility (#1273)
Co-authored-by: Neelasha Bhattacharjee <46113280+Neelashab@users.noreply.github.com>
1 parent e3fe328 commit 85f5230

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/ui/src/builder/sidebar/BuilderSidebarComponentTree.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class="rootBranch"
1111
:component-id="rootComponentId"
1212
:query="query"
13+
@delete="handleComponentDelete"
1314
/>
1415
</div>
1516

@@ -36,6 +37,7 @@
3637
:key="blueprint.id"
3738
:component-id="blueprint.id"
3839
:query="query"
40+
@delete="handleComponentDelete"
3941
/>
4042
<div
4143
v-if="section.items.length === 0"
@@ -94,11 +96,8 @@ const wfbm = inject(injectionKeys.builderManager);
9496
const query = ref("");
9597
9698
const tracking = useWriterTracking(wf);
97-
const { createAndInsertComponent, setContentValue } = useComponentActions(
98-
wf,
99-
wfbm,
100-
tracking,
101-
);
99+
const { createAndInsertComponent, setContentValue, removeComponentSubtree } =
100+
useComponentActions(wf, wfbm, tracking);
102101
103102
const rootComponentId = wfbm.activeRootId;
104103
@@ -201,6 +200,10 @@ async function addSharedBlueprint() {
201200
wfbm.setSelection(pageId);
202201
tracking.track("blueprints_shared_added");
203202
}
203+
204+
function handleComponentDelete(componentId: string) {
205+
removeComponentSubtree(componentId);
206+
}
204207
</script>
205208

206209
<style scoped>

src/ui/src/builder/sidebar/BuilderSidebarComponentTreeBranch.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
:disable-collapse="COMPONENT_TYPES_ROOT.has(component.type)"
1818
:no-nested-space="COMPONENT_TYPES_ROOT.has(component.type)"
1919
:collapsed="isOutsideActivePage"
20+
:right-click-options="rightClickDropdownOptions"
21+
:dropdown-options="
22+
component?.type === 'blueprints_blueprint' &&
23+
isDeleteAllowed(props.componentId)
24+
? rightClickDropdownOptions
25+
: undefined
26+
"
2027
@select="select"
28+
@dropdown-select="handleDropdownSelect($event)"
2129
@dragover="handleDragOver"
2230
@dragstart="handleDragStart"
2331
@dragend="handleDragEnd"
@@ -53,6 +61,7 @@
5361
:component-id="childComponent.id"
5462
:query="query"
5563
@expand-branch="expand"
64+
@delete="$emit('delete', $event)"
5665
/>
5766
</template>
5867
</BuilderTree>
@@ -83,6 +92,7 @@ import {
8392
COMPONENT_TYPES_TOP_LEVEL,
8493
} from "@/constants/component";
8594
import WdsIcon from "@/wds/WdsIcon.vue";
95+
import type { WdsDropdownMenuOption } from "@/wds/WdsDropdownMenu.vue";
8696
8797
const props = defineProps({
8898
componentId: { type: String, required: true },
@@ -91,6 +101,9 @@ const props = defineProps({
91101
92102
const treeBranch = ref<ComponentPublicInstance<typeof BuilderTree>>();
93103
104+
const rightClickDropdownOptions: WdsDropdownMenuOption[] = [
105+
{ label: "Delete", value: "delete", icon: "trash-2" },
106+
];
94107
const wf = inject(injectionKeys.core);
95108
const wfbm = inject(injectionKeys.builderManager);
96109
const selected = computed(() => wfbm.isComponentIdSelected(props.componentId));
@@ -101,11 +114,12 @@ const {
101114
moveComponent,
102115
goToComponentParentPage,
103116
isDraggingAllowed,
117+
isDeleteAllowed,
104118
} = useComponentActions(wf, wfbm, tracking);
105119
const { getComponentInfoFromDrag, removeInsertionCandidacy, isParentSuitable } =
106120
useDragDropComponent(wf);
107121
const { isComponentVisible } = useEvaluator(wf);
108-
const emit = defineEmits(["expandBranch"]);
122+
const emits = defineEmits(["expandBranch", "delete"]);
109123
110124
const q = computed(() => props.query?.toLocaleLowerCase() ?? "");
111125
@@ -145,7 +159,7 @@ async function select(ev: MouseEvent | KeyboardEvent) {
145159
function expand() {
146160
if (!treeBranch.value) return;
147161
treeBranch.value.expand();
148-
emit("expandBranch");
162+
emits("expandBranch");
149163
}
150164
151165
function scrollToShow() {
@@ -201,6 +215,12 @@ function handleDrop(ev: DragEvent) {
201215
removeInsertionCandidacy(ev);
202216
}
203217
218+
function handleDropdownSelect(action: string) {
219+
if (action === "delete" && isDeleteAllowed(props.componentId)) {
220+
emits("delete", props.componentId);
221+
}
222+
}
223+
204224
const isOutsideActivePage = computed(() => {
205225
if (!wf.activePageId.value) return false;
206226

0 commit comments

Comments
 (0)