From 584cf7bc55846ee5973a56f0ae396f0fc0a1f3b7 Mon Sep 17 00:00:00 2001 From: Pascal Wengerter Date: Fri, 16 Dec 2022 20:22:06 +0100 Subject: [PATCH] Address code review --- .../src/components/OcRecipient/OcRecipient.spec.ts | 1 - .../src/components/OcResourceIcon/OcResourceIcon.spec.ts | 1 - packages/web-app-files/src/components/AppBar/AppBar.vue | 2 +- .../web-app-files/src/components/AppBar/ViewOptions.vue | 6 +++--- .../resourcesViewDefaults/useResourcesViewDefaults.ts | 2 +- .../web-app-files/src/composables/viewMode/constants.ts | 6 +++++- .../web-app-files/src/composables/viewMode/useViewMode.ts | 5 +++-- .../tests/unit/components/AppBar/ViewOptions.spec.ts | 5 +++-- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/design-system/src/components/OcRecipient/OcRecipient.spec.ts b/packages/design-system/src/components/OcRecipient/OcRecipient.spec.ts index 51e147440ea..8ca8ea2a03e 100644 --- a/packages/design-system/src/components/OcRecipient/OcRecipient.spec.ts +++ b/packages/design-system/src/components/OcRecipient/OcRecipient.spec.ts @@ -53,7 +53,6 @@ describe('OcRecipient', () => { hasAvatar: false }) - console.log(wrapper.html()) const icon = wrapper.find('[data-testid="recipient-icon"]') expect(icon.exists()).toBeTruthy() diff --git a/packages/design-system/src/components/OcResourceIcon/OcResourceIcon.spec.ts b/packages/design-system/src/components/OcResourceIcon/OcResourceIcon.spec.ts index 4121273e69d..022ada40738 100644 --- a/packages/design-system/src/components/OcResourceIcon/OcResourceIcon.spec.ts +++ b/packages/design-system/src/components/OcResourceIcon/OcResourceIcon.spec.ts @@ -1,5 +1,4 @@ import { shallowMount } from '@vue/test-utils' - import { AVAILABLE_SIZES } from '../../helpers/constants' import { OcResourceIcon } from '..' diff --git a/packages/web-app-files/src/components/AppBar/AppBar.vue b/packages/web-app-files/src/components/AppBar/AppBar.vue index a046e0f8ff9..e5851394794 100644 --- a/packages/web-app-files/src/components/AppBar/AppBar.vue +++ b/packages/web-app-files/src/components/AppBar/AppBar.vue @@ -58,7 +58,7 @@ import { mapGetters, mapState, mapMutations } from 'vuex' import { Resource } from 'web-client' import { SpaceResource } from 'web-client/src/helpers' -import { ViewModeConstants } from '../../composables' +import { ViewModeConstants } from '../../composables/viewMode/constants' import { BreadcrumbItem } from '../../helpers/breadcrumbs' import MixinFileActions from '../../mixins/fileActions' import { isLocationTrashActive } from '../../router' diff --git a/packages/web-app-files/src/components/AppBar/ViewOptions.vue b/packages/web-app-files/src/components/AppBar/ViewOptions.vue index 9a878a0bb55..a7f841c3670 100644 --- a/packages/web-app-files/src/components/AppBar/ViewOptions.vue +++ b/packages/web-app-files/src/components/AppBar/ViewOptions.vue @@ -8,9 +8,9 @@ @@ -85,7 +85,7 @@ export default defineComponent({ }) const viewModeQuery = useRouteQueryPersisted({ name: ViewModeConstants.queryName, - defaultValue: ViewModeConstants.default.name + defaultValue: ViewModeConstants.defaultModeName }) return { diff --git a/packages/web-app-files/src/composables/resourcesViewDefaults/useResourcesViewDefaults.ts b/packages/web-app-files/src/composables/resourcesViewDefaults/useResourcesViewDefaults.ts index e136c25673d..180ecccdf73 100644 --- a/packages/web-app-files/src/composables/resourcesViewDefaults/useResourcesViewDefaults.ts +++ b/packages/web-app-files/src/composables/resourcesViewDefaults/useResourcesViewDefaults.ts @@ -68,7 +68,7 @@ export const useResourcesViewDefaults = ( fields }) - const currentViewModeQuery = useRouteQuery('view-mode', ViewModeConstants.default.name) + const currentViewModeQuery = useRouteQuery('view-mode', ViewModeConstants.defaultModeName) const currentViewMode = computed((): string => queryItemAsString(currentViewModeQuery.value)) const viewMode = useViewMode(currentViewMode) diff --git a/packages/web-app-files/src/composables/viewMode/constants.ts b/packages/web-app-files/src/composables/viewMode/constants.ts index 5a5c7a1c069..58d87a68971 100644 --- a/packages/web-app-files/src/composables/viewMode/constants.ts +++ b/packages/web-app-files/src/composables/viewMode/constants.ts @@ -1,7 +1,11 @@ -import { $gettext } from 'web-app-files/src/router/utils' import { ViewMode } from 'web-pkg/src/ui/types' +function $gettext(msg: string): string { + return msg +} + export abstract class ViewModeConstants { + static readonly defaultModeName: string = 'resource-table' static readonly default: ViewMode = { name: 'resource-table', label: $gettext('Switch to default table view'), diff --git a/packages/web-app-files/src/composables/viewMode/useViewMode.ts b/packages/web-app-files/src/composables/viewMode/useViewMode.ts index 5167a4c3d6a..ccf1f981e5a 100644 --- a/packages/web-app-files/src/composables/viewMode/useViewMode.ts +++ b/packages/web-app-files/src/composables/viewMode/useViewMode.ts @@ -1,5 +1,6 @@ import { computed, ComputedRef, unref } from 'vue' -import { queryItemAsString, useRouteQueryPersisted } from 'web-pkg/src/composables' +import { queryItemAsString } from 'web-pkg/src/composables/appDefaults' +import { useRouteQueryPersisted } from 'web-pkg/src/composables/router' import { ViewModeConstants } from './constants' export function useViewMode(options: ComputedRef): ComputedRef { @@ -9,7 +10,7 @@ export function useViewMode(options: ComputedRef): ComputedRef queryItemAsString(unref(viewModeQuery))) } diff --git a/packages/web-app-files/tests/unit/components/AppBar/ViewOptions.spec.ts b/packages/web-app-files/tests/unit/components/AppBar/ViewOptions.spec.ts index c818a797051..c3a026e7a2a 100644 --- a/packages/web-app-files/tests/unit/components/AppBar/ViewOptions.spec.ts +++ b/packages/web-app-files/tests/unit/components/AppBar/ViewOptions.spec.ts @@ -9,6 +9,7 @@ import { defaultComponentMocks } from 'web-test-helpers' import { ViewModeConstants } from 'web-app-files/src/composables' +import { ViewMode } from 'web-pkg/src/ui/types' jest.mock('web-pkg/src/composables/router') const selectors = { @@ -52,8 +53,8 @@ describe('ViewOptions component', () => { function getWrapper( { perPage = '100' } = {}, - props: { [key: string]: any } = { - viewModes: [] + props?: { + viewModes: ViewMode[] } ) { jest.mocked(useRouteQueryPersisted).mockImplementation(() => ref(perPage))