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

Fix box chart empty condition #2838

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/components/charts/BoxBarChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
sum,
getColorOnBgColor,
isDefined,
isNotDefined,
} from '@togglecorp/fujs';
import {
ContainerCard,
Expand Down Expand Up @@ -70,6 +71,9 @@ function BoxBarChart<
} = props;

const finalData = useMemo(() => {
if (isNotDefined(data) || data?.length <= 0) {
return [];
}
const itemsGroupedByRow = listToGroupList(
data ?? [],
rowSelector,
Expand Down Expand Up @@ -139,12 +143,12 @@ function BoxBarChart<
borderBelowHeaderWidth="thin"
>
{((data?.length ?? 0) === 0 && loading) && <PendingMessage />}
{finalData.length === 0 && <Message empty /> }
{isDefined(data) && finalData.length === 0 && <Message empty /> }
<div className={styles.content}>
{isDefined(data) && (
{isDefined(data) && finalData.length > 0 && (
<div className={styles.row}>
<div />
{columns.map((column) => (
{columns?.map((column) => (
<div
className={_cs(
styles.cell,
Expand All @@ -159,15 +163,15 @@ function BoxBarChart<
<div />
</div>
)}
{finalData.map((item) => (
{finalData?.map((item) => (
<div
key={item.rowLabel}
className={styles.row}
>
<div className={_cs(styles.cell, styles.label)}>
{item.rowLabel}
</div>
{item.columnsForRow.map((countItem, index) => {
{item.columnsForRow?.map((countItem, index) => {
const bgColor = getColorForValue(countItem);

return (
Expand Down
1 change: 1 addition & 0 deletions app/gqlFragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const LAST_ACTIVE_PROJECT_FRAGMENT = gql`
membershipPending
enablePubliclyViewableAnalysisReportSnapshot
isRejected
createdAt
}
`;

Expand Down
28 changes: 11 additions & 17 deletions app/views/AryDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
import { gql, useQuery } from '@apollo/client';
import { removeNull } from '@togglecorp/toggle-form';

import {
todaysDate,
lastYearStartDate,
DEEP_START_DATE,
} from '#utils/common';
import { lastYearStartDate, todaysDate } from '#utils/common';
import { resolveTime } from '#utils/temporal';
import ProjectContext from '#base/context/ProjectContext';
import {
Expand Down Expand Up @@ -199,10 +195,16 @@ function AryDashboard(props: Props) {
const [selectedRegion, setSelectedRegion] = useState<string>();
const [activeAdminLevel, setActiveAdminLevel] = useState<string>();

const activeProjectStartDate = resolveTime(
project?.createdAt ? new Date(project?.createdAt) : lastYearStartDate,
'day',
).getTime();
// eslint-disable-next-line max-len
const projectStartDate = Math.max(activeProjectStartDate, new Date(lastYearStartDate).getTime());
const [
startDate = todaysDateTime,
startDate = projectStartDate,
setStartDate,
] = useState<number | undefined>(todaysDateTime);
] = useState<number | undefined>(projectStartDate);
const [
endDate = todaysDateTime,
setEndDate,
Expand Down Expand Up @@ -234,11 +236,6 @@ function AryDashboard(props: Props) {
skip: !activeProject,
variables: activeProject ? { projectId: activeProject } : undefined,
onCompleted: (response) => {
const projectStartDate = resolveTime(
new Date(response.project?.createdAt ?? todaysDateTime),
'day',
).getTime();
setStartDate(Math.max(projectStartDate, new Date(lastYearStartDate).getTime()));
setSelectedRegion(response.project?.regions?.[0].id);

if (isDefined(activeAdminLevel)) {
Expand Down Expand Up @@ -293,9 +290,6 @@ function AryDashboard(props: Props) {
}, [projectMetadata]);

const projectData = removeNull(data?.project);
const projectStartDate = useMemo(() => (
resolveTime(new Date(projectMetadata?.createdAt ?? DEEP_START_DATE), 'day').getTime()
), [projectMetadata?.createdAt]);

const handleEndDateChange = useCallback((newDate: number | undefined) => {
if (isDefined(newDate)) {
Expand Down Expand Up @@ -427,7 +421,7 @@ function AryDashboard(props: Props) {
regions={projectMetadata?.regions}
filters={filters}
projectId={activeProject}
projectStartDate={projectStartDate}
projectStartDate={activeProjectStartDate}
startDate={startDate}
endDate={endDate}
onStartDateChange={setStartDate}
Expand Down Expand Up @@ -472,7 +466,7 @@ function AryDashboard(props: Props) {
onRegionChange={handleRegionChange}
selectedAdminLevel={activeAdminLevel}
onAdminLevelChange={setActiveAdminLevel}
projectStartDate={projectStartDate}
projectStartDate={activeProjectStartDate}
startDate={startDate}
endDate={endDate}
onStartDateChange={setStartDate}
Expand Down
Loading