Skip to content

Commit

Permalink
Fix Duration filter in dashboards and add contentLoader in respond,al…
Browse files Browse the repository at this point in the history
…ert,watch cards
  • Loading branch information
anagperal committed Oct 11, 2024
1 parent e1b3a19 commit ea0e609
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
18 changes: 11 additions & 7 deletions src/webapp/components/date-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ const ID = "date-range-picker";
export const DateRangePicker: React.FC<DateRangePickerProps> = React.memo(
({ label = "", value, placeholder = "", onChange }) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [startDate, setStartDate] = useState<Date | null>(null);
const [endDate, setEndDate] = useState<Date | null>(null);
const [startDate, setStartDate] = useState<Date | null>(
value && value[0] ? new Date(value[0]) : null
);
const [endDate, setEndDate] = useState<Date | null>(
value && value[1] ? new Date(value[1]) : null
);

const handleOpen = useCallback((event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
Expand All @@ -41,14 +45,14 @@ export const DateRangePicker: React.FC<DateRangePickerProps> = React.memo(
}, [onCleanValues, value.length]);

const formatDurationValue = useMemo(() => {
if (!value || value.length !== 2) {
if (!value || value.length !== 2 || !value[0] || !value[1]) {
return placeholder;
}

return `${moment(startDate).format("DD/MM/yyyy")}${moment(endDate).format(
"DD/MM/yyyy"
)}`;
}, [startDate, endDate, placeholder, value]);
return `${moment(new Date(value[0])).format("DD/MM/yyyy")}${moment(
new Date(value[1])
).format("DD/MM/yyyy")}`;
}, [placeholder, value]);

const onReset = useCallback(() => {
onChange([]);
Expand Down
25 changes: 14 additions & 11 deletions src/webapp/pages/dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DateRangePicker } from "../../components/date-picker/DateRangePicker";
import { PerformanceMetric717, use717Performance } from "./use717Performance";
import { Loader } from "../../components/loader/Loader";
import { useLastAnalyticsRuntime } from "../../hooks/useLastAnalyticsRuntime";
import LoaderContainer from "../../components/loader/LoaderContainer";

export const DashboardPage: React.FC = React.memo(() => {
const {
Expand Down Expand Up @@ -54,7 +55,7 @@ export const DashboardPage: React.FC = React.memo(() => {
resetCurrentEventTrackerId();
});

return performanceOverviewLoading || _717CardsLoading || cardCountsLoading ? (
return performanceOverviewLoading || _717CardsLoading ? (
<Loader />
) : (
<Layout
Expand Down Expand Up @@ -103,16 +104,18 @@ export const DashboardPage: React.FC = React.memo(() => {
/>
</FilterContainer>
</FiltersContainer>
<GridWrapper>
{cardCounts.map((cardCount, index) => (
<StyledStatsCard
key={index}
stat={cardCount.total.toString()}
title={i18n.t(cardCount.name)}
fillParent
/>
))}
</GridWrapper>
<LoaderContainer loading={cardCountsLoading}>
<GridWrapper>
{cardCounts.map((cardCount, index) => (
<StyledStatsCard
key={index}
stat={cardCount.total.toString()}
title={i18n.t(cardCount.name)}
fillParent
/>
))}
</GridWrapper>
</LoaderContainer>
</Section>
<Section title={i18n.t("All public health events")}>
<MapSection
Expand Down

0 comments on commit ea0e609

Please sign in to comment.