Skip to content

Commit

Permalink
fix(datable): update the datatbale and detail skeleton closes2307
Browse files Browse the repository at this point in the history
  • Loading branch information
kaminderpal committed Jun 28, 2024
1 parent ea40b81 commit a39ac5b
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useTheme } from '@mui/material/styles';
import { delay } from 'lodash';
import { Box, FilterAltIcon, Skeleton } from '@/ui';
import { Box, FilterAltIcon } from '@/ui';
import DataTable from './data-table';
import {
useDataTableSelectedLayerPath,
Expand All @@ -24,6 +24,7 @@ import { CONTAINER_TYPE, LAYER_STATUS, TABS } from '@/core/utils/constant';
import { MappedLayerDataType } from './data-table-types';
import { CV_DEFAULT_APPBAR_CORE } from '@/api/config/types/config-constants';
import { TypeContainerBox } from '@/core/types/global-types';
import DataSkeleton from './data-skeleton';

interface DataPanelType {
fullWidth?: boolean;
Expand Down Expand Up @@ -219,7 +220,7 @@ export function Datapanel({ fullWidth = false, containerType = CONTAINER_TYPE.FO
*/
const renderContent = (): JSX.Element | null => {
if (isLoading || memoIsLayerQueryStatusProcessing()) {
return <Skeleton variant="rounded" width="100%" height={400} sx={{ bgcolor: theme.palette.grey[400] }} />;
return <DataSkeleton />;
}
if (!isLayerDisabled() && isSelectedLayerHasFeatures()) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useTheme } from '@mui/material/styles';
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Skeleton } from '@/ui';

/**
* Custom data table skeleton build with table and mui skelton
* @returns {JSX.Element}
*/
export default function DataSkeleton(): JSX.Element {
const theme = useTheme();

return (
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
{[...Array(5).keys()].map((value) => (
<TableCell sx={{ width: '20%' }} key={value}>
<Skeleton variant="text" width="100%" height="25px" sx={{ bgcolor: theme.palette.grey[400] }} />
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{[...Array(6).keys()].map((row) => (
<TableRow key={row} sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>
{[...Array(5).keys()].map((value) => (
<TableCell sx={{ width: '20%' }} key={value}>
<Skeleton variant="text" width="100%" height="25px" sx={{ bgcolor: theme.palette.grey[400] }} />
</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DialogActions,
DialogTitle,
DialogContent,
Table,
MRTTable as Table,
type MRT_ColumnDef as MRTColumnDef,
Box,
CircularProgress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useTheme } from '@mui/material/styles';
import { IconButton, Grid, ArrowForwardIosOutlinedIcon, ArrowBackIosOutlinedIcon, LayersClearOutlinedIcon, Box, Skeleton } from '@/ui';
import { IconButton, Grid, ArrowForwardIosOutlinedIcon, ArrowBackIosOutlinedIcon, LayersClearOutlinedIcon, Box } from '@/ui';
import {
useDetailsStoreActions,
useDetailsCheckedFeatures,
Expand All @@ -16,6 +16,7 @@ import { LayerListEntry, Layout } from '@/core/components/common';
import { getSxClasses } from './details-style';
import { FeatureInfo } from './feature-info-new';
import { LAYER_STATUS } from '@/core/utils/constant';
import DetailsSkeleton from './details-skeleton';

interface DetailsPanelType {
fullWidth?: boolean;
Expand Down Expand Up @@ -430,7 +431,8 @@ export function DetailsPanel({ fullWidth = false }: DetailsPanelType): JSX.Eleme
*/
const renderContent = (): JSX.Element | null => {
if (memoIsAllLayersQueryStatusProcessing()) {
return <Skeleton variant="rounded" width="100%" height={500} sx={{ bgcolor: theme.palette.grey[400] }} />;
// return <Skeleton variant="rounded" width="100%" height={500} sx={{ bgcolor: theme.palette.grey[400] }} />;
return <DetailsSkeleton />;
}
if (memoSelectedLayerDataFeatures && memoSelectedLayerDataFeatures.length > 0) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Box, Skeleton } from '@/ui';

/**
* Custom details skeleton build with mui skeleton component.
* @returns {JSX.Element}
*/
export default function DetailsSkeleton(): JSX.Element {
const sizes = ['15%', '10%', '15%', '25%', '10%', '20%', '10%'];
return (
<Box padding={8}>
<Box pb={8}>
{sizes.map((size) => (
<Box display="flex" justifyContent="space-between" pt={4} pb={4} key={size.toString()}>
<Skeleton variant="text" width={size} height="25px" />
<Skeleton variant="text" width={size} height="25px" />
</Box>
))}
</Box>
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type ButtonDropDownProps = ButtonGroupProps & {
export function ButtonDropDown(props: ButtonDropDownProps): JSX.Element {
// #region PROPS ****************************************************************************************************

const { options, onButtonClick, ...otherProps } = props;
const { options, onButtonClick = null, ...otherProps } = props;

const theme = useTheme();
const sxClasses = getSxClasses(theme);
Expand Down Expand Up @@ -126,8 +126,3 @@ export function ButtonDropDown(props: ButtonDropDownProps): JSX.Element {

// #endregion
}

// TODO: Refactor - Remove defaultProps as it's no longer a good practice
ButtonDropDown.defaultProps = {
onButtonClick: null,
};
1 change: 1 addition & 0 deletions packages/geoview-core/src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ export * from './toolbar/toolbar';
export * from './tooltip/tooltip';
export * from './typography/typography';
export * from './popper/popper';
export { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material';
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type CheckboxListItem = {
* @returns JSX.Element The Component
*/
export function CheckboxList(props: CheckboxListProps): JSX.Element {
const { listItems, checkedValues, multiselect, onChecked } = props;
const { listItems, checkedValues, multiselect, onChecked = null } = props;

const theme = useTheme();
const sxClasses = getSxClasses(theme);
Expand Down Expand Up @@ -111,11 +111,3 @@ export function CheckboxList(props: CheckboxListProps): JSX.Element {
</List>
);
}

/**
* React's default properties for the CheckboxList
*/
// TODO: Refactor - Remove defaultProps as it's no longer a good practice
CheckboxList.defaultProps = {
onChecked: null,
};
2 changes: 1 addition & 1 deletion packages/geoview-core/src/ui/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MaterialReactTable, MRT_TableOptions as MRTTableOptions, type MRT_RowDa
* @param {MRTTableOptions} props props defined by material react table library.
* @returns {JSX.Element}
*/
export function Table<TData extends MRTRowData>(tableOptions: MRTTableOptions<TData>): JSX.Element {
export function MRTTable<TData extends MRTRowData>(tableOptions: MRTTableOptions<TData>): JSX.Element {
return <MaterialReactTable {...tableOptions} />;
}

Expand Down

0 comments on commit a39ac5b

Please sign in to comment.