Skip to content

Commit

Permalink
refactor: move shares from vuex store to pinia
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Jan 18, 2024
1 parent a074763 commit 0bca7e6
Show file tree
Hide file tree
Showing 33 changed files with 872 additions and 716 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
useClientService,
useMessages,
usePasswordPolicyService,
useStore
useSharesStore
} from '@ownclouders/web-pkg'
import { Share } from '@ownclouders/web-client/src/helpers'
Expand All @@ -36,11 +36,11 @@ export default defineComponent({
},
emits: ['confirm', 'update:confirmDisabled'],
setup(props, { expose }) {
const store = useStore()
const { showMessage, showErrorMessage } = useMessages()
const clientService = useClientService()
const passwordPolicyService = usePasswordPolicyService()
const { $gettext } = useGettext()
const { updateLink } = useSharesStore()
const password = ref('')
const errorMessage = ref<string>()
Expand All @@ -52,9 +52,9 @@ export default defineComponent({
const onConfirm = async () => {
try {
await store.dispatch('Files/updateLink', {
await updateLink({
id: props.link.id,
client: clientService.owncloudSdk,
clientService: clientService,
params: { ...props.link, password: unref(password) }
})
showMessage({ title: $gettext('Link was updated successfully') })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@
import { debounce } from 'lodash-es'
import PQueue from 'p-queue'
import { storeToRefs } from 'pinia'
import { mapActions } from 'vuex'
import AutocompleteItem from './AutocompleteItem.vue'
import RoleDropdown from '../RoleDropdown.vue'
import RecipientContainer from './RecipientContainer.vue'
Expand All @@ -153,12 +150,13 @@ import {
useUserStore,
useMessages,
useSpacesStore,
useConfigStore
useConfigStore,
useSharesStore,
useStore
} from '@ownclouders/web-pkg'
import { computed, defineComponent, inject, ref, unref, watch, onMounted } from 'vue'
import { Resource } from '@ownclouders/web-client'
import { useShares } from 'web-app-files/src/composables'
import {
displayPositionedDropdown,
formatDateFromDateTime,
Expand Down Expand Up @@ -194,6 +192,7 @@ export default defineComponent({
},
setup() {
const store = useStore()
const userStore = useUserStore()
const clientService = useClientService()
const spacesStore = useSpacesStore()
Expand All @@ -207,6 +206,10 @@ export default defineComponent({
const configStore = useConfigStore()
const { options: configOptions } = storeToRefs(configStore)
const sharesStore = useSharesStore()
const { addShare } = sharesStore
const { outgoingCollaborators } = storeToRefs(sharesStore)
const saving = ref(false)
const savingDelayed = ref(false)
const notifyEnabled = ref(false)
Expand Down Expand Up @@ -262,6 +265,7 @@ export default defineComponent({
})
return {
store,
resource: inject<Resource>('resource'),
hasResharing: capabilityRefs.sharingResharing,
resharingDefault: capabilityRefs.sharingResharingDefault,
Expand All @@ -276,7 +280,8 @@ export default defineComponent({
clientService,
saving,
savingDelayed,
...useShares(),
outgoingCollaborators,
addShare,
showContextMenuOnBtnClick,
contextMenuButtonRef,
notifyEnabled,
Expand Down Expand Up @@ -355,8 +360,6 @@ export default defineComponent({
},
methods: {
...mapActions('Files', ['addShare']),
async fetchRecipients(query) {
try {
const recipients = await this.$client.shares.getRecipients(
Expand Down Expand Up @@ -494,43 +497,56 @@ export default defineComponent({
const saveQueue = new PQueue({
concurrency: this.createSharesConcurrentRequests
})
const bitmask = this.selectedRole.hasCustomPermissions
? SharePermissions.permissionsToBitmask(this.customPermissions)
: SharePermissions.permissionsToBitmask(
this.selectedRole.permissions(
(this.hasResharing && this.resharingDefault) || this.resourceIsSpace
)
)
let path = this.resource.path
// sharing a share root from the share jail -> use resource name as path
if (this.hasShareJail && path === '/') {
path = `/${this.resource.name}`
}
const savePromises = []
this.selectedCollaborators.forEach((collaborator) => {
savePromises.push(
saveQueue.add(async () => {
const bitmask = this.selectedRole.hasCustomPermissions
? SharePermissions.permissionsToBitmask(this.customPermissions)
: SharePermissions.permissionsToBitmask(
this.selectedRole.permissions(
(this.hasResharing && this.resharingDefault) || this.resourceIsSpace
)
)
let path = this.resource.path
// sharing a share root from the share jail -> use resource name as path
if (this.hasShareJail && path === '/') {
path = `/${this.resource.name}`
}
const addMethod = this.resourceIsSpace ? this.addSpaceMember : this.addShare
try {
await addMethod({
client: this.$client,
resource: this.resource,
graphClient: this.clientService.graphAuthenticated,
path,
shareWith: collaborator.value.shareWith,
displayName: collaborator.label,
shareType: collaborator.value.shareType,
shareWithUser: collaborator.value.shareWithUser,
shareWithProvider: collaborator.value.shareWithProvider,
permissions: bitmask,
role: this.selectedRole,
expirationDate: this.expirationDate,
storageId: this.resource.fileId || this.resource.id,
notify: this.notifyEnabled
})
if (this.resourceIsSpace) {
await this.addSpaceMember({
client: this.$client,
graphClient: this.clientService.graphAuthenticated,
path,
shareWith: collaborator.value.shareWith,
displayName: collaborator.label,
shareType: collaborator.value.shareType,
permissions: bitmask,
role: this.selectedRole,
expirationDate: this.expirationDate,
storageId: this.resource.fileId || this.resource.id
})
} else {
await this.addShare({
clientService: this.$clientService,
vuexStore: this.store,
resource: this.resource,
path,
shareWith: collaborator.value.shareWith,
shareType: collaborator.value.shareType,
shareWithUser: collaborator.value.shareWithUser,
shareWithProvider: collaborator.value.shareWithProvider,
permissions: bitmask,
role: this.selectedRole,
expirationDate: this.expirationDate,
storageId: this.resource.fileId || this.resource.id,
notify: this.notifyEnabled
})
}
} catch (e) {
console.error(e)
errors.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@

<script lang="ts">
import { storeToRefs } from 'pinia'
import { mapActions } from 'vuex'
import { DateTime } from 'luxon'
import EditDropdown from './EditDropdown.vue'
Expand All @@ -141,7 +140,8 @@ import {
useModals,
useSpacesStore,
useUserStore,
useCapabilityStore
useCapabilityStore,
useSharesStore
} from '@ownclouders/web-pkg'
import { Resource, extractDomSelector } from '@ownclouders/web-client/src/helpers/resource'
import { computed, defineComponent, inject, PropType, Ref } from 'vue'
Expand Down Expand Up @@ -195,6 +195,8 @@ export default defineComponent({
const { dispatchModal } = useModals()
const { changeSpaceMember } = useSpacesStore()
const { updateShare } = useSharesStore()
const { user } = storeToRefs(userStore)
const sharedParentDir = computed(() => {
Expand Down Expand Up @@ -238,6 +240,7 @@ export default defineComponent({
return {
resource: inject<Ref<Resource>>('resource'),
changeSpaceMember,
updateShare,
user,
hasResharing: capabilityRefs.sharingResharing,
resharingDefault: capabilityRefs.sharingResharingDefault,
Expand Down Expand Up @@ -422,8 +425,6 @@ export default defineComponent({
}
},
methods: {
...mapActions('Files', ['changeShare']),
removeShare() {
this.$emit('onDelete', this.share)
},
Expand Down Expand Up @@ -470,18 +471,28 @@ export default defineComponent({
(this.hasResharing && this.resharingDefault) || this.isAnySpaceShareType
)
)
const changeMethod = this.isAnySpaceShareType ? this.changeSpaceMember : this.changeShare
try {
changeMethod({
client: this.$client,
graphClient: this.clientService.graphAuthenticated,
resource: this.resource,
share: this.share,
permissions: bitmask,
expirationDate: expirationDate || '',
role
})
if (this.isAnySpaceShareType) {
this.changeSpaceMember({
client: this.$client,
graphClient: this.clientService.graphAuthenticated,
share: this.share,
permissions: bitmask,
expirationDate: expirationDate || '',
role
})
} else {
this.updateShare({
clientService: this.$clientService,
resource: this.resource,
share: this.share,
permissions: bitmask,
expirationDate: expirationDate || '',
role
})
}
this.showMessage({ title: this.$gettext('Share successfully changed') })
} catch (e) {
console.error(e)
Expand Down
31 changes: 20 additions & 11 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<script lang="ts">
import { computed, defineComponent, inject, ref, Ref, unref } from 'vue'
import { DateTime } from 'luxon'
import { mapActions, mapMutations } from 'vuex'
import { mapMutations } from 'vuex'
import {
useStore,
useAbility,
Expand Down Expand Up @@ -148,8 +148,7 @@ import {
isProjectSpaceResource,
isShareSpaceResource
} from '@ownclouders/web-client/src/helpers'
import { isLocationSharesActive } from '@ownclouders/web-pkg'
import { useShares } from 'web-app-files/src/composables'
import { isLocationSharesActive, useSharesStore } from '@ownclouders/web-pkg'
import { useGettext } from 'vue3-gettext'
import { storeToRefs } from 'pinia'
Expand All @@ -174,6 +173,10 @@ export default defineComponent({
const { defaultLinkPermissions } = useDefaultLinkPermissions()
const { dispatchModal } = useModals()
const sharesStore = useSharesStore()
const { updateLink, deleteLink, shares } = sharesStore
const { outgoingLinks } = storeToRefs(sharesStore)
const configStore = useConfigStore()
const { options: configOptions } = storeToRefs(configStore)
Expand All @@ -191,7 +194,6 @@ export default defineComponent({
const initialLinkListCollapsed = !configStore.options.sidebar.shares.showAllOnLoad
const linkListCollapsed = ref(initialLinkListCollapsed)
const indirectLinkListCollapsed = ref(initialLinkListCollapsed)
const { outgoingLinks } = useShares()
const directLinks = computed(() =>
unref(outgoingLinks)
.filter((l) => !l.indirect && !l.quicklink)
Expand Down Expand Up @@ -249,9 +251,9 @@ export default defineComponent({
const updatePublicLink = async ({ params }) => {
try {
await store.dispatch('Files/updateLink', {
await updateLink({
id: params.id,
client: clientService.owncloudSdk,
clientService: clientService,
params
})
showMessage({ title: $gettext('Link was updated successfully') })
Expand All @@ -272,6 +274,7 @@ export default defineComponent({
}
return {
store,
ability,
space,
resource,
Expand All @@ -287,6 +290,7 @@ export default defineComponent({
outgoingLinks,
directLinks,
indirectLinks,
deleteLink,
canCreatePublicLinks,
canDeleteReadOnlyPublicLinkPassword,
configStore,
Expand Down Expand Up @@ -379,7 +383,6 @@ export default defineComponent({
}
},
methods: {
...mapActions('Files', ['addLink', 'updateLink', 'removeLink']),
...mapMutations('Files', ['REMOVE_FILES']),
toggleLinkListCollapsed() {
Expand Down Expand Up @@ -504,15 +507,15 @@ export default defineComponent({
),
confirmText: this.$gettext('Delete'),
onConfirm: () =>
this.deleteLink({
client: this.$client,
this.removeLink({
clientService: this.$clientService,
share: link,
resource: this.resource
})
})
},
async deleteLink({ client, share, resource }) {
async removeLink({ clientService, share, resource }) {
let path = resource.path
// sharing a share root from the share jail -> use resource name as path
if (this.hasShareJail && path === '/') {
Expand All @@ -523,7 +526,13 @@ export default defineComponent({
const loadIndicators = this.outgoingLinks.filter((l) => !l.indirect).length === 1
try {
await this.removeLink({ client, share, path, loadIndicators })
await this.deleteLink({
clientService,
share,
path,
loadIndicators,
vuexStore: this.store
})
this.showMessage({
title: this.$gettext('Link was deleted successfully')
})
Expand Down
Loading

0 comments on commit 0bca7e6

Please sign in to comment.