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 all commits
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,8 @@ 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'

export default {
setup() {
return {
isFilesAppActive: useIsFilesAppActive()
}
},
name: 'BatchActions',
components: { ActionMenuItem },
mixins: [
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
17 changes: 0 additions & 17 deletions packages/web-app-files/src/composables/useIsFilesAppActive.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/web-app-files/src/mixins/actions/downloadArchive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
isLocationPublicActive,
isLocationSpacesActive
} from '../../router'
import isFilesAppActive from './helpers/isFilesAppActive'

export default {
mixins: [isFilesAppActive],
computed: {
$_downloadArchive_items() {
return [
Expand All @@ -21,7 +23,7 @@ export default {
},
isEnabled: ({ resources }) => {
if (
this.isFilesAppActive &&
this.$_isFilesAppActive &&
!isLocationSpacesActive(this.$router, 'files-spaces-personal-home') &&
!isLocationSpacesActive(this.$router, 'files-spaces-project') &&
!isLocationPublicActive(this.$router, 'files-public-files') &&
Expand Down
4 changes: 3 additions & 1 deletion packages/web-app-files/src/mixins/actions/downloadFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
isLocationPublicActive,
isLocationSpacesActive
} from '../../router'
import isFilesAppActive from './helpers/isFilesAppActive'

export default {
mixins: [isFilesAppActive],
computed: {
$_downloadFile_items() {
return [
Expand All @@ -17,7 +19,7 @@ export default {
},
isEnabled: ({ resources }) => {
if (
this.isFilesAppActive &&
this.$_isFilesAppActive &&
!isLocationSpacesActive(this.$router, 'files-spaces-personal-home') &&
!isLocationSpacesActive(this.$router, 'files-spaces-project') &&
!isLocationPublicActive(this.$router, 'files-public-files') &&
Expand Down
4 changes: 3 additions & 1 deletion packages/web-app-files/src/mixins/actions/favorite.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { mapActions } from 'vuex'

import { isLocationCommonActive, isLocationSpacesActive } from '../../router'
import isFilesAppActive from './helpers/isFilesAppActive'

export default {
mixins: [isFilesAppActive],
computed: {
$_favorite_items() {
return [
Expand All @@ -18,7 +20,7 @@ export default {
},
isEnabled: ({ resources }) => {
if (
this.isFilesAppActive &&
this.$_isFilesAppActive &&
!isLocationSpacesActive(this.$router, 'files-spaces-personal-home') &&
!isLocationCommonActive(this.$router, 'files-common-favorites')
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { activeApp } from 'web-pkg/src/composables'

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

export default {
computed: {
$_isFilesAppActive(): boolean {
return isFilesAppActive(activeApp(this.$route))
}
}
}
4 changes: 3 additions & 1 deletion packages/web-app-files/src/mixins/actions/showActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { mapActions } from 'vuex'
import { isLocationCommonActive } from '../../router'
import isFilesAppActive from './helpers/isFilesAppActive'

export default {
mixins: [isFilesAppActive],
computed: {
$_showActions_items() {
return [
Expand All @@ -13,7 +15,7 @@ export default {
handler: this.$_showActions_trigger,
isEnabled: ({ resources }) => {
// sidebar is currently only available inside files app
if (!this.isFilesAppActive) {
if (!this.$_isFilesAppActive) {
return false
}

Expand Down
4 changes: 3 additions & 1 deletion packages/web-app-files/src/mixins/actions/showDetails.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { mapActions } from 'vuex'
import { isLocationCommonActive } from '../../router'
import isFilesAppActive from './helpers/isFilesAppActive'

export default {
mixins: [isFilesAppActive],
computed: {
$_showDetails_items() {
return [
Expand All @@ -15,7 +17,7 @@ export default {
// remove trashbin route rule once we have them.
isEnabled: ({ resources }) => {
// sidebar is currently only available inside files app
if (!this.isFilesAppActive) {
if (!this.$_isFilesAppActive) {
return false
}

Expand Down
4 changes: 3 additions & 1 deletion packages/web-app-files/src/mixins/actions/showShares.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import quickActions, { canShare, openNewCollaboratorsPanel } from '../../quickActions'
import { isLocationCommonActive, isLocationSharesActive } from '../../router'
import { ShareStatus } from '../../helpers/share'
import isFilesAppActive from './helpers/isFilesAppActive'

export default {
mixins: [isFilesAppActive],
computed: {
$_showShares_items() {
return [
Expand All @@ -14,7 +16,7 @@ export default {
handler: this.$_showShares_trigger,
isEnabled: ({ resources }) => {
// sidebar is currently only available inside files app
if (!this.isFilesAppActive) {
if (!this.$_isFilesAppActive) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function createWrapper(testResource, tooltipStub, routeName) {
}
],
mocks: {
$route: {
path: '/files'
},
$router: {
currentRoute: {
name: routeName || 'some-route',
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))
})
}