From 75d648adb676b42af3f286c085d3db7719a2a182 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 11 Jun 2020 11:54:31 -0400 Subject: [PATCH] simpler type fixes Signed-off-by: Sebastian Malton --- .../deployment-scale-dialog.tsx | 2 +- .../client/components/chart/bar-chart.tsx | 27 ++++++++++++------- dashboard/client/components/chart/chart.tsx | 5 +--- .../client/components/chart/pie-chart.tsx | 1 - dashboard/client/components/select/select.tsx | 6 ++--- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dashboard/client/components/+workloads-deployments/deployment-scale-dialog.tsx b/dashboard/client/components/+workloads-deployments/deployment-scale-dialog.tsx index 8fbc47cd78..d421f4692e 100644 --- a/dashboard/client/components/+workloads-deployments/deployment-scale-dialog.tsx +++ b/dashboard/client/components/+workloads-deployments/deployment-scale-dialog.tsx @@ -96,7 +96,7 @@ export class DeploymentScaleDialog extends Component { Desired number of replicas: {desiredReplicas}
- +
{warning && diff --git a/dashboard/client/components/chart/bar-chart.tsx b/dashboard/client/components/chart/bar-chart.tsx index 1bc5bd02ff..3e0792b585 100644 --- a/dashboard/client/components/chart/bar-chart.tsx +++ b/dashboard/client/components/chart/bar-chart.tsx @@ -150,7 +150,7 @@ export function BarChart(props: Props) { } }; const options = merge(barOptions, customOptions); - if (!chartData.datasets.length) { + if (chartData.datasets.length == 0) { return } return ( @@ -170,9 +170,17 @@ export const memoryOptions: ChartOptions = { scales: { yAxes: [{ ticks: { - callback: value => { - if (!value) return 0; - return parseFloat(value) < 1 ? value.toFixed(3) : bytesToUnits(parseInt(value)); + callback: (value: number | string): string => { + if (typeof value == "string") { + const float = parseFloat(value); + if (float < 1) { + return float.toFixed(3); + } + + return bytesToUnits(parseInt(value)); + } + + return `${value}`; }, stepSize: 1 } @@ -194,11 +202,12 @@ export const cpuOptions: ChartOptions = { scales: { yAxes: [{ ticks: { - callback: value => { - if (value == 0) return 0; - if (value < 10) return value.toFixed(3); - if (value < 100) return value.toFixed(2); - return value.toFixed(1); + callback: (value: number | string): string => { + const float = parseFloat(`${value}`); + if (float == 0) return "0"; + if (float < 10) return float.toFixed(3); + if (float < 100) return float.toFixed(2); + return float.toFixed(1); } } }] diff --git a/dashboard/client/components/chart/chart.tsx b/dashboard/client/components/chart/chart.tsx index 6678e94f38..ec8037bb3d 100644 --- a/dashboard/client/components/chart/chart.tsx +++ b/dashboard/client/components/chart/chart.tsx @@ -19,10 +19,7 @@ export interface ChartDataSet extends ChartDataSets { } export interface ChartProps { - data: { - labels?: Array; - datasets?: ChartDataSet[]; - }; + data: ChartData; width?: number | string; height?: number | string; options?: ChartOptions; // Passed to ChartJS instance diff --git a/dashboard/client/components/chart/pie-chart.tsx b/dashboard/client/components/chart/pie-chart.tsx index 7187b1a34d..8960bf67f5 100644 --- a/dashboard/client/components/chart/pie-chart.tsx +++ b/dashboard/client/components/chart/pie-chart.tsx @@ -7,7 +7,6 @@ import { cssNames } from "../../utils"; import { themeStore } from "../../theme.store"; interface Props extends ChartProps { - data: ChartData; title?: string; } diff --git a/dashboard/client/components/select/select.tsx b/dashboard/client/components/select/select.tsx index 1603864bc5..e2cd986e69 100644 --- a/dashboard/client/components/select/select.tsx +++ b/dashboard/client/components/select/select.tsx @@ -10,7 +10,7 @@ import ReactSelect, { components as ReactSelectComponents } from "react-select" import { Props as ReactSelectProps } from "react-select/base" import Creatable, { CreatableProps } from "react-select/creatable" import { StylesConfig } from "react-select/src/styles" -import { ActionMeta } from "react-select/src/types" +import { ActionMeta, OptionTypeBase } from "react-select/src/types" import { themeStore } from "../../theme.store"; export { ReactSelectComponents } @@ -31,7 +31,7 @@ export interface SelectProps extends ReactSelectProps, CreatableProp menuClass?: string; isCreatable?: boolean; autoConvertOptions?: boolean; // to internal format (i.e. {value: T, label: string}[]), not working with groups - onChange?(option: T, meta?: ActionMeta): void; + onChange?(option: T, meta?: ActionMeta): void; } @observer @@ -76,7 +76,7 @@ export class Select extends React.Component { } @autobind() - onChange(value: SelectOption, meta: ActionMeta) { + onChange(value: SelectOption, meta: ActionMeta) { if (this.props.onChange) { this.props.onChange(value, meta); }