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

adds substantial completion date tooltip #1454

Open
wants to merge 11 commits into
base: 19257_show_substantial_completion_date_plus_advanced_search
Choose a base branch
from
2 changes: 2 additions & 0 deletions moped-editor/src/constants/projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const substantialCompletionDateTooltipText =
"The earliest confirmed start date of a project phase that has a simple phase name of Complete (Complete or Post-construction)";
9 changes: 9 additions & 0 deletions moped-editor/src/queries/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,3 +1021,12 @@ export const GET_PROJECTS_GEOGRAPHIES = gql`
}
}
`;

export const GET_PROJECT_SUBSTANTIAL_COMPLETION_DATE = gql`
query MopedProjectCompletionDate($projectId: Int) {
project_list_view(where: { project_id: { _eq: $projectId } }) {
substantial_completion_date
project_id
}
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const useStyles = makeStyles((theme) => ({
width: "100%",
color: theme.palette.text.secondary,
fontSize: ".8rem",
margin: "8px 0",
},
fieldBox: {
maxWidth: "10rem",
Expand Down
17 changes: 10 additions & 7 deletions moped-editor/src/views/projects/projectView/ProjectPhaseToolbar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { Box, Typography } from "@mui/material";
import ButtonDropdownMenu from "src/components/ButtonDropdownMenu";
import ProjectSubstantialCompletionDate from "./ProjectSubstantialCompletionDate";

/** Custom toolbar title that resembles material table titles */
const ProjectPhaseToolbar = ({ addAction, setIsDialogOpen }) => (
<Box display="flex" justifyContent="space-between">
<Typography variant="h2" color="primary" style={{ padding: "1em" }}>
Phases
</Typography>
const ProjectPhaseToolbar = ({ addAction, setIsDialogOpen, completionDate }) => (
<Box display="flex" justifyContent="space-between" sx={{ margin: "1em" }}>
<div>
<Typography variant="h2" color="primary" style={{ paddingTop: "1em" }}>
Phases
</Typography>
<ProjectSubstantialCompletionDate completionDate={completionDate} />
</div>
<div style={{ padding: "1rem" }}>
<ButtonDropdownMenu
addAction={addAction}
Expand Down
25 changes: 21 additions & 4 deletions moped-editor/src/views/projects/projectView/ProjectPhases.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo, useState } from "react";
import { useMutation } from "@apollo/client";
import { useMutation, useQuery } from "@apollo/client";
import { CircularProgress, Box, IconButton } from "@mui/material";
import { DataGridPro } from "@mui/x-data-grid-pro";
import { green } from "@mui/material/colors";
Expand All @@ -12,7 +12,10 @@ import ProjectPhaseToolbar from "./ProjectPhaseToolbar";
import PhaseTemplateModal from "./PhaseTemplateModal";
import ProjectPhaseDialog from "./ProjectPhaseDialog";
import ProjectPhaseDateConfirmationPopover from "./ProjectPhaseDateConfirmationPopover";
import { DELETE_PROJECT_PHASE } from "src/queries/project";
import {
DELETE_PROJECT_PHASE,
GET_PROJECT_SUBSTANTIAL_COMPLETION_DATE,
} from "src/queries/project";
import {
useCurrentProjectPhaseIDs,
useCurrentPhaseIds,
Expand Down Expand Up @@ -157,6 +160,13 @@ const ProjectPhases = ({ projectId, data, refetch }) => {
const [deletePhase, { loading: deleteInProgress }] =
useMutation(DELETE_PROJECT_PHASE);

const { data: completionDateData, refetch: refetchCompletionDate } = useQuery(
GET_PROJECT_SUBSTANTIAL_COMPLETION_DATE,
{
variables: { projectId: Number(projectId) },
}
);

const onClickAddPhase = () => setEditPhase({ project_id: projectId });

const onDeletePhase = useCallback(
Expand All @@ -167,9 +177,10 @@ const ProjectPhases = ({ projectId, data, refetch }) => {
refetchQueries: ["ProjectSummary"],
}).then(() => {
refetch();
refetchCompletionDate();
});
},
[deletePhase, refetch]
[deletePhase, refetch, refetchCompletionDate]
);

const columns = useColumns({
Expand All @@ -187,8 +198,13 @@ const ProjectPhases = ({ projectId, data, refetch }) => {

const subphaseNameLookup = useSubphaseNameLookup(data?.moped_subphases || []);

const completionDate =
completionDateData?.project_list_view[0]["substantial_completion_date"];

const onSubmitCallback = () => {
refetch().then(() => setEditPhase(null));
refetchCompletionDate().then(() =>
refetch().then(() => setEditPhase(null))
);
};

return (
Expand All @@ -212,6 +228,7 @@ const ProjectPhases = ({ projectId, data, refetch }) => {
toolbar: {
addAction: onClickAddPhase,
setIsDialogOpen: setIsTemplateDialogOpen,
completionDate: completionDate,
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Box, Typography, Tooltip } from "@mui/material";
import makeStyles from "@mui/styles/makeStyles";
import { formatDateType } from "src/utils/dateAndTime";
import { substantialCompletionDateTooltipText } from "src/constants/projects";

const useStyles = makeStyles((theme) => ({
fieldLabel: {
width: "100%",
color: theme.palette.text.secondary,
fontSize: ".8rem",
},
fieldBox: {
maxWidth: "10rem",
},
fieldLabelText: {
width: "calc(100% - 2rem)",
},
}));

const ProjectSubstantialCompletionDate = ({ completionDate }) => {
const classes = useStyles();
return (
<>
<Typography className={classes.fieldLabel}>
Substantial completion date
</Typography>
<Box
display="flex"
justifyContent="flex-start"
className={classes.fieldBox}
>
<Tooltip
placement="bottom-start"
title={substantialCompletionDateTooltipText}
>
<Typography className={classes.fieldLabelText} component="span">
{
// If there is no input, render a "-"
completionDate ? formatDateType(completionDate) : "-"
}
</Typography>
</Tooltip>
</Box>
</>
);
};

export default ProjectSubstantialCompletionDate;
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export const useColumns = ({ hiddenColumns }) => {
{
headerName: "Substantial completion date",
field: "substantial_completion_date",
description: "The earliest confirmed start date of a project phase that has a simple phase name of Complete (Complete or Post-construction)",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌 @chiaberry @tillyw Could y'all coordinate for someone to make this description into a variable to hold this string so we can reference it in this PR and in #1456? We may end up adding this in the Data Dictionary too so it could help us update the definition if we ever need to in the future.

I looked in the codebase, and maybe we could add a new file in src/constants to hold tooltip text. What do y'all think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this to my branch, trying to decide what to name the file, projects.js sound okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it here: a60747a

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, @chiaberry!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chiaberry sorry i merged your entire branch into this one when i should have just merged this one commit! i'll just make sure to merge this one last out of the substantial completion date PRs

valueFormatter: (value) => value && formatDateType(value),
width: COLUMN_WIDTHS.small,
},
Expand Down