Skip to content
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

[Platform]: tanstack server side table with initial loading #629

Merged
merged 13 commits into from
Jan 15, 2025
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { Suspense } from "react";
import { styled } from "@mui/material/styles";
import { LoadingBackdrop } from "ui";
import { SectionLoader } from "ui";
import { ENTITIES } from "../../utils";

import prioritisationColumns from "../../static_datasets/prioritisationColumns";
import targetSections from "../../../../sections/targetSections";
import evidenceSections from "../../../../sections/evidenceSections";

import { grey } from "@mui/material/colors";

const LoadingContainer = styled("div")({
margin: "25px 0",
height: "100px",
display: "flex",
justifyContent: "center",
alignItems: "center",
gap: "20px",
});
import { Box } from "@mui/material";

const Container = styled("div", {
shouldForwardProp: prop => prop !== "table",
Expand All @@ -30,10 +22,9 @@ const Container = styled("div", {

function LoadingSection() {
return (
<LoadingContainer>
<LoadingBackdrop />
Importing section assets
</LoadingContainer>
<Box sx={{ m: 3 }}>
<SectionLoader />
</Box>
);
}

Expand Down
23 changes: 16 additions & 7 deletions packages/ui/src/components/OtTable/OtTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement, ReactNode, useEffect, useMemo, useState } from "react";
import { ReactElement, ReactNode, useMemo, useState } from "react";
import { Box, Grid, IconButton, NativeSelect, Skeleton } from "@mui/material";
import {
useReactTable,
Expand Down Expand Up @@ -26,7 +26,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import OtTableColumnFilter from "./OtTableColumnFilter";
// import { naLabel } from "../../constants";
import OtTableSearch from "./OtTableSearch";
import { OtTableProps } from "./table.types";
import { OtTableProps } from "./types/tableTypes";
import {
FontAwesomeIconPadded,
OtTableContainer,
Expand All @@ -42,15 +42,17 @@ import {
getDefaultSortObj,
getFilterValueFromObject,
getLoadingRows,
isNestedColumns,
mapTableColumnToTanstackColumns,
} from "./tableUtil";
} from "./utils/tableUtils";
import Tooltip from "../Tooltip";
import OtTableColumnVisibility from "./OtTableColumnVisibility";

declare module "@tanstack/table-core" {
interface FilterFns {
searchFilterFn: FilterFn<unknown>;
}

interface FilterMeta {
itemRank: RankingInfo;
}
Expand Down Expand Up @@ -309,10 +311,17 @@ function OtTable({
}

function getLoadingCells(columms: Array<Record<string, unknown>>) {
return columms.map(column => ({
...column,
cell: () => <Skeleton sx={{ minWidth: "50px" }} variant="text" />,
}));
const arr: Record<string, unknown>[] = [];
columms.forEach(e => {
if (isNestedColumns(e)) {
const headerObj = {
header: e.header || e.label,
columns: getLoadingCells(e.columns),
};
arr.push(headerObj);
} else arr.push({ ...e, cell: () => <Skeleton sx={{ minWidth: "50px" }} variant="text" /> });
});
return arr;
}

export default OtTable;
Loading
Loading