WIP table typing
parent
d21b6e7f71
commit
7f9beb140c
|
@ -26,8 +26,7 @@ interface SortedLabel {
|
||||||
interface TransformTableDataReturnType {
|
interface TransformTableDataReturnType {
|
||||||
transformedData: DbData[][]
|
transformedData: DbData[][]
|
||||||
sortedTimeVals: DbData[]
|
sortedTimeVals: DbData[]
|
||||||
columnWidths: {[x: string]: number}
|
columnWidths: ColumnWidths
|
||||||
totalWidths: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const calculateTimeColumnWidth = (timeFormat: string): number => {
|
const calculateTimeColumnWidth = (timeFormat: string): number => {
|
||||||
|
@ -225,7 +224,7 @@ export const transformTableData = (
|
||||||
const filteredData = filterTableColumns(sortedData, fieldOptions)
|
const filteredData = filterTableColumns(sortedData, fieldOptions)
|
||||||
const orderedData = orderTableColumns(filteredData, fieldOptions)
|
const orderedData = orderTableColumns(filteredData, fieldOptions)
|
||||||
const transformedData = verticalTimeAxis ? orderedData : _.unzip(orderedData)
|
const transformedData = verticalTimeAxis ? orderedData : _.unzip(orderedData)
|
||||||
const {widths: columnWidths, totalWidths} = calculateColumnWidths(
|
const columnWidths = calculateColumnWidths(
|
||||||
transformedData,
|
transformedData,
|
||||||
fieldOptions,
|
fieldOptions,
|
||||||
timeFormat,
|
timeFormat,
|
||||||
|
@ -233,5 +232,5 @@ export const transformTableData = (
|
||||||
decimalPlaces
|
decimalPlaces
|
||||||
)
|
)
|
||||||
|
|
||||||
return {transformedData, sortedTimeVals, columnWidths, totalWidths}
|
return {transformedData, sortedTimeVals, columnWidths}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,12 @@ import {
|
||||||
DbData,
|
DbData,
|
||||||
} from 'src/types/dashboard'
|
} from 'src/types/dashboard'
|
||||||
|
|
||||||
|
interface Label {
|
||||||
|
label: string
|
||||||
|
seriesIndex: number
|
||||||
|
responseIndex: number
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: TimeSeriesServerResponse
|
data: TimeSeriesServerResponse
|
||||||
tableOptions: TableOptions
|
tableOptions: TableOptions
|
||||||
|
@ -54,8 +60,8 @@ interface Props {
|
||||||
interface State {
|
interface State {
|
||||||
data: DbData[][]
|
data: DbData[][]
|
||||||
transformedData: DbData[][]
|
transformedData: DbData[][]
|
||||||
sortedTimeVals: number[]
|
sortedTimeVals: DbData[]
|
||||||
sortedLabels: string[]
|
sortedLabels: Label[]
|
||||||
hoveredColumnIndex: number
|
hoveredColumnIndex: number
|
||||||
hoveredRowIndex: number
|
hoveredRowIndex: number
|
||||||
timeColumnWidth: number
|
timeColumnWidth: number
|
||||||
|
@ -76,9 +82,9 @@ class TableGraph extends Component<Props, State> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
const sortField = _.get(
|
const sortField: string = _.get(
|
||||||
this.props,
|
this.props,
|
||||||
['tableOptions', 'sortBy', 'internalName'],
|
'tableOptions.sortBy.internalName',
|
||||||
DEFAULT_TIME_FIELD.internalName
|
DEFAULT_TIME_FIELD.internalName
|
||||||
)
|
)
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -174,12 +180,13 @@ class TableGraph extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount() {
|
public componentDidMount() {
|
||||||
const sortField = _.get(
|
const sortField: string = _.get(
|
||||||
this.props,
|
this.props,
|
||||||
['tableOptions', 'sortBy', 'internalName'],
|
['tableOptions', 'sortBy', 'internalName'],
|
||||||
DEFAULT_TIME_FIELD.internalName
|
DEFAULT_TIME_FIELD.internalName
|
||||||
)
|
)
|
||||||
const sort = {field: sortField, direction: DEFAULT_SORT_DIRECTION}
|
|
||||||
|
const sort: Sort = {field: sortField, direction: DEFAULT_SORT_DIRECTION}
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
tableOptions,
|
tableOptions,
|
||||||
|
@ -195,13 +202,7 @@ class TableGraph extends Component<Props, State> {
|
||||||
if (!_.isEqual(computedFieldOptions, fieldOptions)) {
|
if (!_.isEqual(computedFieldOptions, fieldOptions)) {
|
||||||
this.handleUpdateFieldOptions(computedFieldOptions)
|
this.handleUpdateFieldOptions(computedFieldOptions)
|
||||||
}
|
}
|
||||||
|
const {transformedData, sortedTimeVals, columnWidths} = transformTableData(
|
||||||
const {
|
|
||||||
transformedData,
|
|
||||||
sortedTimeVals,
|
|
||||||
columnWidths,
|
|
||||||
totalWidths,
|
|
||||||
} = transformTableData(
|
|
||||||
result.data,
|
result.data,
|
||||||
sort,
|
sort,
|
||||||
computedFieldOptions,
|
computedFieldOptions,
|
||||||
|
@ -219,7 +220,7 @@ class TableGraph extends Component<Props, State> {
|
||||||
this.setState({
|
this.setState({
|
||||||
transformedData,
|
transformedData,
|
||||||
sortedTimeVals,
|
sortedTimeVals,
|
||||||
columnWidths,
|
columnWidths: columnWidths.widths,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
sortedLabels,
|
sortedLabels,
|
||||||
totalColumnWidths: totalWidths,
|
totalColumnWidths: totalWidths,
|
||||||
|
|
|
@ -4,11 +4,36 @@ import {map, reduce, forEach, concat, clone} from 'fast.js'
|
||||||
import {TimeSeriesServerResponse} from 'src/types/series'
|
import {TimeSeriesServerResponse} from 'src/types/series'
|
||||||
import {DbData} from '../types/dashboard'
|
import {DbData} from '../types/dashboard'
|
||||||
|
|
||||||
// interface Results {}
|
interface Result {
|
||||||
// interface Serieses {}
|
statement_id: number
|
||||||
// interface Cells {}
|
series: Series[]
|
||||||
// interface sortedLabels {}
|
responseIndex: number
|
||||||
// interface seriesLabels {}
|
isGroupBy: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Series {
|
||||||
|
name: string
|
||||||
|
columns: string[]
|
||||||
|
values: DbData[][]
|
||||||
|
isGroupBy: boolean
|
||||||
|
responseIndex: number
|
||||||
|
seriesIndex: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Cells {
|
||||||
|
isGroupBy: boolean[]
|
||||||
|
seriesIndex: number[]
|
||||||
|
responseIndex: number[]
|
||||||
|
label: string[]
|
||||||
|
value: DbData[]
|
||||||
|
time: DbData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Label {
|
||||||
|
label: string
|
||||||
|
seriesIndex: number
|
||||||
|
responseIndex: number
|
||||||
|
}
|
||||||
|
|
||||||
const flattenGroupBySeries = (results, responseIndex, tags) => {
|
const flattenGroupBySeries = (results, responseIndex, tags) => {
|
||||||
if (_.isEmpty(results)) {
|
if (_.isEmpty(results)) {
|
||||||
|
@ -50,7 +75,10 @@ const flattenGroupBySeries = (results, responseIndex, tags) => {
|
||||||
return flattenedSeries
|
return flattenedSeries
|
||||||
}
|
}
|
||||||
|
|
||||||
const constructResults = (raw: TimeSeriesServerResponse, isTable: boolean) => {
|
const constructResults = (
|
||||||
|
raw: TimeSeriesServerResponse,
|
||||||
|
isTable: boolean
|
||||||
|
): Result[] => {
|
||||||
return _.flatten(
|
return _.flatten(
|
||||||
map(raw, (response, index) => {
|
map(raw, (response, index) => {
|
||||||
const results = _.get(response, 'response.results', [])
|
const results = _.get(response, 'response.results', [])
|
||||||
|
@ -73,7 +101,7 @@ const constructResults = (raw: TimeSeriesServerResponse, isTable: boolean) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const constructSerieses = results => {
|
const constructSerieses = (results: Result[]): Series[] => {
|
||||||
return reduce(
|
return reduce(
|
||||||
results,
|
results,
|
||||||
(acc, {series = [], responseIndex}) => {
|
(acc, {series = [], responseIndex}) => {
|
||||||
|
@ -90,7 +118,9 @@ const constructSerieses = results => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const constructCells = serieses => {
|
const constructCells = (
|
||||||
|
serieses: Series[]
|
||||||
|
): {cells: Cells; sortedLabels: Label[]; seriesLabels: Label[]} => {
|
||||||
let cellIndex = 0
|
let cellIndex = 0
|
||||||
let labels = []
|
let labels = []
|
||||||
const seriesLabels = []
|
const seriesLabels = []
|
||||||
|
@ -168,10 +198,10 @@ const constructCells = serieses => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertGroupByValues = (
|
const insertGroupByValues = (
|
||||||
serieses,
|
serieses: Series[],
|
||||||
seriesLabels,
|
seriesLabels: Label[],
|
||||||
labelsToValueIndex,
|
labelsToValueIndex: {[x: string]: number},
|
||||||
sortedLabels
|
sortedLabels: Label[]
|
||||||
) => {
|
) => {
|
||||||
const dashArray = Array(sortedLabels.length).fill('-')
|
const dashArray = Array(sortedLabels.length).fill('-')
|
||||||
const timeSeries = []
|
const timeSeries = []
|
||||||
|
@ -263,11 +293,10 @@ const constructTimeSeries = (serieses, cells, sortedLabels, seriesLabels) => {
|
||||||
export const groupByTimeSeriesTransform = (
|
export const groupByTimeSeriesTransform = (
|
||||||
raw: TimeSeriesServerResponse,
|
raw: TimeSeriesServerResponse,
|
||||||
isTable: boolean
|
isTable: boolean
|
||||||
): {sortedLabels: string[]; sortedTimeSeries: DbData[][]} => {
|
): {sortedLabels: Label[]; sortedTimeSeries: DbData[][]} => {
|
||||||
const results = constructResults(raw, isTable)
|
const results = constructResults(raw, isTable)
|
||||||
const serieses = constructSerieses(results)
|
const serieses = constructSerieses(results)
|
||||||
const {cells, sortedLabels, seriesLabels} = constructCells(serieses)
|
const {cells, sortedLabels, seriesLabels} = constructCells(serieses)
|
||||||
|
|
||||||
const sortedTimeSeries = constructTimeSeries(
|
const sortedTimeSeries = constructTimeSeries(
|
||||||
serieses,
|
serieses,
|
||||||
cells,
|
cells,
|
||||||
|
|
|
@ -2,11 +2,40 @@ import {map, reduce} from 'fast.js'
|
||||||
import {groupByTimeSeriesTransform} from 'src/utils/groupByTimeSeriesTransform'
|
import {groupByTimeSeriesTransform} from 'src/utils/groupByTimeSeriesTransform'
|
||||||
|
|
||||||
import {TimeSeriesServerResponse} from 'src/types/series'
|
import {TimeSeriesServerResponse} from 'src/types/series'
|
||||||
|
import {DbData} from '../types/dashboard'
|
||||||
|
|
||||||
|
interface Label {
|
||||||
|
label: string
|
||||||
|
seriesIndex: number
|
||||||
|
responseIndex: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TimeSeries {
|
||||||
|
time: DbData[]
|
||||||
|
values: DbData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TimeSeriesToDyGraphReturnType {
|
||||||
|
labels: string[]
|
||||||
|
timeSeries: TimeSeries[]
|
||||||
|
dygraphSeries: DygraphSeries
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TimeSeriesToTableGraphReturnType {
|
||||||
|
data: DbData[][]
|
||||||
|
sortedLabels: Label[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DygraphSeries {
|
||||||
|
[x: string]: {
|
||||||
|
axis: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const timeSeriesToDygraph = (
|
export const timeSeriesToDygraph = (
|
||||||
raw: TimeSeriesServerResponse,
|
raw: TimeSeriesServerResponse,
|
||||||
isInDataExplorer: boolean
|
isInDataExplorer: boolean
|
||||||
) => {
|
): TimeSeriesToDyGraphReturnType => {
|
||||||
const isTable = false
|
const isTable = false
|
||||||
const {sortedLabels, sortedTimeSeries} = groupByTimeSeriesTransform(
|
const {sortedLabels, sortedTimeSeries} = groupByTimeSeriesTransform(
|
||||||
raw,
|
raw,
|
||||||
|
@ -25,7 +54,6 @@ export const timeSeriesToDygraph = (
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
labels: ['time', ...map(sortedLabels, ({label}) => label)],
|
labels: ['time', ...map(sortedLabels, ({label}) => label)],
|
||||||
timeSeries: map(sortedTimeSeries, ({time, values}) => [
|
timeSeries: map(sortedTimeSeries, ({time, values}) => [
|
||||||
|
@ -36,7 +64,9 @@ export const timeSeriesToDygraph = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const timeSeriesToTableGraph = (raw: TimeSeriesServerResponse) => {
|
export const timeSeriesToTableGraph = (
|
||||||
|
raw: TimeSeriesServerResponse
|
||||||
|
): TimeSeriesToTableGraphReturnType => {
|
||||||
const isTable = true
|
const isTable = true
|
||||||
const {sortedLabels, sortedTimeSeries} = groupByTimeSeriesTransform(
|
const {sortedLabels, sortedTimeSeries} = groupByTimeSeriesTransform(
|
||||||
raw,
|
raw,
|
||||||
|
|
Loading…
Reference in New Issue