Skip to content

Commit

Permalink
FIX: failed to render in 1000ms warning
Browse files Browse the repository at this point in the history
  • Loading branch information
matttdawson committed May 23, 2024
1 parent a21014d commit 0add40d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/components/GridNoRowsOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { LuiStatusSpinner } from "@linzjs/lui";
import { ForwardedRef, forwardRef } from "react";

const GridLoadingOverlayComponent = (props: { headerRowHeight: number }) => (
const GridLoadingOverlayComponentFr = (
props: { headerRowHeight: number },
externalRef: ForwardedRef<HTMLDivElement>,
) => (
<div
ref={externalRef}
style={{
left: 0,
top: 0,
Expand All @@ -19,6 +24,8 @@ const GridLoadingOverlayComponent = (props: { headerRowHeight: number }) => (
</div>
);

const GridLoadingOverlayComponent = forwardRef(GridLoadingOverlayComponentFr);

export interface GridNoRowsOverlayProps {
loading: boolean;
rowCount: number | undefined | null;
Expand All @@ -28,10 +35,17 @@ export interface GridNoRowsOverlayProps {
headerRowHeight: number;
}

export const GridNoRowsOverlay = (props: GridNoRowsOverlayProps) => {
if (props.loading) return <GridLoadingOverlayComponent headerRowHeight={props.headerRowHeight} />;
if (props.rowCount === 0) return <div>{props.noRowsOverlayText ?? "There are currently no rows"}</div>;
if (props.filteredRowCount === 0)
return <div>{props.noRowsMatchingOverlayText ?? "All rows have been filtered"}</div>;
return <span />;
export const GridNoRowsOverlayFr = (props: GridNoRowsOverlayProps, externalRef: ForwardedRef<HTMLDivElement>) => {
if (props.loading) {
return <GridLoadingOverlayComponent ref={externalRef} headerRowHeight={props.headerRowHeight} />;
}
if (props.rowCount === 0) {
return <div ref={externalRef}>{props.noRowsOverlayText ?? "There are currently no rows"}</div>;
}
if (props.filteredRowCount === 0) {
return <div ref={externalRef}>{props.noRowsMatchingOverlayText ?? "All rows have been filtered"}</div>;
}
return <div ref={externalRef} />;
};

export const GridNoRowsOverlay = forwardRef(GridNoRowsOverlayFr);

0 comments on commit 0add40d

Please sign in to comment.