Skip to content

Commit a1a32d6

Browse files
lorem--ipsumvogievetsky
authored andcommitted
Added data-table to data-cube-edit
1 parent 31de03a commit a1a32d6

File tree

13 files changed

+488
-126
lines changed

13 files changed

+488
-126
lines changed

src/client/components/simple-table/simple-table.tsx

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ require('./simple-table.css');
1818

1919
import * as React from 'react';
2020
import * as ReactDOM from 'react-dom';
21-
import { $, Expression, Executor, Dataset } from 'plywood';
22-
import { Stage, Clicker, Essence, DataCube, Filter, Dimension, Measure } from '../../../common/models/index';
21+
import { } from '../../../common/models/index';
2322

2423
import { classNames } from '../../utils/dom/dom';
2524

26-
import { SvgIcon } from '../svg-icon/svg-icon';
27-
import { Scroller, ScrollerPart } from '../scroller/scroller';
25+
import { SvgIcon, Scroller, ScrollerPart } from '../index';
2826

2927
export interface SimpleTableColumn {
3028
label: string;
3129
field: string | ((row: any) => any);
3230
width: number;
3331
cellIcon?: string;
32+
render?: (column: SimpleTableColumn, hovered: boolean) => JSX.Element;
33+
data?: any;
3434
}
3535

