Skip to content

Commit 27be279

Browse files
committed
feat: add onDataView callback to visualization components
This optional callback can be used to get notified whenever the visualization loads new data. This can be used to display some extra UI elements based on the data being empty, partially empty, etc. For now added as alpha, pending some feedback from internal use. JIRA: CQ-1287 risk: low
1 parent 47ad217 commit 27be279

File tree

17 files changed

+155
-7
lines changed

17 files changed

+155
-7
lines changed

libs/sdk-ui-charts/src/charts/repeater/CoreRepeater.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const CoreRepeaterImpl: React.FC<ICoreRepeaterChartProps> = (props) => {
4747
pushData,
4848
onError,
4949
onColumnResized,
50+
onDataView,
5051
config = {},
5152
drillableItems = [],
5253
onDrill = noop,
@@ -76,6 +77,7 @@ export const CoreRepeaterImpl: React.FC<ICoreRepeaterChartProps> = (props) => {
7677
onSuccess: (dataView) => {
7778
onLoadingChanged?.({ isLoading: false });
7879
pushData?.({ dataView: dataView.dataView });
80+
onDataView?.(dataView);
7981
},
8082
onError: (error) => {
8183
onLoadingChanged?.({ isLoading: false });

libs/sdk-ui-ext/src/insightView/InsightRenderer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,10 @@ class InsightRendererCore extends React.PureComponent<IInsightRendererProps & Wr
181181
this.props.onError?.(error);
182182
this.props.onLoadingChanged?.({ isLoading: false });
183183
},
184-
onLoadingChanged: ({ isLoading }) => {
185-
this.props.onLoadingChanged?.({ isLoading });
186-
},
184+
onLoadingChanged: this.props.onLoadingChanged,
187185
pushData: this.props.pushData,
188186
onDrill: this.props.onDrill,
187+
onDataView: this.props.onDataView,
189188
onExportReady: this.onExportReadyDecorator,
190189
afterRender: this.props.afterRender,
191190
},
@@ -370,6 +369,7 @@ export const InsightRenderer: React.FC<IInsightRendererProps> = (props) => {
370369
onError: onErrorCallBack,
371370
onExportReady: onExportReadyCallback,
372371
onLoadingChanged: onLoadingChangedCallback,
372+
onDataView: onDataViewCallback,
373373
...resProps
374374
} = props;
375375

@@ -378,6 +378,7 @@ export const InsightRenderer: React.FC<IInsightRendererProps> = (props) => {
378378
const onError = useUpdatableCallback(onErrorCallBack);
379379
const onExportReady = useUpdatableCallback(onExportReadyCallback);
380380
const onLoadingChanged = useUpdatableCallback(onLoadingChangedCallback);
381+
const onDataView = useUpdatableCallback(onDataViewCallback);
381382

382383
return (
383384
<IntlWrapper locale={props.locale}>
@@ -387,6 +388,7 @@ export const InsightRenderer: React.FC<IInsightRendererProps> = (props) => {
387388
onError={onError}
388389
onExportReady={onExportReady}
389390
onLoadingChanged={onLoadingChanged}
391+
onDataView={onDataView}
390392
{...resProps}
391393
/>
392394
</IntlWrapper>

libs/sdk-ui-ext/src/insightView/InsightView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const InsightViewCore: React.FC<IInsightViewProps & WrappedComponentProps> = (pr
6060
onLoadingChanged,
6161
onExportReady,
6262
onError,
63+
onDataView,
6364
onInsightLoaded,
6465
pushData,
6566

@@ -248,6 +249,7 @@ const InsightViewCore: React.FC<IInsightViewProps & WrappedComponentProps> = (pr
248249
onError={handleError}
249250
onExportReady={onExportReady}
250251
onLoadingChanged={handleLoadingChanged}
252+
onDataView={onDataView}
251253
pushData={pushData}
252254
/>
253255
</div>

libs/sdk-ui-ext/src/internal/components/BaseVisualization.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export class BaseVisualization extends React.PureComponent<IBaseVisualizationPro
272272
console.error(`Error: unsupported visualization type - ${visUri}`);
273273
}
274274

275-
let visualizationId;
275+
let visualizationId: string;
276276
if (isInsight(insight)) {
277277
visualizationId = insight.insight.identifier;
278278
} else {
@@ -304,6 +304,7 @@ export class BaseVisualization extends React.PureComponent<IBaseVisualizationPro
304304
onExportReady: props.onExportReady,
305305
pushData: props.pushData,
306306
onDrill: props.onDrill,
307+
onDataView: props.onDataView,
307308
},
308309
featureFlags,
309310
visualizationProperties: insightProperties(props.insight),

libs/sdk-ui-ext/src/internal/components/pluggableVisualizations/AbstractPluggableVisualization.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
UnexpectedSdkError,
3636
isForecastNotReceived,
3737
isClusteringNotReceived,
38+
DataViewFacade,
3839
} from "@gooddata/sdk-ui";
3940
import { IntlShape } from "react-intl";
4041
import { createInternalIntl } from "../../utils/internalIntlProvider.js";
@@ -292,6 +293,10 @@ export abstract class AbstractPluggableVisualization implements IVisualization {
292293
return this.callbacks.onDrill ? this.callbacks.onDrill(event) : true;
293294
};
294295

296+
protected onDataView = (dataView: DataViewFacade): void => {
297+
this.callbacks.onDataView?.(dataView);
298+
};
299+
295300
//
296301
// Templated implementation of addNewDerivedBucketItems contract
297302
//

libs/sdk-ui-ext/src/internal/components/pluggableVisualizations/baseChart/PluggableBaseChart.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export class PluggableBaseChart extends AbstractPluggableVisualization {
289289
onExportReady={this.onExportReady}
290290
onLoadingChanged={this.onLoadingChanged}
291291
pushData={this.handlePushData}
292+
onDataView={this.onDataView}
292293
height={resultingHeight}
293294
type={this.type}
294295
locale={locale}

libs/sdk-ui-ext/src/internal/components/pluggableVisualizations/geoChart/PluggableGeoPushpinChart.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export class PluggableGeoPushpinChart extends PluggableBaseChart {
308308
onError: this.onError,
309309
onExportReady: this.onExportReady,
310310
onLoadingChanged: this.onLoadingChanged,
311+
onDataView: this.onDataView,
311312
LoadingComponent: null,
312313
ErrorComponent: null,
313314
theme,

libs/sdk-ui-ext/src/internal/components/pluggableVisualizations/headline/PluggableHeadline.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export class PluggableHeadline extends AbstractPluggableVisualization {
242242
config={headlineConfig}
243243
afterRender={this.afterRender}
244244
onLoadingChanged={this.onLoadingChanged}
245+
onDataView={this.onDataView}
245246
pushData={this.pushData}
246247
onError={this.onError}
247248
LoadingComponent={null}

libs/sdk-ui-ext/src/internal/components/pluggableVisualizations/pivotTable/PluggablePivotTable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export class PluggablePivotTable extends AbstractPluggableVisualization {
404404
pushData: this.handlePushData,
405405
onError: this.onError,
406406
onExportReady: this.onExportReady,
407+
onDataView: this.onDataView,
407408
onColumnResized,
408409
};
409410
};

libs/sdk-ui-ext/src/internal/components/pluggableVisualizations/repeater/PluggableRepeater.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ export class PluggableRepeater extends AbstractPluggableVisualization {
372372
onLoadingChanged={this.onLoadingChanged}
373373
pushData={this.handlePushData}
374374
onError={this.onError}
375+
onDataView={this.onDataView}
375376
onColumnResized={this.onColumnResized}
376377
intl={this.intl}
377378
/>,

0 commit comments

Comments
 (0)