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

[INV-3672] Linked ID showing improperly #3673

Merged
merged 5 commits into from
Nov 18, 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
4 changes: 3 additions & 1 deletion app/src/UI/Overlay/Records/Activity/form/FormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getCustomErrorTransformer } from 'rjsf/business-rules/customErrorTransf
import debounce from 'lodash.debounce';
import { RENDER_DEBUG } from 'UI/App';
import AgentSelectAutoComplete from 'rjsf/widgets/AgentSelectAutoComplete';
import LinkedIdSelectAutoComplete from 'rjsf/widgets/LinkedIdSelectAutoComplete';

const FormContainer = () => {
const ref = useRef(0);
Expand Down Expand Up @@ -137,7 +138,8 @@ const FormContainer = () => {
widgets={{
'multi-select-autocomplete': MultiSelectAutoComplete,
'single-select-autocomplete': SingleSelectAutoComplete,
'agent-select-autocomplete': AgentSelectAutoComplete
'agent-select-autocomplete': AgentSelectAutoComplete,
'linked-id-select-autocomplete': LinkedIdSelectAutoComplete
}}
readonly={isDisabled}
key={activity_ID + pasteCount + reported_area}
Expand Down
4 changes: 2 additions & 2 deletions app/src/rjsf/uiSchema/BaseUISchemaComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ const Observation = {
};

const Monitoring = {
linked_id: { 'ui:widget': 'single-select-autocomplete' },
linked_id: { 'ui:widget': 'linked-id-select-autocomplete' },
copy_geometry: { 'ui:widget': 'single-select-autocomplete' },
activity_persons: {},
'ui:order': ['linked_id', 'copy_geometry', 'activity_persons']
};

const Monitoring_Biocontrol_Release = {
linked_id: { 'ui:widget': 'single-select-autocomplete' },
linked_id: { 'ui:widget': 'linked-id-select-autocomplete' },
legacy_iapp_id: {},
activity_persons: {},
'ui:order': ['linked_id', 'copy_geometry', 'legacy_iapp_id', 'activity_persons']
Expand Down
5 changes: 5 additions & 0 deletions app/src/rjsf/widgets/AgentSelectAutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ const AgentSelectAutoComplete = (props: WidgetProps) => {
onLoad={() => {
props.onChange(value);
}}
SelectProps={{
MenuProps: {
sx: { height: '300px' }
}
}}
Comment on lines +89 to +93
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Recommended, due to MUI instability

>
{filteredOptions.map((entry) => (
<MenuItem key={entry.value} value={entry.value}>
Expand Down
63 changes: 63 additions & 0 deletions app/src/rjsf/widgets/LinkedIdSelectAutoComplete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { TextField, MenuItem } from '@mui/material';
import { SelectAutoCompleteContext } from 'UI/Overlay/Records/Activity/form/SelectAutoCompleteContext';
import { ChangeEvent, useContext, useEffect, useState } from 'react';
import { WidgetProps } from '@rjsf/utils';
import { useSelector } from 'utils/use_selector';
import { nanoid } from '@reduxjs/toolkit';

const LinkedIdSelectAutoComplete = (props: WidgetProps) => {
const selectAutoCompleteContext = useContext(SelectAutoCompleteContext);
if (!selectAutoCompleteContext) {
throw new Error('Context not provided to AgentSelectAutoComplete.tsx');
}
/**
* @desc Change Handler for Select Menu, fires RJSF onChangeEvent and updates local state
*/
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
setValue(event.target.value);
props.onChange(event.target.value);
};

const { setLastFieldChanged } = selectAutoCompleteContext;
const { suggestedTreatmentIDs } = useSelector((state) => state.ActivityPage);
const [value, setValue] = useState(props.value ?? null);
const [renderKey] = useState(props.id + nanoid());

useEffect(() => {
setLastFieldChanged({ id: props.id, option: value });
}, [value]);

return (
<TextField
select
required={props.required}
key={renderKey}
onFocus={(event) => props.onFocus(event.target.id, event.target.nodeValue)}
id={props.id}
disabled={props.disabled}
label={props.label}
value={value ?? ''}
onChange={handleChange}
onLoad={() => {
props.onChange(value);
}}
SelectProps={{
MenuProps: {
sx: { height: '300px' }
}
}}
>
{suggestedTreatmentIDs.length > 0 ? (
suggestedTreatmentIDs.map((entry) => (
<MenuItem key={entry.value} value={entry.value}>
{entry.label}
</MenuItem>
))
) : (
<MenuItem disabled>No treatment records found in selected area.</MenuItem>
)}
</TextField>
);
};

export default LinkedIdSelectAutoComplete;
4 changes: 1 addition & 3 deletions app/src/state/reducers/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ function createActivityReducer(): (ActivityState: ActivityState, AnyAction) => A
draftState.suggestedPersons = [...action.payload];
} else if (Activity.Suggestions.treatmentIdsSuccess.match(action)) {
draftState.suggestedTreatmentIDs = [...action.payload];
if (draftState?.schema?.properties?.activity_type_data?.properties?.linked_id)
draftState.schema.properties.activity_type_data.properties.linked_id.options = action.payload;
} else if (Activity.createReq.match(action)) {
const activity_copy_buffer = JSON.parse(JSON.stringify(draftState.activity_copy_buffer));
Object.assign(draftState, {
Expand Down Expand Up @@ -213,7 +211,7 @@ function createActivityReducer(): (ActivityState: ActivityState, AnyAction) => A
break;
}
}
}) as ActivityState;
});
};
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/state/sagas/activity/dataAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export function* handle_ACTIVITY_GET_SUGGESTED_TREATMENT_IDS_REQUEST(action) {
} as FeatureCollection)
: false;

if (linkedActivitySubtypes.length > 0) {
if (linkedActivitySubtypes.length > 0 && search_feature) {
yield put(
Activity.Suggestions.treatmentIdsRequestOnline({
activity_subtype: linkedActivitySubtypes,
Expand Down
2 changes: 1 addition & 1 deletion app/src/state/sagas/activity/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export function* handle_ACTIVITY_GET_SUGGESTED_TREATMENT_IDS_REQUEST_ONLINE(acti
console.error(e);
yield put(
Alerts.create({
content: 'An error occured while fetching suggested persons. Suggestions will not be displayed',
content: 'An error occured while fetching suggested treatment IDs. Suggestions will not be displayed',
severity: AlertSeverity.Error,
subject: AlertSubjects.Form,
autoClose: 8
Expand Down
Loading