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 viewoption modes configurable via appBar || Extend OcResourceIcon for spaces #8105

Merged

Conversation

pascalwengerter
Copy link
Contributor

@pascalwengerter pascalwengerter commented Dec 12, 2022

Description

Follow-up to #7976

Types of changes

  • New feature (non-breaking change which adds functionality)

@kulmann @tbsbdr do you want the condensed option on the favorites view also?

@update-docs
Copy link

update-docs bot commented Dec 12, 2022

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@pascalwengerter pascalwengerter changed the title WIP: Feature/add appbar viewoptions modes WIP: Make viewoption modes configurable via appBar Dec 12, 2022
@pascalwengerter pascalwengerter force-pushed the feature/add-appbar-viewoptions-modes branch from 38da3d6 to e5adb8f Compare December 13, 2022 08:02
@@ -28,7 +28,7 @@
</oc-breadcrumb>
<shares-navigation v-if="hasSharesNavigation" />
<div v-if="hasViewOptions || hasSidebarToggle" class="oc-flex">
<view-options v-if="hasViewOptions" />
<view-options v-if="hasViewOptions" :additional-view-modes="viewModeOptions" />
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer view-modes as prop name and list all available view modes with it. Otherwise the next dev/reader needs to understand first what additional means.

@pascalwengerter pascalwengerter force-pushed the feature/add-appbar-viewoptions-modes branch 3 times, most recently from 11a4863 to dfccb41 Compare December 13, 2022 22:35
@pascalwengerter pascalwengerter marked this pull request as ready for review December 13, 2022 22:35
@pascalwengerter pascalwengerter force-pushed the feature/add-appbar-viewoptions-modes branch from dfccb41 to 9971b3f Compare December 13, 2022 22:45
@pascalwengerter pascalwengerter changed the title WIP: Make viewoption modes configurable via appBar Make viewoption modes configurable via appBar || Extend OcResourceIcon for spaces Dec 13, 2022
@pascalwengerter pascalwengerter requested review from dschmidt and kulmann and removed request for kulmann and dschmidt December 14, 2022 19:18
@pascalwengerter
Copy link
Contributor Author

@kulmann tests are green, ready for re-review :)

Copy link
Contributor

@JammingBen JammingBen left a comment

Choose a reason for hiding this comment

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

I really like that we have a space resource icon now! Should we maybe use the same color as in the sidebar and the projects view? A brighter blue is being used there.

image

}
}
},
computed: {
iconName() {
if (this.isSpace) return defaultSpaceIcon
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it was like this already, but we decided to not use one-line-if-blocks in the project because they are somewhat ugly to read.

Copy link
Member

Choose a reason for hiding this comment

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

.... and because they make debugging more cumbersome and make diffs harder to read when changed later ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So just plain old

if (true) {
  return "something"
}

then, just for clarification?

And what about return "something" ? condition : "fallback", are those types of statements allowed (since I see them used in the same component also)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really like that we have a space resource icon now! Should we maybe use the same color as in the sidebar and the projects view? A brighter blue is being used there.

image

Great eye! I've updated it and would need from @tbsbdr if a ResourceIcon of type "space" should have a more distinct color down the road - for now it'll be the default "passive swatch" color, as it already is in other places right now

Copy link
Contributor

Choose a reason for hiding this comment

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

return "something" ? condition : "fallback" or const someVariable = "something" ? condition : "fallback" is fine. We just don't want to have the "one-line-return/continue".

Copy link
Member

@dschmidt dschmidt left a comment

Choose a reason for hiding this comment

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

Hrm now the additional-view-modes moved one level up, I'm not sure that any better than before.
The issue is the same: one needs to look up what it gets added to and one cannot remove the defaults, maybe we should just push the whole list from wherever AppBar is used?

Also I find it weird to pass an arbitrary array of strings into the component where just a few hardcoded ones are handled. If we stick to the hardcoded list of options, I would argue we should instead just use boolean props to enable/disable them.

If we want to pass in a list to make it more flexible, we should pass in an array of mode switch objects, which provide their "query name"(aria), labels, icons, and which we can loop over.

edit:
Currently you're using this list just to check whether it's longer than 1 element or not... that could be a single boolean ;-)

Depending on how flexible you want to make it (and how much effort you want to put in), I'd prefer the "pass an array of objects and render the buttons dynamically" approach, but a single bool param to enable/disable the switcher or individual bool props to disable the currently hardcoded mode buttons would be fine for me as well.

@kulmann
Copy link
Member

kulmann commented Dec 15, 2022

For the future use case of having view modes registered through the extension system it would indeed be beneficial to define a ViewMode interface and pass a list of view mode objects (with icon, label, some id/name prop) through and don't have any hardcoded values in the ViewOptions.vue component.

@pascalwengerter pascalwengerter force-pushed the feature/add-appbar-viewoptions-modes branch from 36d901e to 194a8fc Compare December 15, 2022 21:46
Copy link
Member

@dschmidt dschmidt left a comment

Choose a reason for hiding this comment

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

Love where this is going 🤩

@@ -0,0 +1,26 @@
import { shallowMount } from '@vue/test-utils'
Copy link
Member

Choose a reason for hiding this comment

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

Please import from web-test-helpers

Copy link
Member

Choose a reason for hiding this comment

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

Still valid / unresolved.

if (!this.displayViewModeSwitch) {
return []
}
return [ViewModeConstants.condensedTable, ViewModeConstants.default]
}
Copy link
Member

Choose a reason for hiding this comment

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

Me gusta

