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 fe1ef1f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 31 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'
17 changes: 0 additions & 17 deletions packages/web-app-files/src/composables/useIsFilesAppActive.ts

This file was deleted.

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 fe1ef1f

Please sign in to comment.