Skip to content

Commit 4bc8d20

Browse files
committed
Fixed conflicts
1 parent beb2ad6 commit 4bc8d20

File tree

3 files changed

+134
-74
lines changed

3 files changed

+134
-74
lines changed

src/apps/content-editor/src/app/views/ItemList/ItemListTable.tsx

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ import {
1313
useMemo,
1414
useState,
1515
useContext,
16+
useEffect,
1617
} from "react";
1718
import AutoSizer, { Size } from "react-virtualized-auto-sizer";
18-
import { ContentItem } from "../../../../../../shell/services/types";
19+
import {
20+
ContentItem,
21+
ContentModelField,
22+
} from "../../../../../../shell/services/types";
1923
import { useStagedChanges } from "./StagedChangesContext";
2024
import { OneToManyCell } from "./TableCells/OneToManyCell";
2125
import { UserCell } from "./TableCells/UserCell";
@@ -29,6 +33,12 @@ import { Currency } from "../../../../../../shell/components/FieldTypeCurrency/c
2933
import { ImageCell } from "./TableCells/ImageCell";
3034
import { SingleRelationshipCell } from "./TableCells/SingleRelationshipCell";
3135
import { TableSortContext } from "./TableSortProvider";
36+
import {
37+
FIELD_SKELETON_MAP,
38+
gridLoadingStyles,
39+
SkeletonLoadingOverlay,
40+
} from "./Loader";
41+
import { Skeleton } from "@mui/material";
3242

3343
type ItemListTableProps = {
3444
loading: boolean;
@@ -67,7 +77,6 @@ const METADATA_COLUMNS = [
6777
width: 240,
6878
filterable: true,
6979
renderCell: (params: GridRenderCellParams) => <UserCell params={params} />,
70-
type: "createdBy",
7180
},
7281
{
7382
field: "createdOn",
@@ -263,8 +272,6 @@ export const ItemListTable = memo(
263272
const [sortModel, setSortModel] = useContext(TableSortContext);
264273
const [pinnedColumns, setPinnedColumns] = useState({});
265274

266-
const { data: fields } = useGetContentModelFieldsQuery(modelZUID);
267-
268275
const saveSnapshot = useCallback(() => {
269276
if (apiRef?.current?.exportState && localStorage) {
270277
const currentState = apiRef.current.exportState();
@@ -297,6 +304,12 @@ export const ItemListTable = memo(
297304
}, [saveSnapshot, fields, modelZUID]);
298305

299306
const columns = useMemo(() => {
307+
const stateFromLocalStorage = localStorage?.getItem(
308+
`${modelZUID}-dataGridState`
309+
);
310+
const colDimensions = stateFromLocalStorage
311+
? JSON.parse(stateFromLocalStorage)?.columns?.dimensions
312+
: null;
300313
let result: any[] = [
301314
{
302315
field: "version",
@@ -307,7 +320,6 @@ export const ItemListTable = memo(
307320
renderCell: (params: GridRenderCellParams) => (
308321
<VersionCell params={params} />
309322
),
310-
type: "version",
311323
},
312324
];
313325
if (fields) {
@@ -336,33 +348,34 @@ export const ItemListTable = memo(
336348
field?.settings?.options?.[1] !== "Yes" && {
337349
width: 280,
338350
}),
339-
type: field.datatype,
340351
})),
341352
];
342353
}
343-
return [...result, ...METADATA_COLUMNS];
344-
}, [fields]);
345-
346-
if (!initialState) {
347-
return (
348-
<Box
349-
display="flex"
350-
justifyContent="center"
351-
alignItems="center"
352-
height="100%"
353-
>
354-
<CircularProgress />
355-
</Box>
356-
);
357-
}
354+
result = [
355+
...result,
356+
...METADATA_COLUMNS?.map((column) => ({
357+
...column,
358+
flex: loading && !fields ? 1 : 0,
359+
})),
360+
];
361+
return result.map((column) => {
362+
const { headerName, ...other } = column;
363+
return {
364+
...other,
365+
width: colDimensions?.[column.field]?.width || column.width,
366+
renderHeader: () =>
367+
loading ? FIELD_SKELETON_MAP.header : headerName,
368+
};
369+
});
370+
}, [fields, loading]);
358371

