From 645c7ab96755926f4a00dd7270de514ef8c3ae0a Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Fri, 12 Jan 2018 23:23:12 +0200 Subject: [PATCH] Cleaner cell repr, better responsive size styles --- src/components/Cell/Cell.css | 31 +++++++++++ src/components/Cell/Cell.css.d.ts | 3 ++ src/components/Cell/Cell.module.d.ts | 6 ++- src/components/Cell/Cell.tsx | 52 ++++++++++++++----- src/components/DataTable/DataTable.css | 2 + .../DataTable/DataTable.module.d.ts | 2 + src/components/DataTable/DataTable.tsx | 43 ++++++++------- src/components/Header/Header.css | 2 + src/components/Header/Header.module.d.ts | 1 + src/components/Header/Header.tsx | 2 +- src/components/KeyList/KeyList.css | 1 - src/components/KeyList/KeyList.module.d.ts | 1 + src/components/KeyList/KeyList.tsx | 6 ++- src/index.css | 1 - src/layouts/App/App.css | 28 ++++++---- src/layouts/App/App.css.d.ts | 2 + src/layouts/App/App.tsx | 10 ++-- 17 files changed, 142 insertions(+), 51 deletions(-) diff --git a/src/components/Cell/Cell.css b/src/components/Cell/Cell.css index fdad7ab..f83accc 100644 --- a/src/components/Cell/Cell.css +++ b/src/components/Cell/Cell.css @@ -3,3 +3,34 @@ .Cell { /* */ } + + +.pre, .pre-alt { + overflow: hidden; + font-family: monospace; + max-width: 150px; + background: #ddd4; + margin: 4px 3px; + border: 1px solid #aaa; + padding: 4px; +} + +.pre { + overflow-x: auto; + width: max-content; +} + +.pre-alt { + display: inline-block; + vertical-align: top; + width: min-content; +} + +.popover { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; +} + diff --git a/src/components/Cell/Cell.css.d.ts b/src/components/Cell/Cell.css.d.ts index 786930b..a7b8e64 100644 --- a/src/components/Cell/Cell.css.d.ts +++ b/src/components/Cell/Cell.css.d.ts @@ -1,2 +1,5 @@ export const Cell: string; export const cell: string; +export const pre: string; +export const preAlt: string; +export const popover: string; diff --git a/src/components/Cell/Cell.module.d.ts b/src/components/Cell/Cell.module.d.ts index b41cb46..27c725f 100644 --- a/src/components/Cell/Cell.module.d.ts +++ b/src/components/Cell/Cell.module.d.ts @@ -1,7 +1,11 @@ export interface IProps { data: any + depth?: number + className?: string } export interface IState { - // state + tableData: any + depth: number + dataVisible: boolean } diff --git a/src/components/Cell/Cell.tsx b/src/components/Cell/Cell.tsx index 2ace423..03ef64d 100644 --- a/src/components/Cell/Cell.tsx +++ b/src/components/Cell/Cell.tsx @@ -1,12 +1,17 @@ import * as React from 'react' import * as css from './Cell.css' import * as I from './Cell.module' +import DataTable from 'components/DataTable/DataTable' + +const MAX_DEPTH = 5 class Cell extends React.Component { constructor(props: I.IProps) { super(props) this.state = { - // + tableData: props.data, + dataVisible: false, + depth: props.depth || 0, } } @@ -19,15 +24,30 @@ class Cell extends React.Component { ) } - private parse(obj?: any) { + private expandData() { + this.setState({ dataVisible: true }) + } + + private parse() { + const obj = this.props.data + const classNames = this.props.className || '' + + if (this.state.depth >= MAX_DEPTH) { + return ( + + ) + } + if (this.isRepresentable(obj)) { - let str = JSON.stringify(obj).split(`\\`).join('') + let str = JSON.stringify(obj, null, '\t').split(`\\`).join('') const maxLen = 400 + if (str.length > maxLen) { str = str.slice(0, maxLen) + '\u2026' } + return ( - {str} +
{str}
) } @@ -39,19 +59,20 @@ class Cell extends React.Component { if (obj.constructor === Array && (!obj.length || obj[0].constructor === {}.constructor)) { const items = obj.slice(0, 3) return ( - - [{items.map((item, i) => ( - - {this.parse(item)} - +
+ Array[{items.map((item, i) => ( + ))}] - +
) } - const keyList = Object.keys(obj).map(s => `"${s}"`).join(', ') + const keyList = Object.keys(obj).map(s => ( + + )) + return ( -
+
this.expandData()}> Object({keyList})
) @@ -64,7 +85,12 @@ class Cell extends React.Component { return (
- {this.parse(this.props.data)} + {this.parse()} + {this.state.dataVisible ? ( +
+ {/* */} +
+ ) : ''}
) } diff --git a/src/components/DataTable/DataTable.css b/src/components/DataTable/DataTable.css index 007e070..bd0a51a 100644 --- a/src/components/DataTable/DataTable.css +++ b/src/components/DataTable/DataTable.css @@ -10,6 +10,8 @@ & tbody td, & thead th { padding: 12px; + width: max-content; + vertical-align: top; } } diff --git a/src/components/DataTable/DataTable.module.d.ts b/src/components/DataTable/DataTable.module.d.ts index 63c3669..a9d322d 100644 --- a/src/components/DataTable/DataTable.module.d.ts +++ b/src/components/DataTable/DataTable.module.d.ts @@ -1,6 +1,8 @@ export interface Props { store: any className?: string + static?: boolean + data?: any[] } export interface State { diff --git a/src/components/DataTable/DataTable.tsx b/src/components/DataTable/DataTable.tsx index 1995f9f..5d07aa9 100644 --- a/src/components/DataTable/DataTable.tsx +++ b/src/components/DataTable/DataTable.tsx @@ -13,11 +13,15 @@ class DataTable extends React.Component { this.state = { columns: props.store.get(StoreKeys.Columns, []), - data: props.store.get(StoreKeys.Table, []), + data: props.data || props.store.get(StoreKeys.Table, []), } } public componentWillMount() { + if (this.props.static) { + return + } + this.listeners = [ register(ActionTypes.UPDATE_COLUMNS, (columns: any) => { this.setState({ @@ -33,6 +37,10 @@ class DataTable extends React.Component { } public componentWillUnmount() { + if (this.props.static) { + return + } + this.listeners.forEach(l => Dispatcher.unregister(l)) } @@ -88,26 +96,23 @@ class DataTable extends React.Component { return
No data to show!
} - const classNames = [ - css.dataTable, - this.props.className || '' - ].join(' ') - return ( - - - - {this.state.columns.map(col => )} - - - - {this.state.data.map((row, i) => ( - - {this.getColumnRowData(row, i)} +
+
{col}
+ + + {this.state.columns.map(col => )} - ))} - -
{col}
+ + + {this.state.data.map((row, i) => ( + + {this.getColumnRowData(row, i)} + + ))} + + +
) } } diff --git a/src/components/Header/Header.css b/src/components/Header/Header.css index 9ae5c48..41f3c51 100644 --- a/src/components/Header/Header.css +++ b/src/components/Header/Header.css @@ -5,6 +5,8 @@ background-image: linear-gradient(to bottom, white, #f3f3f3 88%, #eee); display: grid; grid-row-gap: 14px; + align-content: stretch; + grid-template-rows: min-content auto; overflow: hidden; } diff --git a/src/components/Header/Header.module.d.ts b/src/components/Header/Header.module.d.ts index 2b4ea50..e9f83e4 100644 --- a/src/components/Header/Header.module.d.ts +++ b/src/components/Header/Header.module.d.ts @@ -1,5 +1,6 @@ export interface IProps { store: any + className?: string } export interface IState { diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 129da98..fb1cd71 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -136,7 +136,7 @@ class Header extends React.Component { render() { return ( -
+
{ } render() { + const classNames = [ + css.KeyList, + this.props.className || '' + ].join(' ') return ( -
+
{this.keyListElements}
) diff --git a/src/index.css b/src/index.css index 154041a..982ff97 100644 --- a/src/index.css +++ b/src/index.css @@ -3,7 +3,6 @@ html, body { font-family: "Helvetica Neue", "Calibri", "Segoe UI", "Arial", sans-serif; font-size: 11pt; - overflow: hidden; } * { diff --git a/src/layouts/App/App.css b/src/layouts/App/App.css index 811ee0f..eed5e03 100644 --- a/src/layouts/App/App.css +++ b/src/layouts/App/App.css @@ -1,24 +1,34 @@ +$header-height: 150px; + .App { position: relative; - width: 100%; - height: 100%; - display: grid; - grid-template-rows: min-content auto; + display: flex; + height: 100vh; + flex-direction: column; +} + +.header { + height: $header-height; } .content { - display: grid; width: 100%; - grid-template-columns: [sidebar] 20vw [main] 80vw; + height: 100%; overflow: auto; + display: grid; + grid-template-columns: [sidebar] 20vw [main] 80vw; +} + +.key-list { + grid-column: sidebar; } .table { - grid-area: main; + grid-column: main; } .scrollable { - max-width: 100%; - max-height: 100%; + width: inherit; + height: inherit; overflow: auto; } diff --git a/src/layouts/App/App.css.d.ts b/src/layouts/App/App.css.d.ts index a5892a0..2261f5a 100644 --- a/src/layouts/App/App.css.d.ts +++ b/src/layouts/App/App.css.d.ts @@ -1,5 +1,7 @@ export const App: string; export const app: string; +export const header: string; export const content: string; +export const keyList: string; export const table: string; export const scrollable: string; diff --git a/src/layouts/App/App.tsx b/src/layouts/App/App.tsx index 5e631b6..9e52de0 100644 --- a/src/layouts/App/App.tsx +++ b/src/layouts/App/App.tsx @@ -38,12 +38,12 @@ class App extends React.Component { render() { return (
-
+
- -
- -
+ +
)