3636
export interface SimpleTableAction {
@@ -44,12 +44,16 @@ export interface SimpleTableProps extends React.Props<any> {
4444
rows: any[];
4545
actions?: SimpleTableAction[];
4646
onRowClick?: (row: any) => void;
47+
onHeaderClick?: (column: SimpleTableColumn) => boolean;
48+
49+
headerHeight?: number;
4750
}
4851

4952
export interface SimpleTableState {
5053
sortColumn?: SimpleTableColumn;
5154
sortAscending?: boolean;
5255
hoveredRowIndex?: number;
56+
hoveredColumnIndex?: number;
5357
hoveredActionIndex?: number;
5458
}
5559

@@ -58,18 +62,32 @@ const HEADER_HEIGHT = 26;
5862
const ACTION_WIDTH = 30;
5963

6064
export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableState> {
65+
static defaultProps = {
66+
actions: [] as SimpleTableAction[],
67+
headerHeight: HEADER_HEIGHT
68+
};
69+
6170
constructor() {
6271
super();
6372

6473
this.state = {};
6574
}
6675

6776
renderHeaders(columns: SimpleTableColumn[], sortColumn: SimpleTableColumn, sortAscending: boolean): JSX.Element {
77+
const { hoveredRowIndex, hoveredColumnIndex } = this.state;
78+
6879
var items: JSX.Element[] = [];
6980

7081
for (let i = 0; i < columns.length; i++) {
7182
let column = columns[i];
7283

84+
let isHovered = hoveredRowIndex === -1 && i === hoveredColumnIndex;
85+
86+
if (column.render) {
87+
items.push(column.render(column, isHovered));
88+
continue;
89+
}
90+
7391
let icon: JSX.Element = null;
7492
if (sortColumn && sortColumn === column) {
7593
icon = <SvgIcon
@@ -79,7 +97,7 @@ export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableSt
7997
}
8098

8199
items.push(<div
82-
className="header"
100+
className={classNames("header", {hover: isHovered})}
83101
style={{width: column.width}}
84102
key={`column-${i}`}
85103
>{column.label}{icon}</div>);
@@ -186,6 +204,8 @@ export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableSt
186204
getLayout(columns: SimpleTableColumn[], rows: any[], actions: SimpleTableAction[]) {
187205
const width = columns.reduce((a, b) => a + b.width, 0);
188206

207+
actions = actions || [];
208+
189209
const directActionsCount = actions.filter((a) => !a.inEllipsis).length;
190210
const indirectActionsCount = directActionsCount !== actions.length ? 1 : 0;
191211

@@ -195,7 +215,7 @@ export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableSt
195215
bodyHeight: rows.length * ROW_HEIGHT,
196216

197217
// Gutters
198-
top: HEADER_HEIGHT,
218+
top: this.props.headerHeight,
199219
right: directActionsCount * 30 + indirectActionsCount * 30,
200220
bottom: 0,
201221
left: 0
@@ -240,8 +260,8 @@ export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableSt
240260
var rowIndex = -1; // -1 means header
241261

242262
// Not in the header
243-
if (y > HEADER_HEIGHT) {
244-
rowIndex = Math.floor((y - HEADER_HEIGHT) / ROW_HEIGHT);
263+
if (y > this.props.headerHeight) {
264+
rowIndex = Math.floor((y - this.props.headerHeight) / ROW_HEIGHT);
245265
}
246266

247267
return rowIndex;
@@ -302,6 +322,11 @@ export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableSt
302322
}
303323

304324
onHeaderClick(column: SimpleTableColumn) {
325+
if (this.props.onHeaderClick) {
326+
let shouldSort = this.props.onHeaderClick(column);
327+
if (!shouldSort) return;
328+
}
329+
305330
this.setState({
306331
sortColumn: column,
307332
sortAscending: this.state.sortColumn === column ? !this.state.sortAscending : true
@@ -317,8 +342,10 @@ export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableSt
317342
const headerWidth = this.getHeaderWidth(columns);
318343

319344
var rowIndex = this.getRowIndex(y);
345+
var columnIndex = this.getColumnIndex(x, headerWidth);
320346

321347
this.setState({
348+
hoveredColumnIndex: columnIndex,
322349
hoveredRowIndex: rowIndex > rows.length ? undefined : rowIndex,
323350
hoveredActionIndex: part === Scroller.RIGHT_GUTTER ? this.getActionIndex(x, headerWidth) : undefined
324351
});
@@ -327,6 +354,7 @@ export class SimpleTable extends React.Component<SimpleTableProps, SimpleTableSt
327354
onMouseLeave() {
328355
this.setState({
329356
hoveredRowIndex: undefined,
357+
hoveredColumnIndex: undefined,
330358
hoveredActionIndex: undefined
331359
});
332360
}

src/client/config/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const SEARCH_WAIT = 900;
4242
// Do not set an explicit type for STRINGS, let typescript figure it out and type check that we are using string correctly
4343
export const STRINGS = {
4444
add: 'Add',
45+
addAttributes: 'Add attributes',
4546
addFromCube: 'Add from Cube',
4647
addNewCollection: 'Add new collection',
4748
addNewTile: 'Add new tile',
@@ -89,6 +90,7 @@ export const STRINGS = {
8990
explore: 'Explore',
9091
exportToCSV: 'Export to CSV',
9192
filter: 'Filter',
93+
filters: 'Filters',
9294
generalSettings: 'General settings',
9395
goToUrl: 'Go to URL',
9496
granularity: 'Granularity',
@@ -135,6 +137,7 @@ export const STRINGS = {
135137
stringSearch: 'String search',
136138
subsplit: 'Split',
137139
suggestion: 'suggestion',
140+
suggestions: 'suggestions',
138141
timezone: 'Timezone',
139142
thereAreNoSuggestionsAtTheMoment: 'There are no suggestions at the moment',
140143
undo: 'Click here to undo',
Lines changed: 12 additions & 0 deletions
Loading

src/client/modals/attribute-modal/attribute-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717

18-
import { STRINGS } from "../../config/constants";
1918
require('./attribute-modal.css');
2019

20+
import { STRINGS } from "../../config/constants";
2121
import * as React from 'react';
2222
import { AttributeInfo } from 'plywood';
2323

src/client/utils/styles/_variables.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ $danger: #e24c4c;
2929
// Colors -------------------
3030

3131
$brand: hsl(200, 80%, 51%);
32-
$dark: #004584;
32+
$brand-dark: #004584;
33+
$dark: $brand-dark;
3334

3435
$error: hsla(0, 72%, 59%, 1.00);
3536

src/client/views/settings-view/_layout.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
@include unpin-top($header-height);
8383
left: $left-panel-width;
8484
background-color: $white;
85+
86+
&.full-width {
87+
left: 0;
88+
}
8589
}
8690

8791
.title-bar {

src/client/views/settings-view/data-cube-edit/data-cube-edit.scss

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,39 @@
3333

3434
padding: 10px 5px;
3535

36-
button,
37-
.button {
38-
@extend %button-light;
39-
36+
button {
37+
background-color: transparent;
4038
display: block;
4139
width: 100%;
42-
padding: 10px 15px;
40+
height: 35px;
4341
text-align: left;
42+
color: $text-medium;
43+
44+
&.icon {
45+
padding-left: 38px;
46+
47+
.svg-icon {
48+
position: absolute;
49+
top: 8px;
50+
left: 12px;
51+
52+
path {
53+
fill: hsla(0, 0%, 75%, 1.00);
54+
}
55+
}
56+
}
57+
58+
&:hover {
59+
background-color: hsla(200, 73%, 93%, 1.00);
60+
}
61+
62+
&:active, &.active {
63+
background-color: hsla(200, 73%, 93%, 1.00);
64+
65+
.svg-icon path {
66+
fill: $brand;
67+
}
68+
}
4469
}
4570
}
4671

@@ -65,6 +90,13 @@
6590
}
6691
}
6792

93+
.data-table {
94+
position: absolute;
95+
top: 20px;
96+
left: 20px;
97+
right: 20px;
98+
bottom: 20px;
99+
}
68100

69101
}
70102
}

0 commit comments

Comments
 (0)