Skip to content

Commit

Permalink
get v2 form state changes merge worthy
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-w-wells committed Dec 5, 2023
1 parent 842c419 commit af5a3b3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
38 changes: 16 additions & 22 deletions appv2/src/UI/Overlay/Records/Activity/form/FormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ import MultiSelectAutoComplete from 'rjsf/widgets/MultiSelectAutoComplete';
import SingleSelectAutoComplete from 'rjsf/widgets/SingleSelectAutoComplete';
import rjsfTheme from 'UI/Overlay/Records/Activity/form/rjsfTheme';
import ChemicalTreatmentDetailsForm from './ChemicalTreatmentDetailsForm/ChemicalTreatmentDetailsForm';
import PasteButtonComponent from './PasteButtonComponent';
import { useSelector } from 'util/use_selector';
import { selectAuth } from 'state/reducers/auth';
import { selectConfiguration } from 'state/reducers/configuration';
import { selectActivity } from 'state/reducers/activity';
import { useDispatch } from 'react-redux';
import { ACTIVITY_CHEM_TREATMENT_DETAILS_FORM_ON_CHANGE_REQUEST, ACTIVITY_ON_FORM_CHANGE_REQUEST } from 'state/actions';
import { selectUserSettings } from 'state/reducers/userSettings';
Expand Down Expand Up @@ -74,9 +70,8 @@ export interface IFormContainerProps {
const FormContainer: React.FC<IFormContainerProps> = (props) => {
const activityState = useSelector((state) => state.ActivityPage.activity);
const dispatch = useDispatch();
console.log('rendering')

const debouncedFormChange =
const debouncedFormChange =
_.debounce((event, ref, lastField, callbackFun) => {
//(event, ref, lastField, callbackFun) => {
dispatch({
Expand All @@ -91,13 +86,16 @@ const FormContainer: React.FC<IFormContainerProps> = (props) => {
const [open, setOpen] = React.useState(false);
const [alertMsg, setAlertMsg] = React.useState(null);
const [field, setField] = React.useState('');
const { authenticated } = useSelector(selectAuth);
const authState = useSelector(selectAuth);

const { MOBILE } = useSelector(selectConfiguration);
const authenticated = useSelector((state) => state.Auth.authenticated);
const username = useSelector((state) => state.Auth.username);
const accessRoles = useSelector((state) => state.Auth.accessRoles);

const MOBILE = useSelector((state) => state.Configuration.current.MOBILE);

const { darkTheme } = useSelector(selectUserSettings);
const userSettingsState = useSelector(selectUserSettings);
const apiDocsWithViewOptions = useSelector((state) => state.UserSettings.apiDocsWithViewOptions);
const apiDocsWithSelectOptions = useSelector((state) => state.UserSettings.apiDocsWithSelectOptions);

const suggestedTreatmentIDS = useSelector((state) => state.ActivityPage.suggestedTreatmentIDs);

Expand Down Expand Up @@ -139,7 +137,6 @@ const FormContainer: React.FC<IFormContainerProps> = (props) => {
$this.validate($this.state.formData);
//update formData of the activity via onFormChange
debouncedFormChange({ formData: formRef.current.state.formData }, formRef, null, (updatedFormData) => {
setformData(updatedFormData);
});
});
}, 100);
Expand Down Expand Up @@ -173,21 +170,20 @@ const FormContainer: React.FC<IFormContainerProps> = (props) => {

useEffect(() => {
const getApiSpec = async () => {
console.log('begin api spec stuff')
const subtype = activityState?.activity_subtype || activityState?.activitySubtype;
if (!subtype) throw new Error('Activity has no Subtype specified');
let components;
const notMine = authState?.username !== activityState?.created_by;
const notMine = username !== activityState?.created_by;
const notAdmin =
authState?.accessRoles?.filter((role) => {
accessRoles?.filter((role) => {
return [1,18].includes(role.role_id)
}).length === 0;
if (notAdmin && notMine) {
components = (userSettingsState.apiDocsWithViewOptions as any).components;
components = (apiDocsWithViewOptions as any).components;
} else if (!notAdmin && notMine) {
components = (userSettingsState.apiDocsWithViewOptions as any).components;
components = (apiDocsWithViewOptions as any).components;
} else {
components = (userSettingsState.apiDocsWithSelectOptions as any).components;
components = (apiDocsWithSelectOptions as any).components;
}

let uiSchema = RootUISchemas[subtype];
Expand Down Expand Up @@ -253,22 +249,21 @@ const FormContainer: React.FC<IFormContainerProps> = (props) => {
if (authenticated) {
getApiSpec();
}
console.log('end api spec stuff')
}, [activityState.activity_subtype, authenticated, MOBILE, suggestedTreatmentIDS]);

const [isDisabled, setIsDisabled] = useState(false);
useEffect(() => {
const notMine = authState?.username !== activityState.created_by;
const notMine = username !== activityState.created_by;
const notAdmin =
authState?.accessRoles?.filter((role) => {
accessRoles?.filter((role) => {
return role.role_id === 18;
}).length === 0;
if (notAdmin && notMine) {
setIsDisabled(true);
} else {
setIsDisabled(false);
}
}, [JSON.stringify(authState?.accessRoles), JSON.stringify(authState?.username)]);
}, [JSON.stringify(accessRoles), JSON.stringify(username)]);

// hack to make fields rerender only on paste event
const [keyInt, setKeyInt] = useState(0);
Expand Down Expand Up @@ -309,7 +304,6 @@ const FormContainer: React.FC<IFormContainerProps> = (props) => {
transformErrors={getCustomErrorTransformer()}
autoComplete="off"
onChange={(event) => {
console.log('A CHANGE')
debouncedFormChange(event, formRef, focusedFieldArgs, (updatedFormData) => {
//setformData(updatedFormData);
});
Expand Down
1 change: 1 addition & 0 deletions appv2/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import(/* webpackChunkName: "app_config" */ './state/config').then(({ CONFIG })
console.log('about to render');
const root = createRoot(container);
if (root) {
console.log('rendered')
root.render(
<Router history={historySingleton}>
<Provider store={store}>
Expand Down
5 changes: 2 additions & 3 deletions appv2/src/rjsf/business-rules/customValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ function combineValidators(validators: rjsfValidator[]): rjsfValidator {
}

export function validatorForActivity(activity, linkedActivity): rjsfValidator {
console.log('recombining validators')
return combineValidators([
/* getAreaValidator(activity.activity_subtype),
getAreaValidator(activity.activity_subtype),
getDateAndTimeValidator(activity.activity_subtype),
getDateAndTimeValidatorOther(activity.activity_subtype),
getWindValidator(activity.activity_subtype),
Expand All @@ -36,7 +35,7 @@ export function validatorForActivity(activity, linkedActivity): rjsfValidator {
getJurisdictionPercentValidator(),
getInvasivePlantsValidator(linkedActivity),
getPlotIdentificationTreesValidator(activity.activity_subtype),
accessDescriptionMinChars()*/
accessDescriptionMinChars()
]);
}

Expand Down
2 changes: 1 addition & 1 deletion appv2/src/state/sagas/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function* activityPageSaga() {
handle_ACTIVITY_GET_SUGGESTED_JURISDICTIONS_REQUEST_ONLINE
),
takeLatest(ACTIVITY_GET_SUGGESTED_JURISDICTIONS_SUCCESS, handle_ACTIVITY_SET_CURRENT_HASH_REQUEST),
takeEvery(ACTIVITY_ON_FORM_CHANGE_SUCCESS, handle_ACTIVITY_SET_CURRENT_HASH_REQUEST),
takeLatest(ACTIVITY_ON_FORM_CHANGE_SUCCESS, handle_ACTIVITY_SET_CURRENT_HASH_REQUEST),
takeEvery(ACTIVITY_SAVE_SUCCESS, handle_ACTIVITY_SET_SAVED_HASH_REQUEST),
takeEvery(ACTIVITY_GET_SUGGESTED_PERSONS_REQUEST, handle_ACTIVITY_GET_SUGGESTED_PERSONS_REQUEST),
takeEvery(ACTIVITY_GET_SUGGESTED_PERSONS_REQUEST_ONLINE, handle_ACTIVITY_GET_SUGGESTED_PERSONS_REQUEST_ONLINE),
Expand Down

0 comments on commit af5a3b3

Please sign in to comment.