common component props
This commit is contained in:
@@ -5,12 +5,3 @@ export interface LatestItem {
|
|||||||
amount: string;
|
amount: string;
|
||||||
timeAgo: string;
|
timeAgo: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LatestItemsViewProps {
|
|
||||||
items: LatestItem[];
|
|
||||||
header: string;
|
|
||||||
accentColor: string;
|
|
||||||
canExpand: boolean;
|
|
||||||
onExpand: () => void;
|
|
||||||
isFetching?: boolean;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ComponentProps } from "../report.props";
|
|
||||||
import { buildLatestItems } from "./LatestItems.adapter";
|
import { buildLatestItems } from "./LatestItems.adapter";
|
||||||
import LatestItemsView from "./LatestItems.view";
|
import LatestItemsView from "./LatestItems.view";
|
||||||
|
import { LatestItemsProps } from "./LatestItems.props";
|
||||||
|
|
||||||
type Props = ComponentProps;
|
export default function LatestItems(props: LatestItemsProps) {
|
||||||
|
const {
|
||||||
export default function LatestItems({
|
|
||||||
reportData,
|
reportData,
|
||||||
state,
|
state,
|
||||||
stateSetters,
|
stateSetters,
|
||||||
header,
|
|
||||||
accentColor = "",
|
|
||||||
isFetching,
|
isFetching,
|
||||||
}: Props) {
|
} = props;
|
||||||
|
|
||||||
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
||||||
const [visibleCount, setVisibleCount] = React.useState(5);
|
const [visibleCount, setVisibleCount] = React.useState(5);
|
||||||
|
|
||||||
|
// Reset count when flow changes to start clean
|
||||||
|
React.useEffect(() => {
|
||||||
|
setVisibleCount(5);
|
||||||
|
}, [flow]);
|
||||||
|
|
||||||
const allItems = React.useMemo(() => {
|
const allItems = React.useMemo(() => {
|
||||||
return buildLatestItems(reportData, selectedPeriodId, selectedGroupKey, flow);
|
return buildLatestItems(reportData, selectedPeriodId, selectedGroupKey, flow);
|
||||||
}, [reportData, selectedPeriodId, selectedGroupKey, flow]);
|
}, [reportData, selectedPeriodId, selectedGroupKey, flow]);
|
||||||
@@ -28,11 +31,9 @@ export default function LatestItems({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<LatestItemsView
|
<LatestItemsView
|
||||||
|
{...props}
|
||||||
items={visibleItems}
|
items={visibleItems}
|
||||||
header={header}
|
|
||||||
accentColor={accentColor}
|
|
||||||
canExpand={canExpand}
|
canExpand={canExpand}
|
||||||
isFetching={isFetching}
|
|
||||||
onExpand={() => setVisibleCount((prev) => prev + 5)}
|
onExpand={() => setVisibleCount((prev) => prev + 5)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,21 +10,23 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
import { LatestItemsViewProps } from "./LatestItems.models";
|
import { LatestItemsViewProps } from "./LatestItems.props";
|
||||||
|
|
||||||
export default function LatestItemsView({
|
export default function LatestItemsView({
|
||||||
items,
|
items,
|
||||||
header,
|
title,
|
||||||
accentColor,
|
|
||||||
canExpand,
|
canExpand,
|
||||||
onExpand,
|
onExpand,
|
||||||
isFetching,
|
isFetching,
|
||||||
|
colorScheme,
|
||||||
}: LatestItemsViewProps) {
|
}: LatestItemsViewProps) {
|
||||||
|
const accentColor = colorScheme?.primary || "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: "100%", bgcolor: "background.paper", borderRadius: 4, p: 2, opacity: isFetching ? 0.6 : 1, transition: "opacity 0.3s ease", pointerEvents: isFetching ? "none" : "auto" }}>
|
<Box sx={{ width: "100%", bgcolor: "background.paper", borderRadius: 4, p: 2, opacity: isFetching ? 0.6 : 1, transition: "opacity 0.3s ease", pointerEvents: isFetching ? "none" : "auto" }}>
|
||||||
<Box sx={{ mb: 2, px: 2 }}>
|
<Box sx={{ mb: 2, px: 2 }}>
|
||||||
<Typography variant="h6" fontWeight="bold">
|
<Typography variant="h6" fontWeight="bold">
|
||||||
{header}
|
{title}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user