-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1211 from cityofaustin/14560-jc-atd-calculated-fi…
…elds Add `substantial_completion_date` to project and component views
- Loading branch information
Showing
22 changed files
with
3,143 additions
and
440 deletions.
There are no files selected for viewing
625 changes: 625 additions & 0 deletions
625
moped-database/migrations/1704744986000_substantial_completion_date/down.sql
Large diffs are not rendered by default.
Oops, something went wrong.
453 changes: 453 additions & 0 deletions
453
moped-database/migrations/1704744986000_substantial_completion_date/up.sql
Large diffs are not rendered by default.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
moped-database/migrations/1704906960000_remove_phase_confirm_trigger/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- revert to 1697679713991_confirmed_date_trigger | ||
CREATE OR REPLACE FUNCTION moped_proj_phases_confirmed_dates() RETURNS trigger | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
IF NEW.phase_start <= current_date AND NEW.is_phase_start_confirmed != TRUE THEN | ||
new.is_phase_start_confirmed := true; | ||
END IF; | ||
IF NEW.phase_end <= current_date AND NEW.is_phase_end_confirmed != TRUE THEN | ||
new.is_phase_end_confirmed := true; | ||
END IF; | ||
IF NEW.phase_start > current_date THEN | ||
new.is_phase_start_confirmed := false; | ||
END IF; | ||
IF NEW.phase_end > current_date THEN | ||
new.is_phase_end_confirmed := false; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$; | ||
|
||
CREATE TRIGGER set_moped_proj_phases_confirmed_dates_trigger BEFORE INSERT OR UPDATE ON public.moped_proj_phases | ||
FOR EACH ROW EXECUTE FUNCTION public.moped_proj_phases_confirmed_dates(); |
3 changes: 3 additions & 0 deletions
3
moped-database/migrations/1704906960000_remove_phase_confirm_trigger/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TRIGGER set_moped_proj_phases_confirmed_dates_trigger ON public.moped_proj_phases; | ||
|
||
DROP FUNCTION moped_proj_phases_confirmed_dates; |
497 changes: 497 additions & 0 deletions
497
moped-database/migrations/1704906960001_phase_timestamps/down.sql
Large diffs are not rendered by default.
Oops, something went wrong.
500 changes: 500 additions & 0 deletions
500
moped-database/migrations/1704906960001_phase_timestamps/up.sql
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import Checkbox from "@mui/material/Checkbox"; | ||
import FormControlLabel from "@mui/material/FormControlLabel"; | ||
import { Controller } from "react-hook-form"; | ||
|
||
/** | ||
* A react-hook-form wrapper of the MUI Checkbox component | ||
* @param {object} control - react-hook-form `control` object from useController - required | ||
* @param {string} name - unique field name which be used in react-hook-form data object | ||
* @param {string} label - the label to render next to the checkbox | ||
* @param {object} checkboxProps additional optional MUI checkbox props such as `sx` or `icon` | ||
* @return {JSX.Element} | ||
*/ | ||
const ControlledCheckbox = ({ name, control, label, ...checkBoxProps }) => { | ||
return ( | ||
<Controller | ||
name={name} | ||
control={control} | ||
render={({ field }) => { | ||
return ( | ||
<FormControlLabel | ||
label={label} | ||
control={ | ||
<Checkbox | ||
checked={!!field.value} | ||
onChange={(e) => field.onChange(e.target.checked)} | ||
{...checkBoxProps} | ||
/> | ||
} | ||
/> | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default ControlledCheckbox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from "react"; | ||
import { DatePicker } from "@mui/x-date-pickers"; | ||
import { Controller } from "react-hook-form"; | ||
|
||
/** | ||
* Test if an input is not null and can be coerced to a Date object. | ||
* @param {any} value - any value, but in our case either a string, a Date object, | ||
* an Invalid Date object, or null | ||
* @returns true if the value is not null and can be coerced to a Date object | ||
*/ | ||
const isValidDateStringOrObject = (value) => { | ||
return value !== null && !isNaN(new Date(value)); | ||
}; | ||
|
||
/** | ||
* A react-hook-form wrapper of the MUI DatePicker component. | ||
* @param {object} control - react-hook-form `control` object from useController - required | ||
* @param {string} name - unique field name which be used in react-hook-form data object | ||
* @param {string} label - the label to render next to the checkbox | ||
* @param {bool} error - if the error state is active (triggers red outline around textfield) | ||
* @param {object} datePickerProps additional optional MUI date picker props | ||
* @return {JSX.Element} | ||
*/ | ||
const ControlledDateField = ({ | ||
name, | ||
control, | ||
label, | ||
error, | ||
...datePickerProps | ||
}) => { | ||
return ( | ||
<Controller | ||
name={name} | ||
control={control} | ||
render={({ field }) => { | ||
/** | ||
* The MUI component requires a Date object as the input value. | ||
* So we try to construct a Date object from the value in | ||
* react-hook-form. | ||
* | ||
* Otherwise just pass whatever the value is in state | ||
*/ | ||
let value = field.value; | ||
if (isValidDateStringOrObject(value)) { | ||
value = new Date(field.value); | ||
} | ||
return ( | ||
<DatePicker | ||
size="small" | ||
label={label} | ||
slotProps={{ | ||
textField: { size: "small", error }, | ||
field: { clearable: true }, | ||
}} | ||
value={value} | ||
onChange={(newValue) => { | ||
/** | ||
* This component's value is a Date object or an Invalid Date object. | ||
* If the date object is valid, we can convert it to an ISO string | ||
* and store the string in react-hook-form state. | ||
* | ||
* If the date object is invalid, we store the invalid date in | ||
* react-hook-form-state and let the Yup schema validation prevent | ||
* form submit. | ||
*/ | ||
const valueToStore = isValidDateStringOrObject(newValue) | ||
? newValue.toISOString() | ||
: newValue; | ||
field.onChange(valueToStore); | ||
}} | ||
{...datePickerProps} | ||
/> | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default ControlledDateField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Switch from "@mui/material/Switch"; | ||
import { Controller } from "react-hook-form"; | ||
import FormControlLabel from "@mui/material/FormControlLabel"; | ||
|
||
/** | ||
* A react-hook-form wrapper of the MUI Switch component | ||
* @param {object} control - react-hook-form `control` object from useController - required | ||
* @param {string} name - unique field name which be used in react-hook-form data object | ||
* @param {string} label - the label to render next to the checkbox | ||
* @param {object} switchProps additional optional MUI switch props | ||
* @return {JSX.Element} | ||
*/ | ||
const ControlledSwitch = ({ name, control, label, ...switchProps }) => { | ||
return ( | ||
<Controller | ||
name={name} | ||
control={control} | ||
render={({ field }) => { | ||
return ( | ||
<FormControlLabel | ||
label={label} | ||
control={ | ||
<Switch | ||
checked={!!field.value} | ||
onChange={(e) => field.onChange(e.target.checked)} | ||
color="primary" | ||
inputProps={{ "aria-label": "primary checkbox" }} | ||
{...switchProps} | ||
/> | ||
} | ||
/> | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default ControlledSwitch; |
Oops, something went wrong.