-
Notifications
You must be signed in to change notification settings - Fork 39
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
[MDS-5712] AMS Application Purpose #3036
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f396c47
change around authorizations involved, convert to TS, fix some issues…
taraepp bbfa96e
add 'help' text to radio buttons, make authorizations form section mo…
taraepp 48446c6
make field names closer to mappings, tooltip
taraepp 5b42909
migration to separate out AMS amended authorizations into their own r…
taraepp f9c9d8b
update BE response to include new fields, format a bit differently wh…
taraepp eecfedf
fix issue with label and with radio buttons, process & validate on BE…
taraepp 59828e6
move authorizations involved into common, put in CORE, change 'OTHER'…
taraepp 5ccdda3
make a hidden field component to handle most of the redux-y stuff, up…
taraepp 0ca8605
fix style issues on CORE
taraepp 77355b8
fix issues with multiselect changing value onBlur, fix issues with sa…
taraepp 101545d
add loading indicator on multiselect, remove console log, snaps
taraepp d843948
reverted changes to a method that's no longer being used
taraepp d4436a5
remove failing line from cypress test
taraepp a895ce5
fix indent error
taraepp 7110897
fill in an authorization for cypress test
taraepp fd22d67
update snap
taraepp 2956d5a
forgot to save change to data-cy before last commit
taraepp d2ce89d
fix snap again
taraepp 99adad3
make required fields consistent and also don't show an empty item in …
taraepp c271966
missed change to cypress test
taraepp f5d3c27
rename migration for order, and update data with 'OTHER' type to use …
taraepp eb87872
fix validation method
taraepp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,87 @@ | ||
ALTER TABLE project_summary_authorization | ||
ADD COLUMN IF NOT EXISTS amendment_changes text[], -- array of change types | ||
ADD COLUMN IF NOT EXISTS amendment_severity varchar(3), -- SIG or MIN | ||
ADD COLUMN IF NOT EXISTS is_contaminated boolean, | ||
ADD COLUMN IF NOT EXISTS new_type varchar(3), -- permit | approval | ||
ADD COLUMN IF NOT EXISTS authorization_description varchar(4000), | ||
ADD COLUMN IF NOT EXISTS exemption_requested boolean, | ||
ALTER COLUMN existing_permits_authorizations SET DEFAULT array[]::text[], | ||
ALTER COLUMN existing_permits_authorizations DROP NOT NULL | ||
; | ||
|
||
UPDATE project_summary_authorization | ||
SET authorization_description = array_to_string(existing_permits_authorizations, ',') | ||
WHERE project_summary_authorization_type = 'OTHER'; | ||
|
||
DO | ||
$$ | ||
DECLARE | ||
authorization record; | ||
auth_no text; | ||
auth_array text[]; | ||
i integer; | ||
n integer; | ||
|
||
other_types text[]; | ||
type_count integer; | ||
delete_guids uuid[]; | ||
BEGIN | ||
-- target authorizations with multiple auth # amendments related to EMA | ||
FOR authorization IN SELECT * FROM project_summary_authorization | ||
WHERE 'AMENDMENT'=ANY(project_summary_permit_type) | ||
AND cardinality(existing_permits_authorizations) > 1 | ||
AND project_summary_authorization_type IN( | ||
SELECT project_summary_authorization_type FROM project_summary_authorization_type | ||
WHERE project_summary_authorization_type_group_id = 'ENVIRONMENTAL_MANAGMENT_ACT') | ||
LOOP | ||
-- create a record for each auth no | ||
i := 1; | ||
n := cardinality("authorization"."existing_permits_authorizations"); | ||
auth_array := "authorization"."existing_permits_authorizations"; | ||
|
||
type_count := cardinality("authorization"."project_summary_permit_type"); | ||
IF type_count = 1 THEN | ||
delete_guids := delete_guids || "authorization"."project_summary_authorization_guid"; | ||
ELSE | ||
other_types := array_remove("authorization"."project_summary_permit_type", 'AMENDMENT'); | ||
UPDATE project_summary_authorization | ||
SET project_summary_permit_type = other_types, existing_permits_authorizations = ARRAY[]::text[] | ||
WHERE project_summary_authorization_guid = "authorization"."project_summary_authorization_guid"; | ||
END IF; | ||
|
||
LOOP | ||
auth_no := TRIM(auth_array[i]); | ||
IF auth_no != '' THEN | ||
INSERT INTO project_summary_authorization ( | ||
project_summary_guid, | ||
project_summary_authorization_type, | ||
project_summary_permit_type, | ||
existing_permits_authorizations, | ||
deleted_ind, | ||
create_user, | ||
create_timestamp, | ||
update_user, | ||
update_timestamp | ||
) VALUES ( | ||
"authorization"."project_summary_guid", | ||
"authorization"."project_summary_authorization_type", | ||
'{"AMENDMENT"}', | ||
ARRAY [auth_no], | ||
"authorization"."deleted_ind", | ||
"authorization"."create_user", | ||
"authorization"."create_timestamp", | ||
"authorization"."update_user", | ||
"authorization"."update_timestamp" | ||
); | ||
END IF; | ||
|
||
i := i + 1; | ||
EXIT WHEN i > n; | ||
|
||
END LOOP; | ||
END LOOP; | ||
|
||
DELETE FROM project_summary_authorization | ||
WHERE project_summary_authorization.project_summary_authorization_guid =ANY(delete_guids); | ||
END | ||
$$ |
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
77 changes: 41 additions & 36 deletions
77
services/common/src/components/forms/RenderGroupCheckbox.tsx
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 |
---|---|---|
@@ -1,54 +1,59 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { change } from "redux-form"; | ||
import { connect } from "react-redux"; | ||
import { bindActionCreators } from "redux"; | ||
import React, { FC } from "react"; | ||
import { Checkbox, Form } from "antd"; | ||
import { BaseInputProps } from "./BaseInput"; | ||
|
||
/** | ||
* @constant RenderGroupCheckbox - Ant Design `Checkbox` component for redux-form. | ||
* NOTE ABOUT A REDUX BUG AFFECTING THIS COMPONENT: | ||
* Exactly what's happening here: https://github.com/redux-form/redux-form/issues/2768 | ||
* - When onBlur is called, it calls onChange to update the value | ||
* - but with a group checkbox, it does it with the value of the individual checkbox, | ||
* - not with the value of the group | ||
* - so it will call onChange(true | false) instead of onChange(["val1", "val2"]) | ||
* - which causes an error. | ||
* - And event.preventDefault() on the onBlur also prevents validation | ||
* - The best and easiest solution I found was to put a normalize function on the <Field /> | ||
* - to not update the value if it's not an array (normalize gets called first) | ||
* - It is exported here as normalizeGroupCheckBox | ||
*/ | ||
|
||
const propTypes = { | ||
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, | ||
label: PropTypes.string.isRequired, | ||
meta: PropTypes.objectOf(PropTypes.any).isRequired, | ||
input: PropTypes.objectOf(PropTypes.string).isRequired, | ||
disabled: PropTypes.bool.isRequired, | ||
options: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.string)).isRequired, | ||
change: PropTypes.func.isRequired, | ||
name: PropTypes.string.isRequired, | ||
setInitialValues: PropTypes.func, | ||
}; | ||
interface CheckboxProps extends BaseInputProps { | ||
label: string; | ||
options: any; | ||
defaultValue: any[]; | ||
} | ||
|
||
const onChange = (checkedValues, change, form, name) => { | ||
change(form, name, checkedValues); | ||
}; | ||
export const normalizeGroupCheckBox = (val, prev) => (Array.isArray(val) ? val : prev); | ||
|
||
const RenderGroupCheckbox = (props) => { | ||
const RenderGroupCheckbox: FC<CheckboxProps> = ({ | ||
meta, | ||
input, | ||
label, | ||
options, | ||
required, | ||
...props | ||
}) => { | ||
return ( | ||
<Form.Item | ||
label={props.label} | ||
validateStatus={props.meta.touched ? props.meta.error && "error" : ""} | ||
name={input.name} | ||
label={label} | ||
required={required} | ||
validateStatus={meta.touched ? meta.error && "error" : ""} | ||
help={ | ||
meta.touched && | ||
((meta.error && <span>{meta.error}</span>) || (meta.warning && <span>{meta.warning}</span>)) | ||
} | ||
getValueProps={() => ({ value: input.value })} | ||
> | ||
<Checkbox.Group | ||
// apparently id & checked do not exist on Checkbox.Group | ||
// id={props.id} | ||
name={props.name} | ||
// checked={props.input.value} | ||
options={props.options} | ||
name={input.name} | ||
options={options} | ||
disabled={props.disabled} | ||
defaultValue={props.formValues[props.fieldName]} | ||
value={ | ||
props.setInitialValues && !props.meta.dirty ? props.setInitialValues() : props.input.value | ||
} | ||
onChange={(values) => onChange(values, props.change, props.formName, props.fieldName)} | ||
defaultValue={props.defaultValue} | ||
{...input} | ||
/> | ||
</Form.Item> | ||
); | ||
}; | ||
|
||
RenderGroupCheckbox.propTypes = propTypes; | ||
|
||
const mapDispatchToProps = (dispatch) => bindActionCreators({ change }, dispatch); | ||
export default connect(null, mapDispatchToProps)(RenderGroupCheckbox); | ||
export default RenderGroupCheckbox; |
82 changes: 82 additions & 0 deletions
82
services/common/src/components/forms/RenderHiddenField.tsx
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,82 @@ | ||
import React, { FC, useState, useEffect } from "react"; | ||
import { Input, Form } from "antd"; | ||
import { BaseInputProps, getFormItemLabel } from "./BaseInput"; | ||
|
||
/** | ||
* Just can't conform the UI to play nice with redux-form? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 Love it. Reminds me of an infomercial. "Has this ever happened to you!?" |
||
* This will display the label and handle validation on change and submit | ||
* Can handle string, number, string[] values, can probably use normalize on Field to coerce | ||
|
||
USAGE | ||
- the main thing to note is that you should be handling the redux change to update the value | ||
- making the "actual" input the children will put help/validation messages at the bottom | ||
- if this is not desired, put underneath <Field /> instead, | ||
- but there is a min-height on form-item that will have to be dealt with... | ||
|
||
<Field | ||
name="field_name" | ||
component={RenderHiddenField} | ||
required | ||
validate={[required]} | ||
label="Label" | ||
> | ||
<Checkbox | ||
value | ||
checked | ||
onChange={(e) => dispatch(change(FORM_NAME, "field_name", ["5"]))} | ||
> | ||
Checkbox label | ||
</Checkbox> | ||
{whatever else is necessary to display} | ||
</Field> | ||
*/ | ||
const RenderHiddenField: FC<BaseInputProps> = ({ | ||
label, | ||
labelSubtitle, | ||
help, | ||
meta, | ||
input, | ||
disabled, | ||
required, | ||
defaultValue, | ||
children, | ||
}) => { | ||
const [touched, setTouched] = useState(meta.touched); | ||
|
||
useEffect(() => { | ||
// dirty catches when the value is set & cleared, | ||
// touched should catch when it's submitted | ||
if (meta.dirty || meta.touched) { | ||
setTouched(true); | ||
} | ||
}, [meta.dirty, meta.touched]); | ||
|
||
return ( | ||
<Form.Item | ||
className="form-item-hidden" | ||
name={input.name} | ||
required={required} | ||
label={getFormItemLabel(label, required, labelSubtitle)} | ||
validateStatus={touched ? (meta.error && "error") || (meta.warning && "warning") : ""} | ||
help={ | ||
touched && | ||
((meta.error && <span>{meta.error}</span>) || (meta.warning && <span>{meta.warning}</span>)) | ||
} | ||
> | ||
<> | ||
<div style={{ display: "none" }}> | ||
<Input | ||
disabled={disabled} | ||
defaultValue={defaultValue} | ||
name={input.name} | ||
value={input.value} | ||
/> | ||
</div> | ||
{children} | ||
{help && <div className={`form-item-help ${input.name}-form-help`}>{help}</div>} | ||
</> | ||
</Form.Item> | ||
); | ||
}; | ||
|
||
export default RenderHiddenField; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work with the sql scrip here 👍