-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Publisher][Agency Settings] Add new agency definition section for court and supervision sectors #1594
[Publisher][Agency Settings] Add new agency definition section for court and supervision sectors #1594
Changes from 1 commit
81c8e2d
a418227
f40abce
0d91a80
de7ffec
90d11de
36f5dc2
93008cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ import { | |
DataSourceContainer, | ||
DataSourceQuestionWrapper, | ||
DataSourceTitle, | ||
DefinitionDescriptionInputWrapper, | ||
EditButtonContainer, | ||
} from "./AgencySettings.styles"; | ||
import { AgencySettingsEditModeModal } from "./AgencySettingsEditModeModal"; | ||
|
@@ -56,14 +57,14 @@ type AgencyDefinitionSetting = { | |
sector: AgencySystemKeys; | ||
settings: { | ||
key: string; | ||
included: IncludedValue; | ||
included?: IncludedValue; | ||
value?: string; | ||
}[]; | ||
}; | ||
|
||
const getDefaultSetting = ( | ||
systems: AgencySystemKeys[], | ||
defaultIncluded?: IncludedValue | ||
unconfiguredDefault?: IncludedValue | ||
): AgencyDefinitionSetting[] => { | ||
if (!systems.length) return []; | ||
|
||
|
@@ -74,7 +75,7 @@ const getDefaultSetting = ( | |
([key, obj]) => { | ||
return { | ||
key, | ||
included: defaultIncluded ?? obj.default, | ||
included: unconfiguredDefault ?? obj.default, | ||
}; | ||
} | ||
), | ||
|
@@ -115,7 +116,6 @@ const AgencySettingsDefinition: React.FC<{ | |
|
||
const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false); | ||
const [currentSystems, setCurrentSystems] = useState<AgencySystemKeys[]>([]); | ||
const [descriptionValue, setDescriptionValue] = useState(""); | ||
|
||
const agencyDefinitionSetting = useMemo(() => { | ||
return ( | ||
|
@@ -125,8 +125,6 @@ const AgencySettingsDefinition: React.FC<{ | |
); | ||
}, [currentAgencySettings]); | ||
|
||
const isSettingConfigured = agencyDefinitionSetting.length > 0; | ||
|
||
useEffect(() => { | ||
setCurrentSystems([]); | ||
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. Do we need to reset this every time the effect runs? 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. Yeah, unfortunately we need, because when we select agency without applicable sectors we need to reset 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. Got it - can we add a small comment here to clarify? |
||
|
||
|
@@ -152,15 +150,22 @@ const AgencySettingsDefinition: React.FC<{ | |
isCombinedAgency, | ||
]); | ||
|
||
const initialSetting = isSettingConfigured | ||
? agencyDefinitionSetting | ||
: getDefaultSetting(currentSystems, IncludesExcludesEnum.NO); | ||
const configuredSystems = agencyDefinitionSetting.map( | ||
(setting) => setting.sector | ||
); | ||
const unconfiguredSystems = currentSystems.filter( | ||
(sector) => !configuredSystems.includes(sector) | ||
); | ||
|
||
const initialSetting = [ | ||
...agencyDefinitionSetting, | ||
...getDefaultSetting(unconfiguredSystems, IncludesExcludesEnum.NO), | ||
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. Was this what ended up fixing the checkbox issue (using the 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. Yeah, the problem was that once systems were written to BE, there was no way for unconfigured (or unwritten) systems to get into 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. Gotcha! Great catch and sleuthing! |
||
]; | ||
|
||
const [updatedSetting, setUpdatedSetting] = useState(initialSetting); | ||
|
||
useEffect(() => { | ||
setUpdatedSetting(initialSetting); | ||
setDescriptionValue(""); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [agencyDefinitionSetting, currentSystems]); | ||
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. Can you clarify the purpose of this effect? We already initialize it with 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. This is a reset effect used for resetting setting for UI to work properly. The absence of this effect causes visual bug with incorrect working UI when switching agencies like here 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. Thanks for clarifying. I'd add a small comment here too for clarity. |
||
|
||
|
@@ -215,6 +220,28 @@ const AgencySettingsDefinition: React.FC<{ | |
}); | ||
}; | ||
|
||
const handleDescriptionChange = (system: AgencySystemKeys, value: string) => { | ||
setUpdatedSetting((prevSettings) => { | ||
return prevSettings.map((sector) => { | ||
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. tiny nit: 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. Oh, this actually was resolved in this commit 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. Ah, sorry - I was looking at the wrong commit! Thank you so much! |
||
if (sector.sector === system) { | ||
return { | ||
...sector, | ||
settings: [ | ||
...sector.settings.filter( | ||
(setting) => setting.key !== "ADDITIONAL_CONTEXT" | ||
), // Ensure no duplicate keys | ||
{ | ||
key: "ADDITIONAL_CONTEXT", | ||
value, | ||
}, | ||
], | ||
}; | ||
} | ||
return sector; | ||
}); | ||
}); | ||
}; | ||
|
||
if (!currentSystems.length) return null; | ||
|
||
return ( | ||
|
@@ -243,6 +270,12 @@ const AgencySettingsDefinition: React.FC<{ | |
</DataSourceQuestionWrapper> | ||
|
||
{currentSystems?.map((system) => { | ||
const defaultDescription = initialSetting | ||
.find((setting) => setting.sector === system) | ||
?.settings.find( | ||
(setting) => setting.key === "ADDITIONAL_CONTEXT" | ||
)?.value; | ||
|
||
return ( | ||
<React.Fragment key={system}> | ||
{isSupervisionAgencyWithEnabledSubpopulations && ( | ||
|
@@ -272,21 +305,23 @@ const AgencySettingsDefinition: React.FC<{ | |
handleCheckboxChange(key, checked, system) | ||
} | ||
/> | ||
<DefinitionDescriptionInputWrapper> | ||
<NewInput | ||
name={`${system.toLocaleLowerCase()}_description`} | ||
id={`${system.toLocaleLowerCase()}_description`} | ||
type="text" | ||
multiline | ||
placeholder="If the listed categories do not adequately describe your agency, please describe additional data elements included in your agency’s definition." | ||
defaultValue={defaultDescription} | ||
onChange={(e) => | ||
handleDescriptionChange(system, e.target.value) | ||
} | ||
fullWidth | ||
/> | ||
</DefinitionDescriptionInputWrapper> | ||
</React.Fragment> | ||
); | ||
})} | ||
<NewInput | ||
name="agency_definition_description" | ||
id="agency_definition_description" | ||
type="text" | ||
multiline | ||
placeholder="If the listed categories do not adequately describe your breakdown, please describe additional data elements included in your agency’s definition." | ||
value={descriptionValue} | ||
onChange={(e) => { | ||
setDescriptionValue(e.target.value); | ||
}} | ||
fullWidth | ||
/> | ||
</DataSourceContainer> | ||
} | ||
buttons={[ | ||
|
@@ -309,7 +344,7 @@ const AgencySettingsDefinition: React.FC<{ | |
)} | ||
|
||
<AgencySettingsBlock withBorder id="agency_definition"> | ||
<BasicInfoBlockTitle configured={isSettingConfigured}> | ||
<BasicInfoBlockTitle> | ||
{agencyTitle} Agency Definition | ||
{allowEdit && ( | ||
<EditButtonContainer> | ||
|
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.
tiniest nit: typo in Definition