Skip to content

make widget operations dynamic to add custom ones #4897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f4b3058
dynamic widget operations
Mar 31, 2025
3844e0c
use computed to render widgets controls
Apr 1, 2025
2c807f3
wip
Apr 1, 2025
98057e7
fix max-len eslint warnings
Apr 1, 2025
d64159e
display primary custom operation
Apr 1, 2025
9c461d5
display secondary controls
Apr 2, 2025
d4d0592
pass widget model value to modal, fix event
Apr 2, 2025
43ab477
niughtmare
Apr 2, 2025
d9b6c97
wip
Apr 2, 2025
4439236
adapt
Apr 3, 2025
0113abe
rename
Apr 3, 2025
66c74ab
revert mdi
Apr 3, 2025
5e8ac05
remove logs
Apr 3, 2025
d9b0ec0
yeah
Apr 3, 2025
1986cb0
separator
Apr 3, 2025
4075b2a
clean secondary controls
Apr 3, 2025
f922415
disable secondary items
Apr 3, 2025
86df98d
use ternary
Apr 3, 2025
f805286
display separator based on class
Apr 3, 2025
2e972b9
remove log
Apr 3, 2025
f7dbb73
smartly display separator
Apr 3, 2025
64232c1
wip
Apr 8, 2025
97616e3
check permission
Apr 8, 2025
4f845df
try to pass area schema
Apr 8, 2025
f6d2fce
remove log
Apr 8, 2025
6cd511f
add tests
Apr 9, 2025
0e36809
tooltip
Apr 9, 2025
2df810c
changelog
Apr 9, 2025
7ba8322
remove test
Apr 9, 2025
c5a77da
remove fixme
Apr 9, 2025
6c20ec3
remove test icon
Apr 9, 2025
28e54e8
remove unused clone i18n key
Apr 9, 2025
856be19
Widget operations/styles (#4913)
stuartromanek Apr 14, 2025
c3c40eb
fix context menu for inline arrays
Apr 14, 2025
91d2100
use widget operation name
Apr 14, 2025
6dbd218
Merge branch 'main' of github.com:apostrophecms/apostrophe into pro-7…
Apr 14, 2025
4d9e8e9
fix keyboard shortcut
Apr 14, 2025
dfdac3f
add data-test attr
Apr 16, 2025
b6089b5
icon required at primary level
Apr 16, 2025
f477534
set data-apos-test-context-menu-item to item.modal
Apr 16, 2025
9bce775
add widget operation via widget module
Apr 17, 2025
125e1de
filter thigs
Apr 17, 2025
ba29ff0
changelog
Apr 17, 2025
408a265
Merge branch 'main' of github.com:apostrophecms/apostrophe into pro-7…
Apr 17, 2025
e00da1d
changelog
Apr 17, 2025
1bf4d4f
handle modal result
Apr 17, 2025
601a607
Merge branch 'main' of github.com:apostrophecms/apostrophe into pro-7…
Apr 17, 2025
4d578fc
consistency
Apr 21, 2025
5873267
improve widget operations filtering
Apr 21, 2025
20e8780
result?.widget
Apr 21, 2025
8486ced
remove useless foreign prop
Apr 21, 2025
472902d
remove useless foreign prop everywhere
Apr 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="apos-admin-bar__btn"
:modifiers="['no-motion']"
role="menuitem"
@click="emitEvent('@apostrophecms/page:manager')"
@click="emitEvent({ action: '@apostrophecms/page:manager' })"
/>
</li>
<li
Expand Down Expand Up @@ -42,7 +42,7 @@
:modifiers="['no-motion']"
class="apos-admin-bar__btn"
role="menuitem"
@click="emitEvent(item.action)"
@click="emitEvent(item)"
/>
</li>
<li
Expand Down Expand Up @@ -85,7 +85,7 @@
:label="item.label"
:action="item.action"
:state="trayItemState[item.name] ? [ 'active' ] : []"
@click="emitEvent(item.action)"
@click="emitEvent(item)"
/>
</template>
</li>
Expand Down Expand Up @@ -122,10 +122,9 @@ export default {
}
},
async mounted() {
apos.bus.$on('admin-menu-click', this.onAdminMenuClick);

const itemsSet = klona(this.items);
this.menuItems = itemsSet.filter(item => !(item.options && item.options.contextUtility))
this.menuItems = itemsSet
.filter(item => !(item.options && item.options.contextUtility))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

.map(item => {
if (item.items) {
item.items.forEach(subitem => {
Expand All @@ -148,12 +147,26 @@ export default {
});
},
methods: {
emitEvent(name) {
apos.bus.$emit('admin-menu-click', name);
emitEvent(item) {
apos.bus.$emit('admin-menu-click', item.action);

// Maintain a knowledge of which tray item toggles are active
const trayItem = this.trayItems.find(trayItem => trayItem.name === item.action);

if (trayItem && trayItem.options.toggle) {
this.trayItemState = {
...this.trayItemState,
[item.action]: !this.trayItemState[item.action]
};
}
Comment on lines +153 to +161
Copy link
Contributor Author

@ETLaurent ETLaurent Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block moved from the late onAdminMenuClick (unnecessary? right?) event listener

},
trayItemTooltip(item) {
if (item.options.toggle) {
if (this.trayItemState[item.name] && item.options.tooltip && item.options.tooltip.deactivate) {
if (
this.trayItemState[item.name] &&
item.options.tooltip &&
item.options.tooltip.deactivate
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

return {
content: item.options.tooltip.deactivate,
placement: 'bottom'
Expand All @@ -169,17 +182,6 @@ export default {
} else {
return item.options.tooltip;
}
},
// Maintain a knowledge of which tray item toggles are active
onAdminMenuClick(e) {
const name = e.itemName || e;
const trayItem = this.trayItems.find(item => item.name === name);
if (trayItem && trayItem.options.toggle) {
this.trayItemState = {
...this.trayItemState,
[name]: !this.trayItemState[name]
};
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default {
}
},
methods: {
emitEvent(name) {
apos.bus.$emit('admin-menu-click', name);
emitEvent(item) {
apos.bus.$emit('admin-menu-click', item.action);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So item-clicked emits the entire item, but admin-menu-click emits only the action name?
Shouldn't we make it more consistent and emit the item all the time, maybe it's a lot more work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but in the end, the component that listens to admin-menu-click event will need to adapt, and so on.
Since the scope of this PR has already been way over, I prefer to limit the changes to the minimum.

}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ export default {
}
return 'cellphone-icon';
},
selectBreakpoint(selected) {
selectBreakpoint(item) {
const {
name, label, width, height
} = this.breakpoints.find(({ name }) => name === selected);
} = this.breakpoints.find(({ name }) => name === item.action);
this.toggleBreakpointPreviewMode({
mode: name,
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
>
<!--
TODO: Each div at this level serves as a discrete context menu state
Modules should be able to provide their own menus here to complete tasks specific to them.
Modules should be able to provide their own menus here to complete
tasks specific to them.
Comment on lines +9 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

It might also be worth breaking up the core menus into their own vue components to
further illustrate this concept.
-->
Expand Down Expand Up @@ -107,7 +108,11 @@ export default {
if (this.canPublish) {
if (this.context.lastPublishedAt) {
// Document went from unpublished to published and has nothing staged
if (this.hasBeenPublishedThisPageload && !this.readyToPublish && this.hasBeenPublishedButNotUpdated) {
if (
this.hasBeenPublishedThisPageload &&
!this.readyToPublish &&
this.hasBeenPublishedButNotUpdated
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

return 'apostrophe:published';
// Document *has* had changes published this page load, but nothing staged now
} else if (this.hasBeenPublishedThisPageload && !this.readyToPublish) {
Expand Down Expand Up @@ -135,7 +140,11 @@ export default {
}
},
publishTooltip() {
if (this.canPublish && this.context.lastPublishedAt && !this.hasBeenPublishedThisPageload) {
if (
this.canPublish &&
this.context.lastPublishedAt &&
!this.hasBeenPublishedThisPageload
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

return {
content: 'apostrophe:updateTooltip',
placement: 'bottom'
Expand All @@ -145,10 +154,13 @@ export default {
return false;
},
isAutopublished() {
return this.context._aposAutopublish ?? (window.apos.modules[this.context.type].autopublish || false);
return this.context._aposAutopublish ??
(window.apos.modules[this.context.type].autopublish || false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

},
hasBeenPublishedThisPageload() {
return (this.context.lastPublishedAt > this.mountedAt) || ((this.context.submitted && this.context.submitted.at) > this.mountedAt);
return (
this.context.lastPublishedAt > this.mountedAt) ||
((this.context.submitted && this.context.submitted.at) > this.mountedAt);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

},
canSwitchToEditMode() {
return !this.editMode;
Expand Down Expand Up @@ -188,9 +200,6 @@ export default {
this.hasBeenPublishedButNotUpdated = false;
}
this.$emit('publish');
},
emitEvent(name) {
apos.bus.$emit('admin-menu-click', name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export default {
return window.apos.adminBar;
},
isAutopublished() {
return this.context._aposAutopublish ?? (window.apos.modules[this.context.type].autopublish || false);
return this.context._aposAutopublish ??
(window.apos.modules[this.context.type].autopublish || false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

}
},
mounted() {
Expand All @@ -137,11 +138,11 @@ export default {
togglePublishDraftMode() {
if (this.canTogglePublishDraftMode) {
const mode = this.draftMode === 'draft' ? 'published' : 'draft';
this.switchDraftMode(mode);
this.$emit('switch-draft-mode', mode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.$emit('switch-draft-mode', mode);
const action = this.draftMode === 'draft' ? 'published' : 'draft';
this.switchDraftMode({ action });

}
},
switchDraftMode(mode) {
this.$emit('switch-draft-mode', mode);
switchDraftMode(item) {
this.$emit('switch-draft-mode', item.action);
}
}
};
Expand Down
Loading
Loading