mirror of https://github.com/buster-so/buster.git
make a chart card
This commit is contained in:
parent
679295cff8
commit
af5e599dab
|
@ -1,6 +1,6 @@
|
||||||
import type { IBusterMetricChartConfig } from './requireInterfaces';
|
import type { IBusterMetricChartConfig } from './requireInterfaces';
|
||||||
import type { ColumnSettings } from '../../../components/charts/interfaces/columnInterfaces';
|
import type { ColumnSettings } from '../../../components/charts/interfaces/columnInterfaces';
|
||||||
import { ChartType, ViewType } from '../../../components/charts/interfaces/enum';
|
import { ChartType } from '../../../components/charts/interfaces/enum';
|
||||||
import { DEFAULT_CHART_THEME } from '../../../components/charts/configColors';
|
import { DEFAULT_CHART_THEME } from '../../../components/charts/configColors';
|
||||||
import type { ColumnLabelFormat } from '../../../components/charts/interfaces/columnLabelInterfaces';
|
import type { ColumnLabelFormat } from '../../../components/charts/interfaces/columnLabelInterfaces';
|
||||||
import type { ColumnMetaData } from './interfaces';
|
import type { ColumnMetaData } from './interfaces';
|
||||||
|
@ -8,7 +8,6 @@ import type { ColumnMetaData } from './interfaces';
|
||||||
export const DEFAULT_CHART_CONFIG: IBusterMetricChartConfig = {
|
export const DEFAULT_CHART_CONFIG: IBusterMetricChartConfig = {
|
||||||
colors: DEFAULT_CHART_THEME,
|
colors: DEFAULT_CHART_THEME,
|
||||||
selectedChartType: ChartType.Table,
|
selectedChartType: ChartType.Table,
|
||||||
selectedView: ViewType.Table,
|
|
||||||
yAxisShowAxisLabel: true,
|
yAxisShowAxisLabel: true,
|
||||||
yAxisShowAxisTitle: true,
|
yAxisShowAxisTitle: true,
|
||||||
yAxisAxisTitle: null,
|
yAxisAxisTitle: null,
|
||||||
|
|
|
@ -40,7 +40,7 @@ export const MetricChartEvaluation: React.FC<{
|
||||||
className={cx(
|
className={cx(
|
||||||
styles.container,
|
styles.container,
|
||||||
colorClass,
|
colorClass,
|
||||||
'flex items-center gap-1 rounded-lg px-2 py-1'
|
'flex items-center gap-1 rounded-lg px-2 py-1 hover:shadow-sm'
|
||||||
)}>
|
)}>
|
||||||
{icon}
|
{icon}
|
||||||
{text}
|
{text}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { createStyles } from 'antd-style';
|
import { createStyles } from 'antd-style';
|
||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { MetricViewChartContent } from './MetricViewChartContent';
|
import { MetricViewChartContent } from './MetricViewChartContent';
|
||||||
import { MetricViewChartHeader } from './MetricViewChartHeader';
|
import { MetricViewChartHeader } from './MetricViewChartHeader';
|
||||||
import { useBusterMetricIndividual, useBusterMetricsContextSelector } from '@/context/Metrics';
|
import { useBusterMetricIndividual, useBusterMetricsContextSelector } from '@/context/Metrics';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { inputHasText } from '@/utils/text';
|
import { inputHasText } from '@/utils/text';
|
||||||
import { MetricChartEvaluation } from './MetricChartEvaluation';
|
import { MetricChartEvaluation } from './MetricChartEvaluation';
|
||||||
|
import { ChartType } from '@/components/charts/interfaces/enum';
|
||||||
|
|
||||||
export const MetricViewChart: React.FC<{
|
export const MetricViewChart: React.FC<{
|
||||||
metricId: string;
|
metricId: string;
|
||||||
|
@ -14,6 +15,16 @@ export const MetricViewChart: React.FC<{
|
||||||
const onUpdateMetric = useBusterMetricsContextSelector((x) => x.onUpdateMetric);
|
const onUpdateMetric = useBusterMetricsContextSelector((x) => x.onUpdateMetric);
|
||||||
const { metric, metricData } = useBusterMetricIndividual({ metricId });
|
const { metric, metricData } = useBusterMetricIndividual({ metricId });
|
||||||
const { title, description, time_frame, evaluation_score, evaluation_summary } = metric;
|
const { title, description, time_frame, evaluation_score, evaluation_summary } = metric;
|
||||||
|
const isTable = metric.chart_config.selectedChartType === ChartType.Table;
|
||||||
|
|
||||||
|
const loadingData = !metricData.fetched;
|
||||||
|
const errorData = !!metricData.error;
|
||||||
|
|
||||||
|
const cardClass = useMemo(() => {
|
||||||
|
if (loadingData || errorData) return 'h-full max-h-[600px]';
|
||||||
|
if (isTable) return '';
|
||||||
|
return 'h-full max-h-[600px]';
|
||||||
|
}, [isTable, loadingData, errorData]);
|
||||||
|
|
||||||
const onSetTitle = useMemoizedFn((title: string) => {
|
const onSetTitle = useMemoizedFn((title: string) => {
|
||||||
if (inputHasText(title)) {
|
if (inputHasText(title)) {
|
||||||
|
@ -24,8 +35,13 @@ export const MetricViewChart: React.FC<{
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cx(styles.container, 'm-5 flex h-full flex-col justify-between')}>
|
<div
|
||||||
<div className={cx(styles.chartCard, 'flex flex-col')}>
|
className={cx(
|
||||||
|
styles.container,
|
||||||
|
'm-5 flex h-full flex-col justify-between space-y-3.5',
|
||||||
|
'overflow-hidden'
|
||||||
|
)}>
|
||||||
|
<div className={cx(styles.chartCard, cardClass, 'flex flex-col')}>
|
||||||
<MetricViewChartHeader
|
<MetricViewChartHeader
|
||||||
className="px-4"
|
className="px-4"
|
||||||
title={title}
|
title={title}
|
||||||
|
@ -35,7 +51,6 @@ export const MetricViewChart: React.FC<{
|
||||||
/>
|
/>
|
||||||
<div className={cx(styles.divider)} />
|
<div className={cx(styles.divider)} />
|
||||||
<MetricViewChartContent
|
<MetricViewChartContent
|
||||||
className="px-4"
|
|
||||||
chartConfig={metric.chart_config}
|
chartConfig={metric.chart_config}
|
||||||
metricData={metricData.data}
|
metricData={metricData.data}
|
||||||
dataMetadata={metricData.data_metadata}
|
dataMetadata={metricData.data_metadata}
|
||||||
|
@ -60,6 +75,7 @@ const useStyles = createStyles(({ css, token }) => ({
|
||||||
border-radius: ${token.borderRadiusLG}px;
|
border-radius: ${token.borderRadiusLG}px;
|
||||||
border: 0.5px solid ${token.colorBorder};
|
border: 0.5px solid ${token.colorBorder};
|
||||||
background-color: ${token.colorBgContainer};
|
background-color: ${token.colorBgContainer};
|
||||||
|
overflow: hidden;
|
||||||
`,
|
`,
|
||||||
divider: css`
|
divider: css`
|
||||||
border-bottom: 0.5px solid ${token.colorBorder};
|
border-bottom: 0.5px solid ${token.colorBorder};
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import type { DataMetadata } from '@/api/asset_interfaces';
|
import type { DataMetadata } from '@/api/asset_interfaces';
|
||||||
|
import { BusterChart, ChartType } from '@/components/charts';
|
||||||
import type { BusterMetricData, IBusterMetric } from '@/context/Metrics';
|
import type { BusterMetricData, IBusterMetric } from '@/context/Metrics';
|
||||||
import { createStyles } from 'antd-style';
|
import { createStyles } from 'antd-style';
|
||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
|
||||||
interface MetricViewChartContentProps {
|
interface MetricViewChartContentProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
|
@ -13,9 +14,27 @@ interface MetricViewChartContentProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MetricViewChartContent: React.FC<MetricViewChartContentProps> = React.memo(
|
export const MetricViewChartContent: React.FC<MetricViewChartContentProps> = React.memo(
|
||||||
({ className, chartConfig, metricData, dataMetadata, fetchedData, errorMessage }) => {
|
({ className, chartConfig, metricData = null, dataMetadata, fetchedData, errorMessage }) => {
|
||||||
const { styles, cx } = useStyles();
|
const { styles, cx } = useStyles();
|
||||||
return <div className={cx('flex flex-col py-4', className)}>MetricViewChartContent</div>;
|
const columnMetadata = dataMetadata?.column_metadata;
|
||||||
|
const isTable = chartConfig?.selectedChartType === ChartType.Table;
|
||||||
|
|
||||||
|
const cardClassName = useMemo(() => {
|
||||||
|
if (isTable || !fetchedData) return '';
|
||||||
|
return 'p-4';
|
||||||
|
}, [isTable, fetchedData]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cx('flex h-full flex-col overflow-hidden', cardClassName, className)}>
|
||||||
|
<BusterChart
|
||||||
|
loading={!fetchedData}
|
||||||
|
error={errorMessage || undefined}
|
||||||
|
data={metricData}
|
||||||
|
columnMetadata={columnMetadata}
|
||||||
|
{...chartConfig}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@ import {
|
||||||
BusterChartProps,
|
BusterChartProps,
|
||||||
ChartType,
|
ChartType,
|
||||||
IColumnLabelFormat,
|
IColumnLabelFormat,
|
||||||
Trendline,
|
Trendline
|
||||||
ViewType
|
|
||||||
} from '@/components/charts';
|
} from '@/components/charts';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
import { Checkbox, Select } from 'antd';
|
import { Checkbox, Select } from 'antd';
|
||||||
|
@ -150,7 +149,6 @@ export default function ChartJS() {
|
||||||
<BusterChart
|
<BusterChart
|
||||||
data={chartData}
|
data={chartData}
|
||||||
selectedChartType={chartType as ChartType.Pie}
|
selectedChartType={chartType as ChartType.Pie}
|
||||||
selectedView={ViewType.Table}
|
|
||||||
loading={false}
|
loading={false}
|
||||||
barAndLineAxis={barAndLineAxis}
|
barAndLineAxis={barAndLineAxis}
|
||||||
pieChartAxis={pieConfig.axis}
|
pieChartAxis={pieConfig.axis}
|
||||||
|
|
|
@ -6,8 +6,7 @@ import {
|
||||||
BusterChartProps,
|
BusterChartProps,
|
||||||
ChartType,
|
ChartType,
|
||||||
IColumnLabelFormat,
|
IColumnLabelFormat,
|
||||||
Trendline,
|
Trendline
|
||||||
ViewType
|
|
||||||
} from '@/components/charts';
|
} from '@/components/charts';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
import { Checkbox, Select } from 'antd';
|
import { Checkbox, Select } from 'antd';
|
||||||
|
@ -191,7 +190,6 @@ export default function ChartJS() {
|
||||||
<BusterChart
|
<BusterChart
|
||||||
data={chartData}
|
data={chartData}
|
||||||
selectedChartType={chartType as ChartType.Pie}
|
selectedChartType={chartType as ChartType.Pie}
|
||||||
selectedView={ViewType.Chart}
|
|
||||||
loading={false}
|
loading={false}
|
||||||
barAndLineAxis={barAndLineAxis}
|
barAndLineAxis={barAndLineAxis}
|
||||||
pieChartAxis={pieConfig.axis}
|
pieChartAxis={pieConfig.axis}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { BusterChartProps, ChartEncodes, ChartType, ViewType } from './interfaces';
|
import { BusterChartProps, ChartEncodes, ChartType } from './interfaces';
|
||||||
import isEmpty from 'lodash/isEmpty';
|
import isEmpty from 'lodash/isEmpty';
|
||||||
import { doesChartHaveValidAxis } from './helpers';
|
import { doesChartHaveValidAxis } from './helpers';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
|
@ -44,12 +44,11 @@ export const BusterChart: React.FC<BusterChartProps> = React.memo(
|
||||||
onInitialAnimationEnd,
|
onInitialAnimationEnd,
|
||||||
editable,
|
editable,
|
||||||
selectedChartType,
|
selectedChartType,
|
||||||
selectedView,
|
|
||||||
columnLabelFormats = DEFAULT_CHART_CONFIG.columnLabelFormats,
|
columnLabelFormats = DEFAULT_CHART_CONFIG.columnLabelFormats,
|
||||||
renderType = 'chartjs',
|
renderType = 'chartjs',
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const isTable = selectedView === ViewType.Table || selectedChartType === ChartType.Table;
|
const isTable = selectedChartType === ChartType.Table;
|
||||||
const showNoData = !loading && (isEmpty(data) || data === null);
|
const showNoData = !loading && (isEmpty(data) || data === null);
|
||||||
|
|
||||||
const selectedAxis: ChartEncodes | undefined = useMemo(() => {
|
const selectedAxis: ChartEncodes | undefined = useMemo(() => {
|
||||||
|
@ -73,7 +72,7 @@ export const BusterChart: React.FC<BusterChartProps> = React.memo(
|
||||||
selectedAxis,
|
selectedAxis,
|
||||||
isTable
|
isTable
|
||||||
});
|
});
|
||||||
}, [selectedChartType, selectedView, isTable, selectedAxis]);
|
}, [selectedChartType, isTable, selectedAxis]);
|
||||||
|
|
||||||
const onChartMounted = useMemoizedFn((chart?: any) => {
|
const onChartMounted = useMemoizedFn((chart?: any) => {
|
||||||
onChartMountedProp?.(chart);
|
onChartMountedProp?.(chart);
|
||||||
|
@ -152,12 +151,7 @@ export const BusterChart: React.FC<BusterChartProps> = React.memo(
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BusterChartErrorWrapper>
|
<BusterChartErrorWrapper>
|
||||||
<BusterChartWrapper
|
<BusterChartWrapper id={id} className={className} bordered={bordered} loading={loading}>
|
||||||
id={id}
|
|
||||||
className={className}
|
|
||||||
bordered={bordered}
|
|
||||||
loading={loading}
|
|
||||||
useTableSizing={isTable && !loading && !showNoData && hasValidAxis}>
|
|
||||||
{SwitchComponent()}
|
{SwitchComponent()}
|
||||||
</BusterChartWrapper>
|
</BusterChartWrapper>
|
||||||
</BusterChartErrorWrapper>
|
</BusterChartErrorWrapper>
|
||||||
|
|
|
@ -25,9 +25,7 @@ export class BusterChartErrorWrapper extends Component<Props, State> {
|
||||||
render() {
|
render() {
|
||||||
if (this.state.hasError) {
|
if (this.state.hasError) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="flex h-full w-full items-center justify-center" role="alert">
|
||||||
className="flex h-full w-full items-center justify-center rounded border p-5"
|
|
||||||
role="alert">
|
|
||||||
<Alert
|
<Alert
|
||||||
message="Something went wrong rendering the chart. This is likely an error on our end. Please contact Buster support."
|
message="Something went wrong rendering the chart. This is likely an error on our end. Please contact Buster support."
|
||||||
type="error"
|
type="error"
|
||||||
|
|
|
@ -9,8 +9,7 @@ export const BusterChartWrapper = React.memo<{
|
||||||
className: string | undefined;
|
className: string | undefined;
|
||||||
bordered: boolean;
|
bordered: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
useTableSizing: boolean;
|
}>(({ children, id, className, bordered, loading }) => {
|
||||||
}>(({ children, id, className, bordered, loading, useTableSizing }) => {
|
|
||||||
const { styles, cx } = useStyles();
|
const { styles, cx } = useStyles();
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const size = useSize(ref);
|
const size = useSize(ref);
|
||||||
|
@ -22,12 +21,9 @@ export const BusterChartWrapper = React.memo<{
|
||||||
ref={ref}
|
ref={ref}
|
||||||
id={id}
|
id={id}
|
||||||
className={cx(
|
className={cx(
|
||||||
styles.card,
|
|
||||||
className,
|
className,
|
||||||
'flex w-full flex-col',
|
'flex h-full w-full flex-col',
|
||||||
'transition duration-300',
|
'transition duration-300',
|
||||||
useTableSizing ? 'h-full' : 'h-full max-h-[600px] p-[18px]',
|
|
||||||
bordered ? styles.cardBorder : '',
|
|
||||||
loading ? '!bg-transparent' : undefined,
|
loading ? '!bg-transparent' : undefined,
|
||||||
'overflow-hidden'
|
'overflow-hidden'
|
||||||
)}>
|
)}>
|
||||||
|
@ -40,13 +36,5 @@ export const BusterChartWrapper = React.memo<{
|
||||||
BusterChartWrapper.displayName = 'BusterChartWrapper';
|
BusterChartWrapper.displayName = 'BusterChartWrapper';
|
||||||
|
|
||||||
const useStyles = createStyles(({ token }) => {
|
const useStyles = createStyles(({ token }) => {
|
||||||
return {
|
return {};
|
||||||
card: {
|
|
||||||
borderRadius: token.borderRadius,
|
|
||||||
background: token.colorBgContainer
|
|
||||||
},
|
|
||||||
cardBorder: {
|
|
||||||
border: `0.5px solid ${token.colorBorder}`
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,18 +1,5 @@
|
||||||
import { AppMaterialIcons } from '@/components/icons';
|
import { AppMaterialIcons } from '@/components/icons';
|
||||||
import { ViewType, ChartType } from './interfaces';
|
import { ChartType } from './interfaces';
|
||||||
|
|
||||||
export const viewTypeOptions = [
|
|
||||||
{
|
|
||||||
label: 'Chart',
|
|
||||||
value: ViewType.Chart,
|
|
||||||
icon: <AppMaterialIcons icon="monitoring" />
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Table',
|
|
||||||
value: ViewType.Table,
|
|
||||||
icon: <AppMaterialIcons icon="table" />
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export const chartOptions = [
|
export const chartOptions = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { BarAndLineAxis, ChartEncodes } from './interfaces';
|
import { ChartEncodes } from './interfaces';
|
||||||
import { ChartType, ViewType } from './interfaces/enum';
|
import { ChartType } from './interfaces/enum';
|
||||||
import isEmpty from 'lodash/isEmpty';
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
|
||||||
const defaultAxisCheck = (selectedAxis: ChartEncodes) => {
|
const defaultAxisCheck = (selectedAxis: ChartEncodes) => {
|
||||||
|
|
|
@ -42,7 +42,6 @@ export interface BusterChartRenderComponentProps
|
||||||
| 'id'
|
| 'id'
|
||||||
| 'bordered'
|
| 'bordered'
|
||||||
| 'editable'
|
| 'editable'
|
||||||
| 'selectedView'
|
|
||||||
| 'groupByMethod'
|
| 'groupByMethod'
|
||||||
| 'error'
|
| 'error'
|
||||||
| 'pieChartAxis'
|
| 'pieChartAxis'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ChartType, ViewType } from './enum';
|
import { ChartType } from './enum';
|
||||||
import type { BarAndLineAxis, ComboChartAxis, PieChartAxis, ScatterAxis } from './axisInterfaces';
|
import type { BarAndLineAxis, ComboChartAxis, PieChartAxis, ScatterAxis } from './axisInterfaces';
|
||||||
import type {
|
import type {
|
||||||
CategoryAxisStyleConfig,
|
CategoryAxisStyleConfig,
|
||||||
|
@ -13,7 +13,6 @@ import type { IColumnLabelFormat } from './columnLabelInterfaces';
|
||||||
|
|
||||||
export type BusterChartConfigProps = {
|
export type BusterChartConfigProps = {
|
||||||
selectedChartType: ChartType;
|
selectedChartType: ChartType;
|
||||||
selectedView: ViewType;
|
|
||||||
|
|
||||||
//COLUMN SETTINGS
|
//COLUMN SETTINGS
|
||||||
columnSettings?: Record<string, ColumnSettings>; //OPTIONAL because the defaults will be determined by the UI
|
columnSettings?: Record<string, ColumnSettings>; //OPTIONAL because the defaults will be determined by the UI
|
||||||
|
|
|
@ -14,8 +14,3 @@ export type ChartTypePlottable =
|
||||||
| ChartType.Scatter
|
| ChartType.Scatter
|
||||||
| ChartType.Pie
|
| ChartType.Pie
|
||||||
| ChartType.Combo;
|
| ChartType.Combo;
|
||||||
|
|
||||||
export enum ViewType {
|
|
||||||
Chart = 'chart',
|
|
||||||
Table = 'table'
|
|
||||||
}
|
|
||||||
|
|
|
@ -98,12 +98,14 @@ const useMetricData = () => {
|
||||||
fetching: true
|
fetching: true
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO: remove mock data
|
setTimeout(() => {
|
||||||
// _setMetricData(metricId, { ...MOCK_DATA, fetched: true });
|
//TODO: remove mock data
|
||||||
onSetMetricData({
|
// _setMetricData(metricId, { ...MOCK_DATA, fetched: true });
|
||||||
...MOCK_DATA,
|
onSetMetricData({
|
||||||
metricId
|
...MOCK_DATA,
|
||||||
});
|
metricId
|
||||||
|
});
|
||||||
|
}, 1800);
|
||||||
|
|
||||||
return await busterSocket.emitAndOnce({
|
return await busterSocket.emitAndOnce({
|
||||||
emitEvent: {
|
emitEvent: {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type { BusterMetricData } from '../Metrics';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
|
|
||||||
const mockData = (): Record<string, string | number | null>[] => {
|
const mockData = (): Record<string, string | number | null>[] => {
|
||||||
return Array.from({ length: 10 }, (x, index) => ({
|
return Array.from({ length: 100 }, (x, index) => ({
|
||||||
sales: faker.number.int({ min: index * 50, max: (index + 1) * 100 }),
|
sales: faker.number.int({ min: index * 50, max: (index + 1) * 100 }),
|
||||||
date: faker.date.past({ years: index + 1 }).toISOString(),
|
date: faker.date.past({ years: index + 1 }).toISOString(),
|
||||||
product: faker.commerce.productName()
|
product: faker.commerce.productName()
|
||||||
|
@ -41,12 +41,19 @@ const dataMetadata: DataMetadata = {
|
||||||
row_count: 10
|
row_count: 10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const data = mockData();
|
||||||
|
data.push({
|
||||||
|
sales: 1,
|
||||||
|
date: '2024-01-01',
|
||||||
|
product: 'NATE RULEZ'
|
||||||
|
});
|
||||||
|
|
||||||
export const MOCK_DATA: Required<BusterMetricData> = {
|
export const MOCK_DATA: Required<BusterMetricData> = {
|
||||||
fetched: true,
|
fetched: true,
|
||||||
fetching: false,
|
fetching: false,
|
||||||
error: null,
|
error: null,
|
||||||
fetchedAt: Date.now(),
|
fetchedAt: Date.now(),
|
||||||
data: mockData(),
|
data: data,
|
||||||
data_metadata: dataMetadata,
|
data_metadata: dataMetadata,
|
||||||
dataFromRerun: null,
|
dataFromRerun: null,
|
||||||
code: `SELECT
|
code: `SELECT
|
||||||
|
|
|
@ -505,10 +505,12 @@ export const useBusterMetrics = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: remove this
|
//TODO: remove this
|
||||||
_onGetMetricState({
|
setTimeout(() => {
|
||||||
...MOCK_METRIC,
|
_onGetMetricState({
|
||||||
id: metricId
|
...MOCK_METRIC,
|
||||||
});
|
id: metricId
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
|
||||||
return await busterSocket.emitAndOnce({
|
return await busterSocket.emitAndOnce({
|
||||||
emitEvent: {
|
emitEvent: {
|
||||||
|
|
|
@ -1,6 +1,55 @@
|
||||||
import { DEFAULT_CHART_CONFIG, ShareRole, VerificationStatus } from '@/api/asset_interfaces';
|
import {
|
||||||
|
DataMetadata,
|
||||||
|
DEFAULT_CHART_CONFIG,
|
||||||
|
IBusterMetricChartConfig,
|
||||||
|
ShareRole,
|
||||||
|
VerificationStatus
|
||||||
|
} from '@/api/asset_interfaces';
|
||||||
import { IBusterMetric } from './interfaces';
|
import { IBusterMetric } from './interfaces';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
|
import { ChartType } from '@/components/charts';
|
||||||
|
|
||||||
|
const MOCK_CHART_CONFIG: IBusterMetricChartConfig = {
|
||||||
|
...DEFAULT_CHART_CONFIG,
|
||||||
|
selectedChartType: ChartType.Bar,
|
||||||
|
barAndLineAxis: {
|
||||||
|
x: ['date'],
|
||||||
|
y: ['sales'],
|
||||||
|
category: []
|
||||||
|
// category: ['product']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataMetadata: DataMetadata = {
|
||||||
|
column_count: 3,
|
||||||
|
column_metadata: [
|
||||||
|
{
|
||||||
|
name: 'sales',
|
||||||
|
min_value: 0,
|
||||||
|
max_value: 1000,
|
||||||
|
unique_values: 10,
|
||||||
|
simple_type: 'number',
|
||||||
|
type: 'integer'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'date',
|
||||||
|
min_value: '2024-01-01',
|
||||||
|
max_value: '2024-01-31',
|
||||||
|
unique_values: 31,
|
||||||
|
simple_type: 'date',
|
||||||
|
type: 'date'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'product',
|
||||||
|
min_value: 'Product A',
|
||||||
|
max_value: 'Product Z',
|
||||||
|
unique_values: 26,
|
||||||
|
simple_type: 'text',
|
||||||
|
type: 'text'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
row_count: 10
|
||||||
|
};
|
||||||
|
|
||||||
export const MOCK_METRIC: IBusterMetric = {
|
export const MOCK_METRIC: IBusterMetric = {
|
||||||
id: '123',
|
id: '123',
|
||||||
|
@ -8,14 +57,14 @@ export const MOCK_METRIC: IBusterMetric = {
|
||||||
description: 'This is a mock metric',
|
description: 'This is a mock metric',
|
||||||
time_frame: '1d',
|
time_frame: '1d',
|
||||||
type: 'metric',
|
type: 'metric',
|
||||||
chart_config: DEFAULT_CHART_CONFIG,
|
chart_config: MOCK_CHART_CONFIG,
|
||||||
fetched: true,
|
fetched: true,
|
||||||
fetching: false,
|
fetching: false,
|
||||||
fetchedAt: 0,
|
fetchedAt: 0,
|
||||||
dataset_id: '123',
|
dataset_id: '123',
|
||||||
dataset_name: 'Mock Dataset',
|
dataset_name: 'Mock Dataset',
|
||||||
error: null,
|
error: null,
|
||||||
data_metadata: null,
|
data_metadata: dataMetadata,
|
||||||
status: VerificationStatus.notRequested,
|
status: VerificationStatus.notRequested,
|
||||||
evaluation_score: 'Moderate',
|
evaluation_score: 'Moderate',
|
||||||
evaluation_summary: faker.lorem.sentence(33),
|
evaluation_summary: faker.lorem.sentence(33),
|
||||||
|
|
|
@ -25,7 +25,6 @@ describe('createDefaultChartConfig', () => {
|
||||||
'#E83562'
|
'#E83562'
|
||||||
],
|
],
|
||||||
selectedChartType: 'table',
|
selectedChartType: 'table',
|
||||||
selectedView: 'table',
|
|
||||||
yAxisShowAxisLabel: true,
|
yAxisShowAxisLabel: true,
|
||||||
yAxisShowAxisTitle: true,
|
yAxisShowAxisTitle: true,
|
||||||
yAxisAxisTitle: null,
|
yAxisAxisTitle: null,
|
||||||
|
|
|
@ -158,7 +158,6 @@ const ChartPreviewImage = ({
|
||||||
messageData: BusterMetricData;
|
messageData: BusterMetricData;
|
||||||
}) => {
|
}) => {
|
||||||
const data = messageData?.data || [];
|
const data = messageData?.data || [];
|
||||||
const selectedChartView = message?.chart_config?.selectedView;
|
|
||||||
const chartOptions = message?.chart_config;
|
const chartOptions = message?.chart_config;
|
||||||
|
|
||||||
const chart = (
|
const chart = (
|
||||||
|
@ -187,10 +186,6 @@ export const PreviewImageReactComponent: React.FC<{
|
||||||
}> = ({ isDark = false, message, messageData }) => {
|
}> = ({ isDark = false, message, messageData }) => {
|
||||||
const data = messageData?.data || [];
|
const data = messageData?.data || [];
|
||||||
|
|
||||||
if (!message?.chart_config?.selectedView) {
|
|
||||||
return <div></div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BusterLogo = (
|
const BusterLogo = (
|
||||||
<div
|
<div
|
||||||
className="w-[165px] rounded p-1"
|
className="w-[165px] rounded p-1"
|
||||||
|
|
Loading…
Reference in New Issue