Skip to content

feat(charts): introduce loadingDelay prop #6027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 8, 2024
2 changes: 2 additions & 0 deletions packages/charts/src/components/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@
* @param measure {IChartMeasure} Current measure object
* @param dataElement {object} Current data element
*/
highlightColor?: (value: number, measure: MeasureConfig, dataElement: Record<string, any>) => CSSProperties['color'];

Check warning on line 79 in packages/charts/src/components/BarChart/BarChart.tsx

GitHub Actions / lint

Unexpected any. Specify a different type
}

interface DimensionConfig extends IChartDimension {
@@ -130,6 +130,7 @@
const BarChart = forwardRef<HTMLDivElement, BarChartProps>((props, ref) => {
const {
loading,
loadingDelay,
dataset,
noLegend,
noAnimation,
@@ -185,7 +186,7 @@
? dataKeys.findIndex((key) => key === chartConfig.secondYAxis?.dataKey)
: 0;

const [componentRef, chartRef] = useSyncRef<any>(ref);

Check warning on line 189 in packages/charts/src/components/BarChart/BarChart.tsx

GitHub Actions / lint

Unexpected any. Specify a different type

const onItemLegendClick = useLegendItemClick(onLegendClick);
const labelFormatter = useLabelFormatter(primaryDimension);
@@ -226,6 +227,7 @@
<ChartContainer
dataset={dataset}
loading={loading}
loadingDelay={loadingDelay}
Placeholder={ChartPlaceholder ?? BarChartPlaceholder}
ref={componentRef}
style={style}
2 changes: 2 additions & 0 deletions packages/charts/src/components/BulletChart/BulletChart.tsx
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@
* @param measure {IChartMeasure} Current measure object
* @param dataElement {object} Current data element
*/
highlightColor?: (value: number, measure: MeasureConfig, dataElement: Record<string, any>) => CSSProperties['color'];

Check warning on line 69 in packages/charts/src/components/BulletChart/BulletChart.tsx

GitHub Actions / lint

Unexpected any. Specify a different type
}

interface DimensionConfig extends IChartDimension {
@@ -128,6 +128,7 @@
const BulletChart = forwardRef<HTMLDivElement, BulletChartProps>((props, ref) => {
const {
loading,
loadingDelay,
dataset,
onDataPointClick,
noLegend,
@@ -145,7 +146,7 @@
...rest
} = props;

const [componentRef, chartRef] = useSyncRef<any>(ref);

Check warning on line 149 in packages/charts/src/components/BulletChart/BulletChart.tsx

GitHub Actions / lint

Unexpected any. Specify a different type

const chartConfig: BulletChartProps['chartConfig'] = {
yAxisVisible: false,
@@ -224,7 +225,7 @@
);
} else {
onDataPointClick(
enrichEventWithDetails({} as any, {

Check warning on line 228 in packages/charts/src/components/BulletChart/BulletChart.tsx

GitHub Actions / lint

Unexpected any. Specify a different type
value: eventOrIndex.value,
dataKey: eventOrIndex.dataKey,
dataIndex: eventOrIndex.index,
@@ -271,6 +272,7 @@
<ChartContainer
ref={componentRef}
loading={loading}
loadingDelay={loadingDelay}
dataset={dataset}
Placeholder={ChartPlaceholder ?? Placeholder}
style={style}
@@ -299,7 +301,7 @@
{chartConfig.xAxisVisible &&
dimensions.map((dimension, index) => {
let AxisComponent;
const axisProps: any = {

Check warning on line 304 in packages/charts/src/components/BulletChart/BulletChart.tsx

GitHub Actions / lint

Unexpected any. Specify a different type
dataKey: dimension.accessor,
interval: dimension?.interval ?? (isBigDataSet ? 'preserveStart' : 0),
tickLine: index < 1,
@@ -437,7 +439,7 @@
/>
)}
{sortedMeasures?.map((element, index) => {
const chartElementProps: any = {

Check warning on line 442 in packages/charts/src/components/BulletChart/BulletChart.tsx

GitHub Actions / lint

Unexpected any. Specify a different type
isAnimationActive: !noAnimation
};
let labelPosition = 'top';
2 changes: 2 additions & 0 deletions packages/charts/src/components/ColumnChart/ColumnChart.tsx
Original file line number Diff line number Diff line change
@@ -128,6 +128,7 @@ const valueAccessor =
const ColumnChart = forwardRef<HTMLDivElement, ColumnChartProps>((props, ref) => {
const {
loading,
loadingDelay,
dataset,
noLegend,
noAnimation,
@@ -225,6 +226,7 @@ const ColumnChart = forwardRef<HTMLDivElement, ColumnChartProps>((props, ref) =>
<ChartContainer
dataset={dataset}
loading={loading}
loadingDelay={loadingDelay}
Placeholder={ChartPlaceholder ?? ColumnChartPlaceholder}
ref={componentRef}
style={style}
Original file line number Diff line number Diff line change
@@ -106,6 +106,7 @@ type AvailableChartTypes = 'line' | 'bar' | string;
const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProps>((props, ref) => {
const {
loading,
loadingDelay,
dataset,
style,
className,
@@ -177,6 +178,7 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
tooltipConfig={lineTooltipConfig}
noAnimation={noAnimation}
loading={loading}
loadingDelay={loadingDelay}
onClick={onClick}
syncId={syncId}
style={{ ...style, height: `calc(${style?.height} * 0.2)` }}
@@ -201,6 +203,7 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
noAnimation={noAnimation}
noLegend={noLegend}
loading={loading}
loadingDelay={loadingDelay}
onClick={onClick}
onDataPointClick={onDataPointClick}
syncId={syncId}
2 changes: 2 additions & 0 deletions packages/charts/src/components/ComposedChart/index.tsx
Original file line number Diff line number Diff line change
@@ -142,6 +142,7 @@ type AvailableChartTypes = 'line' | 'bar' | 'area' | string;
const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref) => {
const {
loading,
loadingDelay,
dataset,
onDataPointClick,
noLegend,
@@ -276,6 +277,7 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
<ChartContainer
ref={componentRef}
loading={loading}
loadingDelay={loadingDelay}
dataset={dataset}
Placeholder={ChartPlaceholder ?? Placeholder}
style={style}
2 changes: 2 additions & 0 deletions packages/charts/src/components/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
@@ -115,6 +115,7 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
const {
dataset,
loading,
loadingDelay,
noLegend,
noAnimation,
tooltipConfig,
@@ -214,6 +215,7 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
<ChartContainer
dataset={dataset}
loading={loading}
loadingDelay={loadingDelay}
Placeholder={ChartPlaceholder ?? LineChartPlaceholder}
ref={componentRef}
style={style}
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ const resolveColor = (index: number, color = null) => {
* The `MicroBarChart` compares different values of the same category to each other by displaying them in a compact way.
*/
const MicroBarChart = forwardRef<HTMLDivElement, MicroBarChartProps>((props, ref) => {
const { loading, dataset, onDataPointClick, style, className, slot, ChartPlaceholder, ...rest } = props;
const { loading, loadingDelay, dataset, onDataPointClick, style, className, slot, ChartPlaceholder, ...rest } = props;

useStylesheet(styleData, MicroBarChart.displayName);

@@ -140,6 +140,7 @@ const MicroBarChart = forwardRef<HTMLDivElement, MicroBarChartProps>((props, ref
<ChartContainer
dataset={dataset}
loading={loading}
loadingDelay={loadingDelay}
Placeholder={ChartPlaceholder ?? BarChartPlaceholder}
ref={ref}
style={style}
2 changes: 2 additions & 0 deletions packages/charts/src/components/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
@@ -91,6 +91,7 @@ const tooltipItemDefaultStyle = { color: 'var (--sapTextColor)' };
const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
const {
loading,
loadingDelay,
dataset,
noLegend,
noAnimation,
@@ -267,6 +268,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
dataset={dataset}
ref={ref}
loading={loading}
loadingDelay={loadingDelay}
Placeholder={ChartPlaceholder ?? PieChartPlaceholder}
style={style}
className={className}
2 changes: 2 additions & 0 deletions packages/charts/src/components/RadarChart/RadarChart.tsx
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ const measureDefaults = {
const RadarChart = forwardRef<HTMLDivElement, RadarChartProps>((props, ref) => {
const {
loading,
loadingDelay,
dataset,
noLegend,
noAnimation,
@@ -166,6 +167,7 @@ const RadarChart = forwardRef<HTMLDivElement, RadarChartProps>((props, ref) => {
dataset={dataset}
ref={ref}
loading={loading}
loadingDelay={loadingDelay}
Placeholder={ChartPlaceholder ?? PieChartPlaceholder}
style={style}
className={className}
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ interface RadialChartConfig {

[rest: string]: any;
}

//todo expose `loading`
export interface RadialChartProps extends Omit<CommonProps, 'onClick' | 'children' | 'onLegendClick'> {
/**
* The actual value which defines how much the ring is filled.
@@ -126,6 +126,8 @@ const RadialChart = forwardRef<HTMLDivElement, RadialChartProps>((props, ref) =>

return (
<ChartContainer
loading={undefined}
loadingDelay={undefined}
dataset={dataset}
ref={ref}
Placeholder={PieChartPlaceholder}
Original file line number Diff line number Diff line change
@@ -133,6 +133,7 @@ const ScatterChart = forwardRef<HTMLDivElement, ScatterChartProps>((props, ref)
const {
dataset,
loading,
loadingDelay,
noLegend,
noAnimation,
tooltipConfig,
@@ -216,6 +217,7 @@ const ScatterChart = forwardRef<HTMLDivElement, ScatterChartProps>((props, ref)
<ChartContainer
dataset={dataset}
loading={loading}
loadingDelay={loadingDelay}
Placeholder={ChartPlaceholder ?? ScatterChartPlaceholder}
ref={componentRef}
style={style}
9 changes: 7 additions & 2 deletions packages/charts/src/interfaces/IChartBaseProps.ts
Original file line number Diff line number Diff line change
@@ -7,10 +7,15 @@ export interface IChartBaseProps<T = ICartesianChartConfig> extends Omit<CommonP
/**
* Flag whether the chart should display a loading indicator.
*
* This can either be a placeholder shimmer (in case the chart has no data yet) or a small
* loading bar in the top of the chart (in case the chart has already some data to display).
* This can either be a skeleton placeholder shimmer (in case the chart has no data yet) or a `BusyIndicator` on top of the chart (in case the chart has already some data to display).
*/
loading?: boolean;
/**
* Defines the delay in milliseconds, after which the `BusyIndicator` will be visible on the screen.
*
* @default 1000
*/
loadingDelay?: number;
/**
* The `dataset` is an array of object which will be displayed in the chart.
*/
18 changes: 15 additions & 3 deletions packages/charts/src/internal/ChartContainer.tsx
Original file line number Diff line number Diff line change
@@ -23,9 +23,10 @@ addCustomCSSWithScoping(

export interface ContainerProps extends CommonProps {
children: ReactElement;
Placeholder?: ComponentType;
Placeholder: ComponentType;
dataset: unknown[];
loading?: boolean;
loading: boolean;
loadingDelay: number;
resizeDebounce: number;
}

@@ -49,7 +50,17 @@ class ErrorBoundary extends Component<{ children: ReactNode }, { errorCount: num
}

const ChartContainer = forwardRef<HTMLDivElement, ContainerProps>((props, ref) => {
const { Placeholder, loading = false, dataset, className, slot, children, resizeDebounce, ...rest } = props;
const {
Placeholder,
loading = false,
dataset,
className,
slot,
children,
resizeDebounce,
loadingDelay,
...rest
} = props;

useStylesheet(styleData, ChartContainer.displayName);

@@ -60,6 +71,7 @@ const ChartContainer = forwardRef<HTMLDivElement, ContainerProps>((props, ref) =
{loading && (
<BusyIndicator
active
delay={loadingDelay}
className={classNames.busyIndicator}
data-component-name="ChartContainerBusyIndicator"
/>

Unchanged files with check annotations Beta

function ResizeTestComponent({ onChange }: { onChange: (event: { width: number; height: number }) => void }) {
useEffect(() => {
attachResizeHandler(onChange);
}, []);

Check warning on line 12 in packages/base/src/Device/index.cy.tsx

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'onChange'. Either include it or remove the dependency array
const unregister = () => {
detachResizeHandler(onChange);
}) {
useEffect(() => {
attachOrientationChangeHandler(onChange);
}, []);

Check warning on line 32 in packages/base/src/Device/index.cy.tsx

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'onChange'. Either include it or remove the dependency array
const unregister = () => {
detachOrientationChangeHandler(onChange);
speed={2}
backgroundColor={ThemingParameters.sapContent_ImagePlaceholderBackground}
foregroundColor={ThemingParameters.sapContent_ImagePlaceholderForegroundColor}
backgroundOpacity={ThemingParameters.sapContent_DisabledOpacity as any}

Check warning on line 15 in packages/charts/src/components/BarChart/Placeholder.tsx

GitHub Actions / lint

Unexpected any. Specify a different type
>
<rect x="20" y="10" width="1" height="135" />
<rect x="20" y="20" width="85" height="15" />