Skip to content

Commit

Permalink
Merge pull request #10316 from owncloud/spaces-to-pinia
Browse files Browse the repository at this point in the history
refactor: move spaces to pinia store
  • Loading branch information
JammingBen authored Jan 12, 2024
2 parents eb8854b + 4e17e14 commit d223ede
Show file tree
Hide file tree
Showing 105 changed files with 1,174 additions and 989 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/change-spaces-store
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Change: Spaces store to pinia

BREAKING CHANGE for developers: Spaces are no longer stored in a vuex store but in pinia instead. You can access all the store functionality via the new `useSpacesStore` composable.

For more details please see the linked PR down below.

https://github.com/owncloud/web/pull/10316
https://github.com/owncloud/web/issues/10210
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export default defineComponent({
const filterParams = computed(() => ({ resources: props.items }))
const { actions: deleteActions } = useSpaceActionsDelete({ store })
const { actions: disableActions } = useSpaceActionsDisable({ store })
const { actions: disableActions } = useSpaceActionsDisable()
const { actions: editQuotaActions } = useSpaceActionsEditQuota()
const { actions: editDescriptionActions } = useSpaceActionsEditDescription({ store })
const { actions: renameActions } = useSpaceActionsRename({ store })
const { actions: restoreActions } = useSpaceActionsRestore({ store })
const { actions: editDescriptionActions } = useSpaceActionsEditDescription()
const { actions: renameActions } = useSpaceActionsRename()
const { actions: restoreActions } = useSpaceActionsRestore()
const { actions: showDetailsActions } = useActionsShowDetails()
const menuItemsPrimaryActions = computed(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export default defineComponent({
}))
const { actions: deleteActions } = useSpaceActionsDelete({ store })
const { actions: disableActions } = useSpaceActionsDisable({ store })
const { actions: editDescriptionActions } = useSpaceActionsEditDescription({ store })
const { actions: disableActions } = useSpaceActionsDisable()
const { actions: editDescriptionActions } = useSpaceActionsEditDescription()
const { actions: editQuotaActions } = useSpaceActionsEditQuota()
const { actions: renameActions } = useSpaceActionsRename({ store })
const { actions: restoreActions } = useSpaceActionsRestore({ store })
const { actions: renameActions } = useSpaceActionsRename()
const { actions: restoreActions } = useSpaceActionsRestore()
const actions = computed(() => {
return [
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-admin-settings/src/views/Spaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ export default defineComponent({
}
const { actions: deleteActions } = useSpaceActionsDelete({ store })
const { actions: disableActions } = useSpaceActionsDisable({ store })
const { actions: disableActions } = useSpaceActionsDisable()
const { actions: editQuotaActions } = useSpaceActionsEditQuota()
const { actions: restoreActions } = useSpaceActionsRestore({ store })
const { actions: restoreActions } = useSpaceActionsRestore()
const batchActions = computed((): SpaceAction[] => {
return [
Expand Down
6 changes: 4 additions & 2 deletions packages/web-app-admin-settings/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ import {
SideBarPanel,
SideBarPanelContext,
useUserStore,
useMessages
useMessages,
useSpacesStore
} from '@ownclouders/web-pkg'
import {
computed,
Expand Down Expand Up @@ -203,6 +204,7 @@ export default defineComponent({
const clientService = useClientService()
const configurationManager = useConfigurationManager()
const userStore = useUserStore()
const spacesStore = useSpacesStore()
const currentPageQuery = useRouteQuery('page', '1')
const currentPage = computed(() => {
Expand Down Expand Up @@ -542,7 +544,7 @@ export default defineComponent({
if (editUser.id === userStore.user.id) {
// Load current user quota
store.commit('runtime/spaces/UPDATE_SPACE_FIELD', {
spacesStore.updateSpaceField({
id: editUser.drive.id,
field: 'spaceQuota',
value: updateDriveResponse.data.quota
Expand Down
10 changes: 5 additions & 5 deletions packages/web-app-admin-settings/tests/unit/views/Users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
eventBus,
useAppDefaults,
useConfigurationManager,
useMessages
useMessages,
useSpacesStore
} from '@ownclouders/web-pkg'
import { mock, mockDeep } from 'jest-mock-extended'
import { mockAxiosResolve, mockAxiosReject } from 'web-test-helpers/src/mocks'
Expand Down Expand Up @@ -232,7 +233,7 @@ describe('Users view', () => {
})
)

const { wrapper, storeOptions } = getMountedWrapper({ clientService })
const { wrapper } = getMountedWrapper({ clientService })

const busStub = jest.spyOn(eventBus, 'publish')

Expand All @@ -249,9 +250,8 @@ describe('Users view', () => {
expect(updatedUser.memberOf[0].id).toEqual('1')

expect(busStub).toHaveBeenCalled()
expect(
storeOptions.modules.runtime.modules.spaces.mutations.UPDATE_SPACE_FIELD
).toHaveBeenCalled()
const spacesStore = useSpacesStore()
expect(spacesStore.updateSpaceField).toHaveBeenCalled()
})

it('should show message on error', async () => {
Expand Down
13 changes: 7 additions & 6 deletions packages/web-app-files/src/HandleUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RouteLocationNormalizedLoaded } from 'vue-router'
import { Resource, SpaceResource } from '@ownclouders/web-client/src'
import { urlJoin } from '@ownclouders/web-client/src/utils'
import { ResourceConflict } from './helpers/resource'
import { MessageStore, UserStore, locationPublicLink } from '@ownclouders/web-pkg'
import { MessageStore, SpacesStore, UserStore, locationPublicLink } from '@ownclouders/web-pkg'
import { locationSpacesGeneric, UppyService, UppyResource } from '@ownclouders/web-pkg'
import { isPersonalSpaceResource, isShareSpaceResource } from '@ownclouders/web-client/src/helpers'
import { ClientService, queryItemAsString } from '@ownclouders/web-pkg'
Expand All @@ -23,6 +23,7 @@ export interface HandleUploadOptions {
store: Store<any>
userStore: UserStore
messageStore: MessageStore
spacesStore: SpacesStore
uppyService: UppyService
id?: string
space?: SpaceResource
Expand Down Expand Up @@ -53,6 +54,7 @@ export class HandleUpload extends BasePlugin {
store: Store<any>
userStore: UserStore
messageStore: MessageStore
spacesStore: SpacesStore
uppyService: UppyService
quotaCheckEnabled: boolean
directoryTreeCreateEnabled: boolean
Expand All @@ -72,6 +74,7 @@ export class HandleUpload extends BasePlugin {
this.store = opts.store
this.userStore = opts.userStore
this.messageStore = opts.messageStore
this.spacesStore = opts.spacesStore
this.uppyService = opts.uppyService

this.quotaCheckEnabled = opts.quotaCheckEnabled ?? true
Expand All @@ -89,10 +92,6 @@ export class HandleUpload extends BasePlugin {
return this.store.getters['Files/files']
}

get spaces(): SpaceResource[] {
return this.store.getters['runtime/spaces/spaces']
}

removeFilesFromUpload(filesToUpload: UppyResource[]) {
for (const file of filesToUpload) {
this.uppy.removeFile(file.id)
Expand Down Expand Up @@ -206,7 +205,9 @@ export class HandleUpload extends BasePlugin {
}

if (uppyResource.meta.routeName === locationSpacesGeneric.name) {
targetUploadSpace = this.spaces.find((space) => space.id === uppyResource.meta.spaceId)
targetUploadSpace = this.spacesStore.spaces.find(
({ id }) => id === uppyResource.meta.spaceId
)
}

if (
Expand Down
14 changes: 9 additions & 5 deletions packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ import {
useFileActions,
useFileActionsCreateNewShortcut,
useMessages,
useSpacesStore,
useUserStore
} from '@ownclouders/web-pkg'
import { useActiveLocation } from '@ownclouders/web-pkg'
Expand Down Expand Up @@ -266,6 +267,7 @@ export default defineComponent({
const clientService = useClientService()
const store = useStore()
const userStore = useUserStore()
const spacesStore = useSpacesStore()
const messageStore = useMessages()
const route = useRoute()
const language = useGettext()
Expand All @@ -283,6 +285,7 @@ export default defineComponent({
space: props.space,
store,
userStore,
spacesStore,
messageStore,
uppyService
})
Expand Down Expand Up @@ -376,12 +379,14 @@ export default defineComponent({
const { spaceId, currentFolder, currentFolderId, driveType } = file.meta
if (unref(hasSpaces) && !isPublicSpaceResource(props.space)) {
const spaces = store.getters['runtime/spaces/spaces']
const isOwnSpace = spaces.find((space) => space.id === spaceId)?.isOwner(userStore.user)
const isOwnSpace = spacesStore.spaces
.find(({ id }) => id === spaceId)
?.isOwner(userStore.user)
if (driveType === 'project' || isOwnSpace) {
const client = clientService.graphAuthenticated
const driveResponse = await client.drives.getDrive(spaceId.toString())
store.commit('runtime/spaces/UPDATE_SPACE_FIELD', {
const driveResponse = await client.drives.getDrive(spaceId)
spacesStore.updateSpaceField({
id: driveResponse.data.id,
field: 'spaceQuota',
value: driveResponse.data.quota
Expand Down Expand Up @@ -456,7 +461,6 @@ export default defineComponent({
...mapGetters(['capabilities', 'configuration', 'newFileHandlers']),
...mapGetters('Files', ['files', 'selectedFiles', 'clipboardResources']),
...mapGetters('runtime/ancestorMetaData', ['ancestorMetaData']),
...mapGetters('runtime/spaces', ['spaces']),
showPasteHereButton() {
return this.clipboardResources && this.clipboardResources.length !== 0
Expand Down
6 changes: 4 additions & 2 deletions packages/web-app-files/src/components/AppBar/CreateSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
useCreateSpace,
useSpaceHelpers,
useStore,
useMessages
useMessages,
useSpacesStore
} from '@ownclouders/web-pkg'
export default defineComponent({
Expand All @@ -32,12 +33,13 @@ export default defineComponent({
const { createSpace } = useCreateSpace()
const { checkSpaceNameModalInput } = useSpaceHelpers()
const { dispatchModal } = useModals()
const spacesStore = useSpacesStore()
const addNewSpace = async (name: string) => {
try {
const createdSpace = await createSpace(name)
store.commit('Files/UPSERT_RESOURCE', createdSpace)
store.commit('runtime/spaces/UPSERT_SPACE', createdSpace)
spacesStore.upsertSpace(createdSpace)
showMessage({ title: $gettext('Space was created successfully') })
} catch (error) {
console.error(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ import {
useAbility,
useEmbedMode,
useFileActionsCreateLink,
useSpacesStore,
useStore
} from '@ownclouders/web-pkg'
import { Resource, SpaceResource } from '@ownclouders/web-client'
import { Resource } from '@ownclouders/web-client'
import { useGettext } from 'vue3-gettext'
import { storeToRefs } from 'pinia'
export default {
setup() {
const store = useStore()
const ability = useAbility()
const language = useGettext()
const { isLocationPicker, postMessage } = useEmbedMode()
const spacesStore = useSpacesStore()
const { currentSpace: space } = storeToRefs(spacesStore)
const space = computed<SpaceResource>(() => store.getters['runtime/spaces/currentSpace'])
const selectedFiles = computed<Resource[]>(() => {
if (isLocationPicker.value) {
return [store.getters['Files/currentFolder']]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ export default defineComponent({
})
const { actions: deleteActions } = useSpaceActionsDelete({ store })
const { actions: disableActions } = useSpaceActionsDisable({ store })
const { actions: disableActions } = useSpaceActionsDisable()
const { actions: duplicateActions } = useSpaceActionsDuplicate({ store })
const { actions: editDescriptionActions } = useSpaceActionsEditDescription({ store })
const { actions: editDescriptionActions } = useSpaceActionsEditDescription()
const { actions: editQuotaActions } = useSpaceActionsEditQuota()
const { actions: editReadmeContentActions } = useSpaceActionsEditReadmeContent()
const { actions: renameActions } = useSpaceActionsRename({ store })
const { actions: restoreActions } = useSpaceActionsRestore({ store })
const { actions: renameActions } = useSpaceActionsRename()
const { actions: restoreActions } = useSpaceActionsRestore()
const { actions: uploadImageActions, uploadImageSpace } = useSpaceActionsUploadImage({
store,
spaceImageInput
})
const { actions: downloadArchiveActions } = useFileActionsDownloadArchive({ store })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ import {
useConfigurationManager,
useStore,
useUserStore,
useMessages
useMessages,
useSpacesStore
} from '@ownclouders/web-pkg'
import { computed, defineComponent, inject, ref, unref, watch, onMounted } from 'vue'
Expand Down Expand Up @@ -201,6 +202,9 @@ export default defineComponent({
const store = useStore()
const userStore = useUserStore()
const clientService = useClientService()
const spacesStore = useSpacesStore()
const { addSpaceMember } = spacesStore
const { spaceMembers } = storeToRefs(spacesStore)
const { user } = storeToRefs(userStore)
Expand Down Expand Up @@ -267,6 +271,8 @@ export default defineComponent({
hasRoleCustomPermissions: useCapabilityFilesSharingAllowCustomPermissions(store),
minSearchLength: useCapabilityFilesSharingSearchMinLength(store),
isRunningOnEos: computed(() => store.getters.configuration?.options?.runningOnEos),
spaceMembers,
addSpaceMember,
user,
clientService,
saving,
Expand Down Expand Up @@ -298,7 +304,6 @@ export default defineComponent({
}
},
computed: {
...mapGetters('runtime/spaces', ['spaceMembers']),
...mapGetters(['configuration']),
$_announcementWhenCollaboratorAdded() {
Expand Down Expand Up @@ -354,7 +359,6 @@ export default defineComponent({
methods: {
...mapActions('Files', ['addShare']),
...mapActions('runtime/spaces', ['addSpaceMember']),
async fetchRecipients(query) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import {
useCapabilityFilesSharingResharingDefault,
useMessages,
useModals,
useSpacesStore,
useUserStore
} from '@ownclouders/web-pkg'
import { extractDomSelector } from '@ownclouders/web-client/src/helpers/resource'
Expand Down Expand Up @@ -191,6 +192,7 @@ export default defineComponent({
const clientService = useClientService()
const { $gettext } = useGettext()
const { dispatchModal } = useModals()
const { changeSpaceMember } = useSpacesStore()
const { user } = storeToRefs(userStore)
Expand Down Expand Up @@ -235,6 +237,7 @@ export default defineComponent({
return {
hasResharing: useCapabilityFilesSharingResharing(),
resharingDefault: useCapabilityFilesSharingResharingDefault(),
changeSpaceMember,
user,
clientService,
sharedParentDir,
Expand Down Expand Up @@ -418,7 +421,6 @@ export default defineComponent({
},
methods: {
...mapActions('Files', ['changeShare']),
...mapActions('runtime/spaces', ['changeSpaceMember']),
removeShare() {
this.$emit('onDelete', this.share)
Expand Down
Loading

0 comments on commit d223ede

Please sign in to comment.