Skip to content

Commit f56f76e

Browse files
committed
[frontend] Add the option to not show a header in the HueTable component
1 parent aed0d9a commit f56f76e

File tree

4 files changed

+173
-118
lines changed

4 files changed

+173
-118
lines changed

desktop/core/src/desktop/js/components/HueTable.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// limitations under the License.
1616

1717
export interface Column<T> {
18-
label: string;
19-
key: string | number;
18+
label?: string;
19+
key: keyof T | string | number;
2020
cssClass?: string;
2121
htmlValue?: boolean;
2222
headerCssClass?: string;
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
Licensed to Cloudera, Inc. under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. Cloudera, Inc. licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
@import './styles/colors';
20+
@import './styles/mixins';
21+
22+
.hue-table-container {
23+
overflow-x: auto;
24+
width: 100%;
25+
margin: 0 0 15px 0;
26+
27+
.hue-table {
28+
line-height: 14px;
29+
table-layout: auto;
30+
border-collapse: separate;
31+
32+
&.header-less {
33+
border-collapse: collapse;
34+
tbody > tr:first-child {
35+
border-top: 1px solid $fluid-gray-300;
36+
}
37+
}
38+
39+
thead,
40+
tbody {
41+
tr {
42+
height: 40px;
43+
44+
th,
45+
td {
46+
@include nowrap-ellipsis;
47+
48+
height: 16px;
49+
max-width: 300px;
50+
padding: 12px;
51+
border-bottom: 1px solid $fluid-gray-300;
52+
text-align: left;
53+
54+
&.column-flush {
55+
width: 100%;
56+
}
57+
}
58+
}
59+
}
60+
61+
thead {
62+
tr {
63+
th {
64+
background-color: $fluid-white;
65+
color: $fluid-gray-700;
66+
font-size: 13px;
67+
font-weight: 500;
68+
white-space: nowrap;
69+
70+
&.sticky-first-col {
71+
background-color: $fluid-white;
72+
position: sticky;
73+
position: -webkit-sticky;
74+
left: 0;
75+
z-index: 102;
76+
}
77+
78+
.sort-header {
79+
display: flex;
80+
cursor: pointer;
81+
align-items: center;
82+
letter-spacing: normal;
83+
outline: 0;
84+
}
85+
}
86+
}
87+
}
88+
89+
tbody {
90+
tr {
91+
td {
92+
color: $fluid-gray-900;
93+
font-size: 14px;
94+
95+
&.sticky-first-col {
96+
@include position-sticky;
97+
98+
background-color: $fluid-white;
99+
left: 0;
100+
z-index: 100;
101+
}
102+
103+
&:last-of-type {
104+
padding-right: 8px;
105+
}
106+
}
107+
}
108+
109+
&.clickable-rows tr {
110+
cursor: pointer;
111+
112+
&:hover {
113+
background-color: $fluid-blue-050;
114+
}
115+
}
116+
}
117+
118+
&.sticky-header {
119+
thead th {
120+
@include position-sticky;
121+
122+
top: 0;
123+
z-index: 101;
124+
125+
&.sticky-first-col {
126+
@include position-sticky;
127+
128+
top: 0;
129+
}
130+
}
131+
}
132+
}
133+
}

desktop/core/src/desktop/js/components/HueTable.vue

Lines changed: 23 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,32 @@
1919
<!-- eslint-disable vue/no-v-html -->
2020
<template>
2121
<div ref="tableContainer" class="hue-table-container" @scroll="onContainerScroll">
22-
<table class="hue-table" :class="{ 'sticky-header': stickyHeader }">
22+
<table
23+
class="hue-table"
24+
:class="{ 'sticky-header': stickyHeader && showHeader, 'header-less': !showHeader }"
25+
>
2326
<caption>
2427
<!-- Because of Web:TableWithoutCaptionCheck -->
2528
{{
2629
caption
2730
}}
2831
</caption>
29-
<thead>
32+
<thead v-if="showHeader">
3033
<tr class="header-row">
3134
<th
3235
v-for="(column, colIndex) in columns"
3336
:key="colIndex"
3437
:class="cellClass(column.headerCssClass, colIndex)"
3538
scope="col"
3639
>
37-
{{ column.label }}
40+
{{ column.label || column.key }}
3841
</th>
3942
<!-- To fill the blank space to the right when table width is smaller than available horizontal space -->
4043
<th class="column-flush" scope="col" />
4144
</tr>
4245
</thead>
43-
<tbody>
44-
<tr v-for="(row, rowIndex) in rows" :key="rowIndex" @click="$emit('row-clicked', row)">
46+
<tbody :class="{ 'clickable-rows': clickableRows }">
47+
<tr v-for="(row, rowIndex) in rows" :key="rowIndex" @click="onRowClick(row)">
4548
<td
4649
v-for="(column, colIndex) in columns"
4750
:key="colIndex"
@@ -64,6 +67,7 @@
6467
<script lang="ts">
6568
import { defineComponent, PropType } from 'vue';
6669
70+
import './HueTable.scss';
6771
import { Column, Row } from './HueTable';
6872
6973
export default defineComponent({
@@ -83,6 +87,11 @@
8387
type: String,
8488
default: undefined
8589
},
90+
showHeader: {
91+
type: Boolean,
92+
required: false,
93+
default: true
94+
},
8695
stickyHeader: {
8796
type: Boolean,
8897
required: false,
@@ -92,6 +101,10 @@
92101
type: Boolean,
93102
required: false,
94103
default: false
104+
},
105+
clickableRows: {
106+
type: Boolean,
107+
default: false
95108
}
96109
},
97110
@@ -101,18 +114,15 @@
101114
hasCellSlot(column: Column<unknown>): boolean {
102115
return !!this.$slots[this.cellSlotName(column)];
103116
},
104-
105117
cellSlotName(column: Column<unknown>): string {
106118
return 'cell-' + column.key;
107119
},
108-
109120
onContainerScroll(): void {
110121
const containerEl = <HTMLElement>this.$refs.tableContainer;
111122
if (containerEl.scrollHeight === containerEl.scrollTop + containerEl.clientHeight) {
112123
this.$emit('scroll-to-end');
113124
}
114125
},
115-
116126
cellClass(cellClass: string | undefined, index: number): string | null {
117127
// This prevents rendering of empty class="" for :class="[x,y]" when x and y are undefined
118128
// Possibly fixed in Vue 3
@@ -122,110 +132,12 @@
122132
return 'sticky-first-col';
123133
}
124134
return cellClass || null;
135+
},
136+
onRowClick(row: Row): void {
137+
if (this.clickableRows) {
138+
this.$emit('row-clicked', row);
139+
}
125140
}
126141
}
127142
});
128143
</script>
129-
130-
<style lang="scss" scoped>
131-
@import './styles/colors';
132-
@import './styles/mixins';
133-
134-
.hue-table-container {
135-
overflow-x: auto;
136-
width: 100%;
137-
margin: 0 0 15px 0;
138-
139-
.hue-table {
140-
line-height: 14px;
141-
table-layout: auto;
142-
border-collapse: separate;
143-
144-
thead,
145-
tbody {
146-
tr {
147-
height: 40px;
148-
149-
th,
150-
td {
151-
@include nowrap-ellipsis;
152-
153-
height: 16px;
154-
max-width: 300px;
155-
padding: 12px;
156-
border-bottom: 1px solid $fluid-gray-300;
157-
text-align: left;
158-
159-
&.column-flush {
160-
width: 100%;
161-
}
162-
}
163-
}
164-
}
165-
166-
thead {
167-
tr {
168-
th {
169-
background-color: $fluid-white;
170-
color: $fluid-gray-700;
171-
font-size: 13px;
172-
font-weight: 500;
173-
white-space: nowrap;
174-
175-
&.sticky-first-col {
176-
background-color: $fluid-white;
177-
position: sticky;
178-
position: -webkit-sticky;
179-
left: 0;
180-
z-index: 102;
181-
}
182-
183-
.sort-header {
184-
display: flex;
185-
cursor: pointer;
186-
align-items: center;
187-
letter-spacing: normal;
188-
outline: 0;
189-
}
190-
}
191-
}
192-
}
193-
194-
tbody {
195-
tr {
196-
td {
197-
color: $fluid-gray-900;
198-
font-size: 14px;
199-
200-
&.sticky-first-col {
201-
@include position-sticky;
202-
203-
background-color: $fluid-white;
204-
left: 0;
205-
z-index: 100;
206-
}
207-
208-
&:last-of-type {
209-
padding-right: 8px;
210-
}
211-
}
212-
}
213-
}
214-
215-
&.sticky-header {
216-
thead th {
217-
@include position-sticky;
218-
219-
top: 0;
220-
z-index: 101;
221-
222-
&.sticky-first-col {
223-
@include position-sticky;
224-
225-
top: 0;
226-
}
227-
}
228-
}
229-
}
230-
}
231-
</style>

0 commit comments

Comments
 (0)