Skip to content

Commit

Permalink
feat: Allow registration of advanced external share actions
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal authored and skjnldsv committed Mar 6, 2024
1 parent 8fded1d commit 1260c85
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ export default {
* @return {Array}
*/
externalLinkActions() {
const filterValidAction = (action) => (action.shareType.includes(ShareTypes.SHARE_TYPE_LINK) || action.shareType.includes(ShareTypes.SHARE_TYPE_EMAIL)) && !action.advanced
// filter only the registered actions for said link
return this.ExternalShareActions.actions
.filter(action => action.shareType.includes(ShareTypes.SHARE_TYPE_LINK)
|| action.shareType.includes(ShareTypes.SHARE_TYPE_EMAIL))
.filter(filterValidAction)
},
isPasswordPolicyEnabled() {
Expand Down
8 changes: 7 additions & 1 deletion apps/files_sharing/src/services/ExternalShareActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ export default class ExternalShareActions {
return this._state
}

/**
* @typedef ExternalShareActionData
* @property {import('vue').Component} is Vue component to render, for advanced actions the `async onSave` method of the component will be called when saved
*/

/**
* Register a new option/entry for the a given share type
*
* @param {object} action new action component to register
* @param {string} action.id unique action id
* @param {Function} action.data data to bind the component to
* @param {(data: any) => ExternalShareActionData & Record<string, unknown>} action.data data to bind the component to
* @param {Array} action.shareType list of \@nextcloud/sharing.Types.SHARE_XXX to be mounted on
* @param {boolean} action.advanced `true` if the action entry should be rendered within advanced settings
* @param {object} action.handlers list of listeners
* @return {boolean}
*/
Expand Down
34 changes: 34 additions & 0 deletions apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@
</label>
<textarea id="share-note-textarea" :value="share.note" @input="share.note = $event.target.value" />
</template>
<ExternalShareAction v-for="action in externalLinkActions"
:id="action.id"
ref="externalLinkActions"
:key="action.id"
:action="action"
:file-info="fileInfo"
:share="share" />
<NcCheckboxRadioSwitch :checked.sync="setCustomPermissions">
{{ t('files_sharing', 'Custom permissions') }}
</NcCheckboxRadioSwitch>
Expand Down Expand Up @@ -234,6 +241,7 @@
<script>
import { getLanguage } from '@nextcloud/l10n'
import { Type as ShareType } from '@nextcloud/sharing'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcInputField from '@nextcloud/vue/dist/Components/NcInputField.js'
Expand All @@ -256,6 +264,8 @@ import MenuDownIcon from 'vue-material-design-icons/MenuDown.vue'
import MenuUpIcon from 'vue-material-design-icons/MenuUp.vue'
import DotsHorizontalIcon from 'vue-material-design-icons/DotsHorizontal.vue'
import ExternalShareAction from '../components/ExternalShareAction.vue'
import GeneratePassword from '../utils/GeneratePassword.js'
import Share from '../models/Share.js'
import ShareRequests from '../mixins/ShareRequests.js'
Expand All @@ -281,6 +291,7 @@ export default {
CloseIcon,
CircleIcon,
EditIcon,
ExternalShareAction,
LinkIcon,
GroupIcon,
ShareIcon,
Expand Down Expand Up @@ -318,6 +329,8 @@ export default {
isFirstComponentLoad: true,
test: false,
creating: false,
ExternalShareActions: OCA.Sharing.ExternalShareActions.state,
}
},
Expand Down Expand Up @@ -670,6 +683,18 @@ export default {
}
return undefined
},
/**
* Additional actions for the menu
*
* @return {Array}
*/
externalLinkActions() {
const filterValidAction = (action) => (action.shareType.includes(ShareType.SHARE_TYPE_LINK) || action.shareType.includes(ShareType.SHARE_TYPE_EMAIL)) && action.advanced
// filter only the advanced registered actions for said link
return this.ExternalShareActions.actions
.filter(filterValidAction)
},
},
watch: {
setCustomPermissions(isChecked) {
Expand Down Expand Up @@ -860,6 +885,15 @@ export default {
this.queueUpdate(...permissionsAndAttributes)
}
if (this.$refs.externalLinkActions?.length > 0) {
await Promise.allSettled(this.$refs.externalLinkActions.map((action) => {
if (typeof action.$children.at(0)?.onSave !== 'function') {
return Promise.resolve()
}
return action.$children.at(0)?.onSave?.()
}))
}
this.$emit('close-sharing-details')
},
/**
Expand Down

0 comments on commit 1260c85

Please sign in to comment.