359372
return (
360373
<AutoSizer>
361374
{({ width, height }: Size) => (
362375
<DataGridPro
363376
apiRef={apiRef}
364377
loading={loading}
365-
rows={rows}
378+
rows={loading ? [] : rows}
366379
columns={columns}
367380
style={{
368381
width,
@@ -393,12 +406,19 @@ export const ItemListTable = memo(
393406
}}
394407
slots={{
395408
noRowsOverlay: noRowsOverlay,
396-
baseCheckbox: (props: any) => (
397-
<Checkbox
398-
disabled={stagedChanges && Object.keys(stagedChanges)?.length}
399-
{...props}
400-
/>
401-
),
409+
baseCheckbox: (props: any) =>
410+
loading ? (
411+
<Skeleton variant="rounded" width="18px" height="18px" />
412+
) : (
413+
<Checkbox
414+
disabled={
415+
stagedChanges && Object.keys(stagedChanges)?.length
416+
}
417+
{...props}
418+
/>
419+
),
420+
421+
loadingOverlay: () => <SkeletonLoadingOverlay fields={fields} />,
402422
}}
403423
slotProps={{
404424
baseTooltip: {
@@ -453,6 +473,7 @@ export const ItemListTable = memo(
453473
params.row?.meta?.version &&
454474
!(stagedChanges && Object.keys(stagedChanges)?.length)
455475
}
476+
onColumnWidthChange={saveSnapshot}
456477
sx={{
457478
backgroundColor: "common.white",
458479
".MuiDataGrid-row": {
@@ -495,6 +516,7 @@ export const ItemListTable = memo(
495516
"& [data-cy='NoResults']": {
496517
pointerEvents: "all",
497518
},
519+
...(loading ? gridLoadingStyles : {}),
498520
}}
499521
/>
500522
)}

src/apps/content-editor/src/app/views/ItemList/SkeletonLoader.tsx renamed to src/apps/content-editor/src/app/views/ItemList/Loader.tsx

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@ import {
22
useGridApiContext,
33
gridColumnsTotalWidthSelector,
44
gridColumnPositionsSelector,
5-
gridDensityRowHeightSelector,
65
} from "@mui/x-data-grid-pro";
76
import { ReactNode, useMemo } from "react";
87
import { Box, Skeleton } from "@mui/material";
98
import ImageRoundedIcon from "@mui/icons-material/ImageRounded";
109
import Typography from "@mui/material/Typography";
10+
import { ContentModelField } from "../../../../../../shell/services/types";
11+
12+
export const gridLoadingStyles = {
13+
pointerEvents: "none",
14+
"& .MuiDataGrid-virtualScroller": {
15+
overflow: "hidden",
16+
},
17+
"& .MuiDataGrid-columnHeader .MuiDataGrid-iconButtonContainer": {
18+
visibility: "hidden!important",
19+
},
20+
"& .MuiDataGrid-columnSeparator": {
21+
visibility: "hidden!important",
22+
},
23+
};
1124

1225
const CellWrapper = ({
1326
align = "left",
@@ -165,8 +178,14 @@ export const FIELD_SKELETON_MAP: Record<string, JSX.Element> = {
165178
alignItems="center"
166179
justifyContent="flex-start"
167180
position="absolute"
181+
pr={2}
168182
>
169-
<Skeleton height={12} width="70%" />
183+
<Skeleton
184+
variant="rounded"
185+
height="12px"
186+
width="calc(100% - 16px)"
187+
sx={{ maxWidth: "180px" }}
188+
/>
170189
</Box>
171190
),
172191
default: (
@@ -181,14 +200,19 @@ export const FIELD_SKELETON_MAP: Record<string, JSX.Element> = {
181200
),
182201
};
183202

184-
export const SkeletonLoadingOverlay = () => {
203+
export const SkeletonLoadingOverlay = ({
204+
fields,
205+
}: {
206+
fields?: ContentModelField[];
207+
}) => {
185208
const apiRef = useGridApiContext();
186209

187210
const dimensions = apiRef.current?.getRootDimensions();
188211
const viewportHeight = dimensions?.viewportInnerSize.height ?? 0;
189-
190-
const rowHeight = gridDensityRowHeightSelector(apiRef);
191-
const skeletonRowsCount = Math.ceil(viewportHeight / rowHeight);
212+
const rowHeight = apiRef.current.state.dimensions.rowHeight;
213+
const skeletonRowsCount = Math.ceil(
214+
viewportHeight / apiRef.current.state.dimensions.rowHeight
215+
);
192216

193217
const totalWidth = gridColumnsTotalWidthSelector(apiRef);
194218
const positions = gridColumnPositionsSelector(apiRef);
@@ -198,6 +222,23 @@ export const SkeletonLoadingOverlay = () => {
198222
);
199223
const columns = apiRef.current.getVisibleColumns().slice(0, inViewportCount);
200224

225+
const COL_TYPE_MAP = useMemo(() => {
226+
const typesMap = fields?.reduce((acc, field) => {
227+
acc[field.name] = field.datatype;
228+
return acc;
229+
}, {} as Record<string, string>);
230+
return {
231+
...typesMap,
232+
createdBy: "createdBy",
233+
createdOn: "text",
234+
lastSaved: "text",
235+
lastPublished: "text",
236+
zuid: "text",
237+
version: "version",
238+
__check__: "checkboxSelection",
239+
};
240+
}, [fields]);
241+
201242
const children = useMemo(() => {
202243
const array: ReactNode[] = [];
203244

@@ -217,7 +258,11 @@ export const SkeletonLoadingOverlay = () => {
217258
borderColor: "border",
218259
}}
219260
>
220-
{FIELD_SKELETON_MAP[column.type] || FIELD_SKELETON_MAP.default}
261+
{FIELD_SKELETON_MAP[
262+
COL_TYPE_MAP[
263+
column.field as keyof typeof COL_TYPE_MAP
264+
] as keyof typeof FIELD_SKELETON_MAP
265+
] || FIELD_SKELETON_MAP.default}
221266
</Box>
222267
);
223268
}

src/apps/content-editor/src/app/views/ItemList/index.tsx

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "react";
1919
import { SearchRounded, RestartAltRounded } from "@mui/icons-material";
2020
import noSearchResults from "../../../../../../../public/images/noSearchResults.svg";
21+
import { ItemListFilters } from "./ItemListFilters";
2122
import { useParams } from "../../../../../../shell/hooks/useParams";
2223
import { useDispatch, useSelector } from "react-redux";
2324
import { AppState } from "../../../../../../shell/store/types";
@@ -36,7 +37,7 @@ import { fetchItems } from "../../../../../../shell/store/content";
3637
import { TableSortContext } from "./TableSortProvider";
3738
import { fetchFields } from "../../../../../../shell/store/fields";
3839
import { debounce } from "lodash";
39-
import { SkeletonContentHeader } from "./SkeletonLoader";
40+
import { SkeletonContentHeader, SkeletonItemListFilters } from "./Loader";
4041

4142
const dateFormatter = new Intl.DateTimeFormat("en-US", {
4243
year: "numeric",
@@ -79,9 +80,7 @@ export const ItemList = () => {
7980
useGetContentModelQuery(modelZUID);
8081
const { data: fields, isFetching: isFieldsFetching } =
8182
useGetContentModelFieldsQuery(modelZUID);
82-
const { data: languages, isLoading: isLanguagesLoading } = useGetLangsQuery(
83-
{}
84-
);
83+
const { data: languages } = useGetLangsQuery({});
8584
const activeLangId =
8685
languages?.find((lang) => lang.code === activeLanguageCode)?.ID || 1;
8786
const allItems = useSelector((state: AppState) => state.content);
@@ -95,11 +94,7 @@ export const ItemList = () => {
9594

9695
const allFields = useSelector((state: AppState) => state.fields);
9796
const user = useSelector((state: AppState) => state.user);
98-
const {
99-
data: users,
100-
isFetching: isUsersFetching,
101-
isLoading: isUsersLoading,
102-
} = useGetUsersQuery();
97+
const { data: users, isFetching: isUsersFetching } = useGetUsersQuery();
10398
const [processedItems, setProcessedItems] = useState([]);
10499
const [isModelItemsFetching, setIsModelItemsFetching] = useState(true);
105100
const [sortModel] = useContext(TableSortContext);
@@ -586,34 +581,30 @@ export const ItemList = () => {
586581
{(stagedChanges && Object.keys(stagedChanges)?.length) ||
587582
selectedItems?.length ? (
588583
<UpdateListActions items={items as ContentItem[]} />
584+
) : isModelFetching ? (
585+
<SkeletonContentHeader />
589586
) : (
590587
<>
591-
{isUsersLoading || isLanguagesLoading || isModelFetching ? (
592-
<SkeletonContentHeader />
593-
) : (
594-
<>
595-
<Box flex={1}>
596-
<ContentBreadcrumbs />
597-
<Typography
598-
variant="h3"
599-
mt={0.25}
600-
fontWeight={700}
601-
sx={{
602-
display: "-webkit-box",
603-
"-webkit-line-clamp": "2",
604-
"-webkit-box-orient": "vertical",
605-
wordBreak: "break-word",
606-
wordWrap: "break-word",
607-
hyphens: "auto",
608-
overflow: "hidden",
609-
}}
610-
>
611-
{model?.label}
612-
</Typography>
613-
</Box>
614-
<ItemListActions ref={searchRef} />
615-
</>
616-
)}
588+
<Box flex={1}>
589+
<ContentBreadcrumbs />
590+
<Typography
591+
variant="h3"
592+
mt={0.25}
593+
fontWeight={700}
594+
sx={{
595+
display: "-webkit-box",
596+
"-webkit-line-clamp": "2",
597+
"-webkit-box-orient": "vertical",
598+
wordBreak: "break-word",
599+
wordWrap: "break-word",
600+
hyphens: "auto",
601+
overflow: "hidden",
602+
}}
603+
>
604+
{model?.label}
605+
</Typography>
606+
</Box>
607+
<ItemListActions ref={searchRef} />
617608
</>
618609
)}
619610
</Box>
@@ -630,13 +621,15 @@ export const ItemList = () => {
630621
<ItemListEmpty />
631622
) : (
632623
<>
624+
{isFieldsFetching || isUsersFetching ? (
625+
<SkeletonItemListFilters />
626+
) : (
627+
<ItemListFilters />
628+
)}
633629
<ItemListTable
634630
key={modelZUID}
635631
loading={
636-
isFieldsFetching ||
637-
isUsersFetching ||
638-
isModelItemsFetching ||
639-
isModelFetching
632+
isFieldsFetching || isUsersFetching || isModelItemsFetching
640633
}
641634
rows={sortedAndFilteredItems}
642635
fields={fields}

0 commit comments

Comments
 (0)