-
Notifications
You must be signed in to change notification settings - Fork 601
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
Changes from all commits
f4b3058
3844e0c
2c807f3
98057e7
d64159e
9c461d5
d4d0592
43ab477
d9b6c97
4439236
0113abe
66c74ab
5e8ac05
d9b0ec0
1986cb0
4075b2a
f922415
86df98d
f805286
2e972b9
f7dbb73
64232c1
97616e3
4f845df
f6d2fce
6cd511f
0e36809
2df810c
7ba8322
c5a77da
6c20ec3
28e54e8
856be19
c3c40eb
91d2100
6dbd218
4d9e8e9
dfdac3f
b6089b5
f477534
9bce775
125e1de
ba29ff0
408a265
e00da1d
1bf4d4f
601a607
4d578fc
5873267
20e8780
8486ced
472902d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but in the end, the component that listens to |
||
} | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ | |
> | ||
<!-- | ||
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. It might also be worth breaking up the core menus into their own vue | ||
components to further illustrate this concept. | ||
Modules should be able to provide their own menus here to complete | ||
tasks specific to them. | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
--> | ||
<div | ||
v-if="!editMode" | ||
|
@@ -200,9 +201,6 @@ export default { | |
this.hasBeenPublishedButNotUpdated = false; | ||
} | ||
this.$emit('publish'); | ||
}, | ||
emitEvent(name) { | ||
apos.bus.$emit('admin-menu-click', name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused |
||
} | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,9 +23,10 @@ module.exports = { | |||||||||||||||||||||||||
'rank', | ||||||||||||||||||||||||||
'level' | ||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||
self.widgetManagers = {}; | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate |
||||||||||||||||||||||||||
self.richTextWidgetTypes = []; | ||||||||||||||||||||||||||
self.widgetManagers = {}; | ||||||||||||||||||||||||||
self.widgetOperations = []; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
self.enableBrowserData(); | ||||||||||||||||||||||||||
self.addDeduplicateWidgetIdsMigration(); | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
|
@@ -658,6 +659,21 @@ module.exports = { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
addWidgetOperation(operation) { | ||||||||||||||||||||||||||
if (!operation.name || !operation.label || !operation.modal) { | ||||||||||||||||||||||||||
throw self.apos.error('invalid', 'addWidgetOperation requires name, label and modal properties.'); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (operation.secondaryLevel !== true && !operation.icon) { | ||||||||||||||||||||||||||
throw self.apos.error('invalid', 'addWidgetOperation requires the icon property at primary level.'); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
self.widgetOperations = self.widgetOperations.filter( | ||||||||||||||||||||||||||
({ name }) => name !== operation.name | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this to avoid duplicates? I think that throwing an error would be easier to debug and fix for users? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this replaces an already-registered operation with the same name. apostrophe/modules/@apostrophecms/doc/index.js Line 1538 in 62cdeaa
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
self.widgetOperations.push(operation); | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
getBrowserData(req) { | ||||||||||||||||||||||||||
const widgets = {}; | ||||||||||||||||||||||||||
const widgetEditors = {}; | ||||||||||||||||||||||||||
|
@@ -682,6 +698,13 @@ module.exports = { | |||||||||||||||||||||||||
contextualWidgetDefaultData[name] = manager.options.defaultData || {}; | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const widgetOperations = self.widgetOperations.filter(({ permission }) => { | ||||||||||||||||||||||||||
if (permission?.action && permission?.type) { | ||||||||||||||||||||||||||
return self.apos.permission.can(req, permission.action, permission.type, permission.mode || 'draft'); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
Comment on lines
+701
to
+706
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like my version better 🍃 |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ actual change |
||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||
components: { | ||||||||||||||||||||||||||
editor: 'AposAreaEditor', | ||||||||||||||||||||||||||
|
@@ -694,7 +717,8 @@ module.exports = { | |||||||||||||||||||||||||
widgetPreview, | ||||||||||||||||||||||||||
contextualWidgetDefaultData, | ||||||||||||||||||||||||||
widgetManagers, | ||||||||||||||||||||||||||
action: self.action | ||||||||||||||||||||||||||
action: self.action, | ||||||||||||||||||||||||||
widgetOperations | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
async addDeduplicateWidgetIdsMigration() { | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
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