Skip to content

Commit 24251a7

Browse files
committed
Vue 3: fix unwanted scrollbars on narrow viewports
1 parent 61fc425 commit 24251a7

File tree

12 files changed

+296
-158
lines changed

12 files changed

+296
-158
lines changed

src/components/cylc/Toolbar.vue

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,39 @@ component. Note: this is not used for the workflow view, see
2323
<template>
2424
<v-toolbar
2525
id="core-app-bar"
26-
density="compact"
26+
absolute
27+
:height="toolbarHeight"
2728
flat
2829
class="c-toolbar"
29-
v-if="showNavBtn"
3030
>
31-
<v-toolbar-title
32-
class="tertiary--text"
31+
<!-- TODO: duplicated in workflow/Toolbar.vue and cylc/Toolbar.vue -->
32+
<!-- burger button for mobile -->
33+
<v-btn
34+
icon
35+
@click.stop="toggleDrawer"
36+
id="toggle-drawer"
3337
>
34-
<!-- TODO: duplicated in workflow/Toolbar.vue and cylc/Toolbar.vue -->
35-
<!-- burger button for mobile -->
36-
<v-btn
37-
icon
38-
@click.stop="onClickBtn"
39-
class="default v-btn--simple"
40-
id="toggle-drawer"
41-
>
42-
<v-icon>{{ svgPaths.list }}</v-icon>
43-
</v-btn>
44-
<!-- title -->
45-
<span class="c-toolbar-title">{{ title }}</span>
38+
<v-icon>{{ svgPaths.list }}</v-icon>
39+
</v-btn>
40+
<v-toolbar-title>
41+
{{ title }}
4642
</v-toolbar-title>
4743
</v-toolbar>
4844
</template>
4945

