mirror of
https://github.com/apache/superset.git
synced 2026-04-27 20:14:54 +00:00
chore(superset-ui): clean up legacy-plugin-chart-time-table (#17626)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable class-methods-use-this */
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
@@ -17,7 +18,6 @@
|
||||
* under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {
|
||||
Sparkline,
|
||||
LineSeries,
|
||||
@@ -28,29 +28,30 @@ import {
|
||||
} from '@data-ui/sparkline';
|
||||
import { getTextDimension, formatNumber } from '@superset-ui/core';
|
||||
|
||||
const propTypes = {
|
||||
className: PropTypes.string,
|
||||
width: PropTypes.number,
|
||||
height: PropTypes.number,
|
||||
data: PropTypes.array.isRequired,
|
||||
ariaLabel: PropTypes.string,
|
||||
numberFormat: PropTypes.string,
|
||||
yAxisBounds: PropTypes.array,
|
||||
showYAxis: PropTypes.bool,
|
||||
renderTooltip: PropTypes.func,
|
||||
};
|
||||
const defaultProps = {
|
||||
className: '',
|
||||
width: 300,
|
||||
height: 50,
|
||||
ariaLabel: '',
|
||||
numberFormat: undefined,
|
||||
yAxisBounds: [null, null],
|
||||
showYAxis: false,
|
||||
renderTooltip() {
|
||||
return <div />;
|
||||
},
|
||||
};
|
||||
interface Props {
|
||||
ariaLabel: string;
|
||||
className?: string;
|
||||
height: number;
|
||||
numberFormat: string;
|
||||
renderTooltip: ({ index }: { index: number }) => void;
|
||||
showYAxis: boolean;
|
||||
width: number;
|
||||
yAxisBounds: Array<number>;
|
||||
data: Array<number>;
|
||||
}
|
||||
|
||||
interface TooltipProps {
|
||||
onMouseLeave: () => void;
|
||||
onMouseMove: () => void;
|
||||
tooltipData: {
|
||||
index: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface Yscale {
|
||||
min?: number;
|
||||
max?: number;
|
||||
}
|
||||
|
||||
const MARGIN = {
|
||||
top: 8,
|
||||
@@ -65,7 +66,7 @@ const tooltipProps = {
|
||||
offsetTop: 0,
|
||||
};
|
||||
|
||||
function getSparklineTextWidth(text) {
|
||||
function getSparklineTextWidth(text: string) {
|
||||
return (
|
||||
getTextDimension({
|
||||
text,
|
||||
@@ -78,7 +79,7 @@ function getSparklineTextWidth(text) {
|
||||
);
|
||||
}
|
||||
|
||||
function isValidBoundValue(value) {
|
||||
function isValidBoundValue(value?: number | string) {
|
||||
return (
|
||||
value !== null &&
|
||||
value !== undefined &&
|
||||
@@ -87,8 +88,8 @@ function isValidBoundValue(value) {
|
||||
);
|
||||
}
|
||||
|
||||
class SparklineCell extends React.Component {
|
||||
renderHorizontalReferenceLine(value, label) {
|
||||
class SparklineCell extends React.Component<Props, {}> {
|
||||
renderHorizontalReferenceLine(value?: number, label?: string) {
|
||||
return (
|
||||
<HorizontalReferenceLine
|
||||
reference={value}
|
||||
@@ -103,17 +104,17 @@ class SparklineCell extends React.Component {
|
||||
|
||||
render() {
|
||||
const {
|
||||
width,
|
||||
height,
|
||||
width = 300,
|
||||
height = 50,
|
||||
data,
|
||||
ariaLabel,
|
||||
numberFormat,
|
||||
yAxisBounds,
|
||||
showYAxis,
|
||||
renderTooltip,
|
||||
numberFormat = undefined,
|
||||
yAxisBounds = [undefined, undefined],
|
||||
showYAxis = false,
|
||||
renderTooltip = () => <div />,
|
||||
} = this.props;
|
||||
|
||||
const yScale = {};
|
||||
const yScale: Yscale = {};
|
||||
let hasMinBound = false;
|
||||
let hasMaxBound = false;
|
||||
|
||||
@@ -129,10 +130,10 @@ class SparklineCell extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
let min;
|
||||
let max;
|
||||
let minLabel;
|
||||
let maxLabel;
|
||||
let min: number | undefined;
|
||||
let max: number | undefined;
|
||||
let minLabel: string;
|
||||
let maxLabel: string;
|
||||
let labelLength = 0;
|
||||
if (showYAxis) {
|
||||
const [minBound, maxBound] = yAxisBounds;
|
||||
@@ -162,7 +163,7 @@ class SparklineCell extends React.Component {
|
||||
hoverStyles={null}
|
||||
renderTooltip={renderTooltip}
|
||||
>
|
||||
{({ onMouseLeave, onMouseMove, tooltipData }) => (
|
||||
{({ onMouseLeave, onMouseMove, tooltipData }: TooltipProps) => (
|
||||
<Sparkline
|
||||
ariaLabel={ariaLabel}
|
||||
width={width}
|
||||
@@ -197,7 +198,4 @@ class SparklineCell extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
SparklineCell.propTypes = propTypes;
|
||||
SparklineCell.defaultProps = defaultProps;
|
||||
|
||||
export default SparklineCell;
|
||||
@@ -16,7 +16,31 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
export default function transformProps(chartProps) {
|
||||
import { ChartProps, DataRecord, Metric } from '@superset-ui/core';
|
||||
|
||||
interface FormData {
|
||||
groupby: string[];
|
||||
metrics: Array<object>;
|
||||
url: string;
|
||||
columnCollection: Array<object> | [];
|
||||
}
|
||||
|
||||
interface QueryData {
|
||||
data: {
|
||||
records: DataRecord[];
|
||||
columns: string[];
|
||||
};
|
||||
}
|
||||
|
||||
export type TableChartProps = ChartProps & {
|
||||
formData: FormData;
|
||||
queriesData: QueryData[];
|
||||
};
|
||||
|
||||
interface ColumnData {
|
||||
timeLag?: string | number;
|
||||
}
|
||||
export default function transformProps(chartProps: TableChartProps) {
|
||||
const { height, datasource, formData, queriesData } = chartProps;
|
||||
const { columnCollection = [], groupby, metrics, url } = formData;
|
||||
const { records, columns } = queriesData[0].data;
|
||||
@@ -24,8 +48,7 @@ export default function transformProps(chartProps) {
|
||||
|
||||
// When there is a "group by",
|
||||
// each row in the table is a database column
|
||||
// Otherwise,
|
||||
// each row in the table is a metric
|
||||
// Otherwise each row in the table is a metric
|
||||
let rows;
|
||||
if (isGroupBy) {
|
||||
rows = columns.map(column =>
|
||||
@@ -36,8 +59,7 @@ export default function transformProps(chartProps) {
|
||||
const map = acc;
|
||||
map[current.metric_name] = current;
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
}, {} as Record<string, Metric>);
|
||||
rows = metrics.map(metric =>
|
||||
typeof metric === 'object' ? metric : metricMap[metric],
|
||||
);
|
||||
@@ -45,8 +67,8 @@ export default function transformProps(chartProps) {
|
||||
|
||||
// TODO: Better parse this from controls instead of mutative value here.
|
||||
columnCollection.forEach(column => {
|
||||
const c = column;
|
||||
if (c.timeLag !== undefined && c.timeLag !== null && c.timeLag !== '') {
|
||||
const c: ColumnData = column;
|
||||
if (typeof c.timeLag === 'string' && c.timeLag) {
|
||||
c.timeLag = parseInt(c.timeLag, 10);
|
||||
}
|
||||
});
|
||||
19
superset-frontend/src/visualizations/TimeTable/types.d.ts
vendored
Normal file
19
superset-frontend/src/visualizations/TimeTable/types.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
declare module '@data-ui/sparkline';
|
||||
Reference in New Issue
Block a user