Skip to content

Commit 06f9689

Browse files
authored
feat(dashboards): Allow removing of wrapper in lazyrender (#68998)
1 parent 604a22e commit 06f9689

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

static/app/components/lazyRender.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export interface LazyRenderProps {
2525
children: React.ReactNode;
2626
containerHeight?: number;
2727
observerOptions?: Partial<IntersectionObserverInit>;
28+
/**
29+
* Removes the wrapping div once visible
30+
*/
31+
withoutContainer?: boolean;
2832
}
2933

3034
/**
@@ -79,5 +83,9 @@ export function LazyRender(props: LazyRenderProps) {
7983
[visible, props.observerOptions, props.containerHeight]
8084
);
8185

86+
if (visible && props.withoutContainer) {
87+
return props.children;
88+
}
89+
8290
return <div ref={onRefNode}>{visible ? props.children : null}</div>;
8391
}

static/app/components/modals/widgetBuilder/addToDashboardModal.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import {DashboardWidgetSource, DisplayType} from 'sentry/views/dashboards/types'
1111

1212
const stubEl = (props: {children?: React.ReactNode}) => <div>{props.children}</div>;
1313

14+
jest.mock('sentry/components/lazyRender', () => ({
15+
LazyRender: ({children}: {children: React.ReactNode}) => children,
16+
}));
17+
1418
const mockWidgetAsQueryParams = {
1519
defaultTableColumns: ['field1', 'field2'],
1620
defaultTitle: 'Default title',

static/app/views/dashboards/widgetCard/index.spec.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import ReleaseWidgetQueries from 'sentry/views/dashboards/widgetCard/releaseWidg
2222

2323
jest.mock('sentry/components/charts/simpleTableChart', () => jest.fn(() => <div />));
2424
jest.mock('sentry/views/dashboards/widgetCard/releaseWidgetQueries');
25+
jest.mock('sentry/components/lazyRender', () => ({
26+
LazyRender: ({children}: {children: React.ReactNode}) => children,
27+
}));
2528

2629
describe('Dashboards > WidgetCard', function () {
2730
const {router, organization, routerContext} = initializeOrg({

static/app/views/dashboards/widgetCard/index.tsx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Component, Fragment} from 'react';
2-
// import LazyLoad from 'react-lazyload';
32
import type {WithRouterProps} from 'react-router';
43
import type {useSortable} from '@dnd-kit/sortable';
54
import styled from '@emotion/styled';
@@ -10,6 +9,7 @@ import {Alert} from 'sentry/components/alert';
109
import ErrorPanel from 'sentry/components/charts/errorPanel';
1110
import {HeaderTitle} from 'sentry/components/charts/styles';
1211
import ErrorBoundary from 'sentry/components/errorBoundary';
12+
import {LazyRender} from 'sentry/components/lazyRender';
1313
import ExternalLink from 'sentry/components/links/externalLink';
1414
import Panel from 'sentry/components/panels/panel';
1515
import PanelAlert from 'sentry/components/panels/panelAlert';
@@ -226,7 +226,7 @@ class WidgetCard extends Component<Props, State> {
226226
renderErrorMessage,
227227
tableItemLimit,
228228
windowWidth,
229-
// noLazyLoad,
229+
noLazyLoad,
230230
showStoredAlert,
231231
noDashboardsMEPProvider,
232232
dashboardFilters,
@@ -349,8 +349,7 @@ class WidgetCard extends Component<Props, State> {
349349
<IconWarning color="gray500" size="lg" />
350350
</StyledErrorPanel>
351351
</Fragment>
352-
) : (
353-
// noLazyLoad ?
352+
) : noLazyLoad ? (
354353
<WidgetCardChartContainer
355354
location={location}
356355
api={api}
@@ -365,28 +364,23 @@ class WidgetCard extends Component<Props, State> {
365364
dashboardFilters={dashboardFilters}
366365
chartGroup={DASHBOARD_CHART_GROUP}
367366
/>
368-
// )
369-
// : (
370-
// <LazyLoad
371-
// once
372-
// resize
373-
// height={200}
374-
// >
375-
// <WidgetCardChartContainer
376-
// location={location}
377-
// api={api}
378-
// organization={organization}
379-
// selection={selection}
380-
// widget={widget}
381-
// isMobile={isMobile}
382-
// renderErrorMessage={renderErrorMessage}
383-
// tableItemLimit={tableItemLimit}
384-
// windowWidth={windowWidth}
385-
// onDataFetched={this.setData}
386-
// dashboardFilters={dashboardFilters}
387-
// chartGroup={DASHBOARD_CHART_GROUP}
388-
// />
389-
// </LazyLoad>
367+
) : (
368+
<LazyRender containerHeight={200} withoutContainer>
369+
<WidgetCardChartContainer
370+
location={location}
371+
api={api}
372+
organization={organization}
373+
selection={selection}
374+
widget={widget}
375+
isMobile={isMobile}
376+
renderErrorMessage={renderErrorMessage}
377+
tableItemLimit={tableItemLimit}
378+
windowWidth={windowWidth}
379+
onDataFetched={this.setData}
380+
dashboardFilters={dashboardFilters}
381+
chartGroup={DASHBOARD_CHART_GROUP}
382+
/>
383+
</LazyRender>
390384
)}
391385
{this.renderToolbar()}
392386
</WidgetCardPanel>

0 commit comments

Comments
 (0)