5046
<script>
5147
import { mapState } from 'vuex'
52-
import toolbar from '@/mixins/toolbar'
48+
import { useToolbar, toolbarHeight } from '@/utils/toolbar'
5349
import {
5450
mdiViewList
5551
} from '@mdi/js'
5652
5753
export default {
54+
setup () {
55+
const { toggleDrawer } = useToolbar()
56+
return { toggleDrawer, toolbarHeight }
57+
},
58+
5859
mixins: [
5960
toolbar
6061
],

src/components/cylc/workflow/Toolbar.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ You should have received a copy of the GNU General Public License
1515
along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
-->
1717

18-
<!-- Toolbar for the workflow view -->
18+
<!-- Toolbar for the workspace view -->
1919

2020
<template>
2121
<v-toolbar
2222
id="core-app-bar"
23-
density="compact"
23+
:height="toolbarHeight"
2424
flat
2525
class="c-toolbar"
2626
color="grey-lighten-4"
@@ -30,8 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3030
<v-btn
3131
v-if="showNavBtn"
3232
icon
33-
@click.stop="onClickBtn"
34-
class="default v-btn--simple"
33+
@click.stop="toggleDrawer"
3534
id="toggle-drawer"
3635
>
3736
<v-icon>{{ svgPaths.list }}</v-icon>
@@ -148,19 +147,22 @@ import {
148147
mdiViewList
149148
} from '@mdi/js'
150149
import { startCase } from 'lodash'
151-
import toolbar from '@/mixins/toolbar'
150+
import { useToolbar, toolbarHeight } from '@/utils/toolbar'
152151
import WorkflowState from '@/model/WorkflowState.model'
153152
import graphql from '@/mixins/graphql'
154-
155153
import {
156154
mutationStatus
157155
} from '@/utils/aotf'
158156
159157
export default {
160158
name: 'Toolbar',
161159
160+
setup () {
161+
const { showNavBtn, toggleDrawer } = useToolbar()
162+
return { showNavBtn, toggleDrawer, toolbarHeight }
163+
},
164+
162165
mixins: [
163-
toolbar,
164166
graphql
165167
],
166168

src/layouts/Default.vue

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
<template>
1919
<div>
2020
<ConnectionStatus :is-offline="offline" />
21-
<toolbar v-if="!workflowViews.includes($route.name)" />
22-
<drawer v-if="showSidebar" />
21+
<Toolbar v-if="showToolbar" />
22+
<Drawer v-if="showSidebar" />
2323
<CylcObjectMenu/>
2424

2525
<v-main>
2626
<alert />
27-
<div id="core-view" class="h-screen overflow-auto">
27+
<div
28+
id="core-view"
29+
class="overflow-auto"
30+
:style="coreViewStyle"
31+
>
2832
<v-fade-transition mode="out-in">
2933
<slot/>
3034
</v-fade-transition>
@@ -34,18 +38,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3438
</template>
3539

3640
<script>
41+
import { computed } from 'vue'
42+
import { useRoute } from 'vue-router'
3743
import { mapState } from 'vuex'
3844
import { store } from '@/store/index'
3945
import AlertModel from '@/model/Alert.model'
4046
import Alert from '@/components/core/Alert.vue'
4147
import Drawer from '@/components/cylc/Drawer.vue'
4248
import Toolbar from '@/components/cylc/Toolbar.vue'
49+
import { useNavBtn, toolbarHeight } from '@/utils/toolbar'
4350
import ConnectionStatus from '@/components/cylc/ConnectionStatus.vue'
4451
import CylcObjectMenu from '@/components/cylc/cylcObject/Menu.vue'
4552
4653
export default {
4754
name: 'Default',
4855
56+
setup () {
57+
const route = useRoute()
58+
/**
59+
* Views that display workflows. For these views, we do not
60+
* want to display the default Toolbar—the Workflow view
61+
* has its own Toolbar that communicates with the Workflow
62+
* component (e.g. the Workflow Toolbar owns a button that
63+
* triggers the action to add a new Tree or Table View, so the events
64+
* are passed down from the parent Workflow View).
65+
*/
66+
const workflowViews = [
67+
'workspace',
68+
'tree',
69+
'table',
70+
'graph',
71+
]
72+
const { showNavBtn } = useNavBtn()
73+
74+
/** Whether to show app toolbar (not the workspace view toolbar). */
75+
const showToolbar = computed(
76+
() => showNavBtn.value && !workflowViews.includes(route.name)
77+
)
78+
const coreViewStyle = computed(() => ({
79+
marginTop: showToolbar.value ? `${toolbarHeight}px` : 0,
80+
height: showToolbar.value ? `calc(100vh - ${toolbarHeight}px)` : '100vh',
81+
}))
82+
83+
return {
84+
showToolbar,
85+
coreViewStyle,
86+
}
87+
},
88+
4989
components: {
5090
ConnectionStatus,
5191
CylcObjectMenu,
@@ -62,25 +102,6 @@ export default {
62102
}
63103
},
64104
65-
data () {
66-
return {
67-
/**
68-
* Views that display workflows. For these views, we do not
69-
* want to display the default Toolbar—the Workflow view
70-
* has its own Toolbar that communicates with the Workflow
71-
* component (e.g. the Workflow Toolbar owns a button that
72-
* triggers the action to add a new Tree or Table View, so the events
73-
* are passed down from the parent Workflow View).
74-
*/
75-
workflowViews: [
76-
'workspace',
77-
'tree',
78-
'table',
79-
'graph'
80-
]
81-
}
82-
},
83-
84105
computed: {
85106
...mapState(['offline'])
86107
},

src/mixins/toolbar.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/styles/cylc/_workflow.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
.workflow-panel {
2222
.main {
2323
display: flex;
24-
min-height: calc(100vh - 48px);
2524
.content {
2625
min-width: 300px;
2726
min-height: 300px;

src/styles/index.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ html {
5151
}
5252
}
5353

54-
// The following two entries are used to set the height of the content view (core-view), under the
55-
// toolbar, to the maximum. And the skeleton needs to maintain the height 100% otherwise its children
54+
// The skeleton loader needs to maintain the height 100% otherwise its children
5655
// nodes with height: 100% or auto won't be displayed at all.
57-
#core-view {
58-
height: calc(100vh - 48px);
59-
}
6056
.v-skeleton-loader {
6157
height: 100%;
6258
}

src/utils/toolbar.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
import { computed, onMounted } from 'vue'
19+
import { useDisplay } from 'vuetify'
20+
import { useStore } from 'vuex'
21+
22+
/** Height in px */
23+
export const toolbarHeight = 48
24+
25+
/**
26+
* Composable that returns a computed property for whether we should show
27+
* the hamburger nav drawer button.
28+
*/
29+
export function useNavBtn () {
30+
const { mobile } = useDisplay()
31+
const store = useStore()
32+
return {
33+
showNavBtn: computed(() => mobile.value || !store.state.app.drawer),
34+
}
35+
}
36+
37+
/**
38+
* Composable that replaces the old toolbar mixin.
39+
*
40+
* Main responsibility is to add responsive toggle
41+
* to a Toolbar component. Shared between (at least) the Cylc
42+
* UI default Toolbar, and the Workflow view Toolbar.
43+
*/
44+
export function useToolbar () {
45+
const store = useStore()
46+
const { showNavBtn } = useNavBtn()
47+
48+
onMounted(() => {
49+
store.commit('app/setDrawer', !showNavBtn.value)
50+
})
51+
52+
const toggleDrawer = () => {
53+
store.commit('app/setDrawer', !store.state.app.drawer)
54+
}
55+
56+
return {
57+
showNavBtn,
58+
toggleDrawer,
59+
}
60+
}

src/views/Workspace.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
<Toolbar
2121
:views="$options.allViews"
2222
:workflow-name="workflowName"
23-
@add="this.addView"
24-
:initialOptions="{}"
23+
@add="addView"
2524
/>
26-
<div class="workflow-panel">
25+
<div
26+
class="workflow-panel"
27+
:style="$options.panelStyle"
28+
>
2729
<Lumino
2830
ref="lumino"
2931
@lumino:deleted="onWidgetDeletedEvent"
@@ -52,6 +54,7 @@ import subscriptionMixin from '@/mixins/subscription'
5254
import ViewState from '@/model/ViewState.model'
5355
import Lumino from '@/components/cylc/workflow/Lumino.vue'
5456
import Toolbar from '@/components/cylc/workflow/Toolbar.vue'
57+
import { toolbarHeight } from '@/utils/toolbar'
5558
5659
// Use dynamic async components for lazy loading:
5760
const TreeView = defineAsyncComponent(() => import('@/views/Tree.vue'))
@@ -195,5 +198,9 @@ export default {
195198
* @type {Object[]}
196199
*/
197200
allViews,
201+
202+
panelStyle: {
203+
height: `calc(100vh - ${toolbarHeight}px)`,
204+
},
198205
}
199206
</script>

0 commit comments

Comments
 (0)