-
Notifications
You must be signed in to change notification settings - Fork 159
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
Make viewoption modes configurable via appBar || Extend OcResourceIcon for spaces #8105
Conversation
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. |
38da3d6
to
e5adb8f
Compare
@@ -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" /> |
There was a problem hiding this comment.
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.
11a4863
to
dfccb41
Compare
dfccb41
to
9971b3f
Compare
packages/design-system/src/components/OcResourceIcon/OcResourceIcon.vue
Outdated
Show resolved
Hide resolved
packages/web-app-files/tests/unit/components/AppBar/ViewOptions.spec.js
Outdated
Show resolved
Hide resolved
@kulmann tests are green, ready for re-review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
} | ||
}, | ||
computed: { | ||
iconName() { | ||
if (this.isSpace) return defaultSpaceIcon |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;-)
There was a problem hiding this comment.
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)?
There was a problem hiding this 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.
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
There was a problem hiding this comment.
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".
There was a problem hiding this 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.
For the future use case of having view modes registered through the extension system it would indeed be beneficial to define a |
36d901e
to
194a8fc
Compare
There was a problem hiding this 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' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] | ||
} |
There was a problem hiding this comment.
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 } = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
5a581fa
to
584cf7b
Compare
There was a problem hiding this 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' |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
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" /> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { AVAILABLE_SIZES } from '../../helpers/constants' | |
import { AVAILABLE_SIZES } from '../../helpers' |
(at least that's what my IDE is complaining about ;-) )
There was a problem hiding this comment.
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 :)
…nd extract IconFillType to designsystem
…Space+Favorties view
584cf7b
to
adbe049
Compare
adbe049
to
33cdf83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤘
SonarCloud Quality Gate failed. |
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)
Description
Follow-up to #7976
Types of changes
@kulmann @tbsbdr do you want the condensed option on the favorites view also?