function getWrapper({ perPage = '100' } = {}) {
function getWrapper(
{ perPage = '100' } = {},
props: { [key: string]: any } = {
Copy link
Member

Choose a reason for hiding this comment

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

No need for this type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VSCode wanted one pretty badly, but I'll try without...

@@ -9,7 +9,7 @@ export function useViewMode<T>(options: ComputedRef<string>): ComputedRef<string

const viewModeQuery = useRouteQueryPersisted({
name: ViewModeConstants.queryName,
defaultValue: ViewModeConstants.default
defaultValue: ViewModeConstants.default.name
Copy link
Member

Choose a reason for hiding this comment

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

I've seen this code a bunch of times, maybe worth putting into its own composable

:key="viewMode.name"
v-oc-tooltip="viewMode.label"
:appearance="viewModeCurrent === viewMode.name ? 'filled' : 'outline'"
:label="viewMode.label"
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to pass this to $gettext again to make translations actually work

@pascalwengerter pascalwengerter requested review from dschmidt, JammingBen and kulmann and removed request for kulmann, dschmidt and JammingBen December 16, 2022 08:33
@pascalwengerter pascalwengerter force-pushed the feature/add-appbar-viewoptions-modes branch 3 times, most recently from 5a581fa to 584cf7b Compare December 16, 2022 19:16
Copy link
Member

@kulmann kulmann left a comment

Choose a reason for hiding this comment

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

Found some more nitpick-material, sorry 😅

@@ -0,0 +1,26 @@
import { shallowMount } from '@vue/test-utils'
Copy link
Member

Choose a reason for hiding this comment

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

Still valid / unresolved.


const resources = ['file', 'folder', 'space']

function getWrapper(props) {
Copy link
Member

Choose a reason for hiding this comment

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

Please move the getWrapper function below the tests (for consistency with other tests in web).

const resources = ['file', 'folder', 'space']

function getWrapper(props) {
return shallowMount(OcResourceIcon, {
Copy link
Member

Choose a reason for hiding this comment

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

Please return an object with key wrapper and your shallowMount call as value, i.e.

return {
  wrapper: shallowMount(...

for consistency with other tests in web.

@@ -1,7 +1,7 @@
<template>
<div class="oc-flex">
<files-view-wrapper>
<app-bar :side-bar-open="sideBarOpen" />
<app-bar :display-view-mode-switch="true" :side-bar-open="sideBarOpen" />
Copy link
Member

Choose a reason for hiding this comment

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

Side note: This already is an example where we don't want the condensed view mode (or at least it doesn't make too much sense, since it is not different from the default list view mode), but will want to have the tiles view mode available in the future. :-/ Let's keep it like you have it here for the time being.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

soon

@@ -326,7 +326,7 @@ export default defineComponent({
},
viewMode: {
type: String,
default: ViewModeConstants.default
default: ViewModeConstants.default.name
Copy link
Member

Choose a reason for hiding this comment

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

You have already introduced the defaultModeName const for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently slipped through, sry about that

}
)
const viewModeSwitchButtons = wrapper.find('[data-testid="viewmode-switch-buttons"]')
expect(viewModeSwitchButtons).toMatchSnapshot()
Copy link
Member

Choose a reason for hiding this comment

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

Would like to avoid a snapshot test for this. Should already be sufficient to check the presence of the element.
If you ever find a situation where a snapshot test is useful, please do so on the .html() result of the element. Will be required shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm somewhat torn about this - I know the oC web team in general is not a huge fan of snapshot tests, however in this case it's not only asserting that there is an element with a viewmode-switch-buttons data-testid, but also that there's two buttons, each with an icon inside (and checks for the momentarily correct CSS classes etc)

Copy link
Member

Choose a reason for hiding this comment

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

Also fine to keep it... I'd go the way of asserting that there are x buttons and ignoring the icon assertion for example.

But: please change line 50 to expect(viewModeSwitchButtons.html()).toMatchSnapshot()

import OcIcon from '../OcIcon/OcIcon.vue'
import iconNameMap from '../../helpers/resourceIconExtensionMapping'
import iconColorMap from '../../helpers/resourceIconColorExtensionMapping'
import { AVAILABLE_SIZES } from '../../helpers/constants'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import { AVAILABLE_SIZES } from '../../helpers/constants'
import { AVAILABLE_SIZES } from '../../helpers'

(at least that's what my IDE is complaining about ;-) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possible but can eventually lead to circular import (stumbled upon this last week), will fix for now but keep in mind pls :)

@pascalwengerter pascalwengerter force-pushed the feature/add-appbar-viewoptions-modes branch from 584cf7b to adbe049 Compare December 19, 2022 21:18
@pascalwengerter pascalwengerter force-pushed the feature/add-appbar-viewoptions-modes branch from adbe049 to 33cdf83 Compare December 19, 2022 21:40
Copy link
Member

@kulmann kulmann left a comment

Choose a reason for hiding this comment

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

🤘

@sonarcloud
Copy link

sonarcloud bot commented Dec 19, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 2 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

75.0% 75.0% Coverage
0.0% 0.0% Duplication

@kulmann kulmann merged commit 508c716 into owncloud:master Dec 19, 2022
ownclouders pushed a commit that referenced this pull request Dec 19, 2022
Author: Pascal Wengerter <[email protected]>
Date:   Tue Dec 20 00:14:26 2022 +0100

    Make viewoption modes configurable via appBar || Extend OcResourceIcon for spaces (#8105)
@pascalwengerter pascalwengerter deleted the feature/add-appbar-viewoptions-modes branch December 21, 2022 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants