Skip to content

Commit

Permalink
Make fileActions mixin standalone again.
Browse files Browse the repository at this point in the history
In #6445 we introduced a dependency on isFilesAppActive for the fileActions mixin. We added it to
ContextActions and BatchActions, but there are way more places where the mixin is used. That's why
we add a computed to the mixin itself now. Because mixins belong to the options api we unfortunately
cannot use composables directly and extract helper functions for that reason.
  • Loading branch information
dschmidt committed Feb 18, 2022
1 parent 0294044 commit a07f09f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import DownloadFile from '../../../mixins/actions/downloadFile'
import EmptyTrashBin from '../../../mixins/actions/emptyTrashBin'
import Move from '../../../mixins/actions/move'
import Restore from '../../../mixins/actions/restore'
import { useIsFilesAppActive } from '../../../composables/useIsFilesAppActive'
import { useIsFilesAppActive } from '../../../composables'
export default {
setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ import Restore from '../../mixins/actions/restore'
import ShowActions from '../../mixins/actions/showActions'
import ShowDetails from '../../mixins/actions/showDetails'
import ShowShares from '../../mixins/actions/showShares'
import { useIsFilesAppActive } from '../../composables/useIsFilesAppActive'
export default {
setup() {
return {
isFilesAppActive: useIsFilesAppActive()
}
},
name: 'ContextActions',
components: { ActionMenuItem },
mixins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ import { mapGetters } from 'vuex'
import ActionMenuItem from '../../ActionMenuItem.vue'
import FileActions from '../../../mixins/fileActions'
import { useIsFilesAppActive } from '../../../composables/useIsFilesAppActive'
export default {
setup() {
return {
isFilesAppActive: useIsFilesAppActive()
}
},
name: 'FileActions',
title: ($gettext) => {
return $gettext('Actions')
Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/src/composables/router/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './useActiveLocation'
export * from './useIsFilesAppActive'
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { computed, ComputedRef, unref } from '@vue/composition-api'
import { useActiveApp } from 'web-pkg/src/composables'
import FilesApp from '../index'

export const isFilesAppActive = (activeApp : string) : boolean => {
// FIXME: we should use this constant but it somehow breaks the unit tests
// return activeApp === FilesApp.appInfo.id
return activeApp === 'files'
}

/*
* This composable can be used to check whether the current route
Expand All @@ -12,6 +17,6 @@ import FilesApp from '../index'
export const useIsFilesAppActive = (): ComputedRef<boolean> => {
const activeApp = useActiveApp()
return computed(() => {
return unref(activeApp) === FilesApp.appInfo.id
return isFilesAppActive(unref(activeApp))
})
}
9 changes: 9 additions & 0 deletions packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import Rename from './actions/rename'
import Restore from './actions/restore'
import kebabCase from 'lodash-es/kebabCase'

import { activeApp } from 'web-pkg/src/composables'
import { isFilesAppActive } from '../composables'

const actionsMixins = [
'fetch',
'navigate',
Expand Down Expand Up @@ -55,6 +58,12 @@ export default {
...mapGetters('Files', ['highlightedFile', 'currentFolder']),
...mapGetters(['capabilities', 'configuration']),

// TODO: Replace this with the useIsFilesAppActive composable
// once we port this mixin to something using the composition api
isFilesAppActive() {
return isFilesAppActive(activeApp(this.$route))
},

$_fileActions_systemActions() {
return actionsMixins.flatMap((actionMixin) => {
return this[`$_${actionMixin}_items`]
Expand Down
7 changes: 6 additions & 1 deletion packages/web-pkg/src/composables/router/useActiveApp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { computed, ComputedRef, unref } from '@vue/composition-api'
import { useRoute } from './useRoute'
import { Route } from 'vue-router'

export const activeApp = (route : Route) : string => {
return route.path.split('/')[1]
}

export const useActiveApp = (): ComputedRef<string> => {
const route = useRoute()
return computed(() => {
return unref(route).path.split('/')[1]
return activeApp(unref(route))
})
}

0 comments on commit a07f09f

Please sign in to comment.