Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fileActions mixin standalone again. #6453

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ 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() {
return {
isFilesAppActive: useIsFilesAppActive()
}
},
name: 'BatchActions',
components: { ActionMenuItem },
mixins: [
Expand All @@ -44,6 +39,11 @@ export default {
Move,
Restore
],
setup() {
return {
isFilesAppActive: useIsFilesAppActive()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, can't you delete this again with the helper function now being used in the mixins?

}
},
computed: {
...mapGetters('Files', ['selectedFiles']),

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, is it really sufficient to provide the function here? Are we using the fileActions mixin really in all locations that use any of the specific file action mixins?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why the composable is still used in BatchActions ...
We include single actions there and not the fileActions mixin.

... but that's a very good point, this has become hard to reason about. I will add this to all the mixins :(

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))
})
}