Skip to content

Commit c1f79ee

Browse files
committed
adds remove to backend config, keep it standalone in frontend
1 parent 51e544e commit c1f79ee

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎modules/@apostrophecms/area/ui/apos/components/AposWidgetControls.vue‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
/>
2727

2828
<AposButton
29+
v-if="widgetRemoveControl"
2930
v-bind="widgetRemoveControl"
3031
@click="handleClick({ action: 'remove' })"
3132
/>
@@ -37,6 +38,8 @@
3738
3839
import checkIfConditions from 'apostrophe/lib/universal/check-if-conditions.mjs';
3940
41+
const standaloneWidgetOperation = [ 'remove' ];
42+
4043
export default {
4144
props: {
4245
modelValue: {
@@ -100,7 +103,7 @@ export default {
100103
...operation,
101104
disabled,
102105
tooltip: {
103-
content: !disabled && operation.label,
106+
content: !disabled && (operation.tooltip || operation.label),
104107
placement: 'left'
105108
}
106109
};
@@ -133,18 +136,28 @@ export default {
133136
return controls.concat(this.widgetCustomSecondaryOperations.map(renderOperation));
134137
},
135138
widgetRemoveControl() {
139+
const { widgetOperations = [] } = this.moduleOptions;
140+
const removeWidgetOperation = widgetOperations
141+
.find((operation) => operation.action === 'remove');
142+
if (!removeWidgetOperation) {
143+
return null;
144+
}
145+
136146
return {
137147
...this.widgetDefaultControl,
138-
label: 'apostrophe:remove',
139-
icon: 'trash-can-outline-icon',
140-
disabled: this.disabled,
148+
...removeWidgetOperation,
141149
tooltip: {
142-
content: 'apostrophe:delete',
150+
content: removeWidgetOperation.tooltip,
143151
placement: 'left'
144-
},
145-
action: 'remove'
152+
}
146153
};
147154
},
155+
widgetSkipControlsMap() {
156+
return new Map(
157+
(this.moduleOptions.skipOperations || [])
158+
.map(operation => [ operation, true ])
159+
);
160+
},
148161
widgetPrimaryOperations() {
149162
return this.getOperations({ secondaryLevel: false });
150163
},
@@ -168,6 +181,9 @@ export default {
168181
getOperations({ secondaryLevel, native }) {
169182
const { widgetOperations = [] } = this.moduleOptions;
170183
return widgetOperations.filter(operation => {
184+
if (standaloneWidgetOperation.includes(operation.name)) {
185+
return false;
186+
}
171187
if (
172188
typeof native === 'boolean' &&
173189
((native && !operation.native) || (!native && operation.native))

‎modules/@apostrophecms/widget-type/index.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ module.exports = {
247247
native: true
248248
}
249249
},
250+
remove: {
251+
label: 'apostrophe:remove',
252+
icon: 'trash-can-outline-icon',
253+
disabled: this.disabled,
254+
tooltip: 'apostrophe:delete',
255+
action: 'remove',
256+
native: true
257+
},
250258
cut: {
251259
label: 'apostrophe:cut',
252260
icon: 'content-cut-icon',

0 commit comments

Comments
 (0)