Skip to content

Commit 3fa7085

Browse files
Merged in bcal-167-disabled-fields (pull request #6024)
BCAL-167: Fixing none api selects being required offline Approved-by: Dennis Hernandez
2 parents b05ebc5 + 1b4272a commit 3fa7085

8 files changed

+40
-51
lines changed

app/javascript/components/record-form/form/field-types/select-field-container.jsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import { fetchReferralUsers } from "../../../record-actions/transitions/action-c
99
import SearchableSelect from "../../../searchable-select";
1010
import { getUserFilters } from "../../../record-actions/transitions/components/utils";
1111
import { SERVICE_SECTION_FIELDS } from "../../../record-actions/transitions/components/referrals";
12-
import { buildOptions, getSelectFieldDefaultValue, handleChangeOnServiceUser, isFieldRequired } from "../utils";
12+
import { buildOptions, getSelectFieldDefaultValue, handleChangeOnServiceUser, asyncFieldOffline } from "../utils";
1313
import { useMemoizedSelector } from "../../../../libs";
1414
import { getOptionsAreLoading } from "../../selectors";
1515
import { getLoading } from "../../../record-list/selectors";
1616
import { REFERRAL_TYPE } from "../../../record-actions/transitions";
1717
import { OPTION_TYPES } from "../../../form";
1818
import useOptions from "../../../form/use-options";
1919
import { RECORD_TYPES } from "../../../../config";
20-
import { ASYNC_OPTIONS } from "../constants";
2120

2221
const SelectFieldContainer = ({
2322
field,
@@ -46,8 +45,7 @@ const SelectFieldContainer = ({
4645
multi_select: multiSelect,
4746
selected_value: selectedDefaultValue,
4847
option_strings_source: optionStringsSource,
49-
option_strings_text: optionStringsText,
50-
required
48+
option_strings_text: optionStringsText
5149
} = field;
5250
const option = optionStringsSource || optionStringsText;
5351
const fieldValue = typeof value === "boolean" ? String(value) : value;
@@ -110,8 +108,7 @@ const SelectFieldContainer = ({
110108
);
111109
};
112110

113-
const apiSelectOptionsOffline =
114-
!isFieldRequired(online, option, required) && ASYNC_OPTIONS.includes(option) && required;
111+
const apiSelectOptionsOffline = asyncFieldOffline(online, option);
115112

116113
const inputHelperText = () => {
117114
if (error && touched) {

app/javascript/components/record-form/form/form-section-field.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import AttachmentField from "./field-types/attachments";
3333
import LinkToForm from "./field-types/link-to-form";
3434
import TallyField from "./field-types/tally-field";
3535
import css from "./styles.css";
36-
import { isFieldRequired } from "./utils";
36+
import { asyncFieldOffline } from "./utils";
3737

3838
const FormSectionField = ({
3939
name,
@@ -104,7 +104,7 @@ const FormSectionField = ({
104104
InputLabelProps: {
105105
htmlFor: name,
106106
shrink: true,
107-
required: isFieldRequired(online, optionStringsSource, required),
107+
required: asyncFieldOffline(online, optionStringsSource) ? false : required,
108108
classes: {
109109
root: css.inputLabel
110110
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ASYNC_OPTIONS } from "../constants";
2+
3+
function asyncFieldOffline(online, option) {
4+
if (!online && ASYNC_OPTIONS.includes(option)) {
5+
return true;
6+
}
7+
8+
return false;
9+
}
10+
11+
export default asyncFieldOffline;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { CUSTOM_STRINGS_SOURCE } from "../constants";
2+
3+
import asyncFieldOffline from "./async-field-offline";
4+
5+
describe("asyncFieldOffline", () => {
6+
it("returns false when online and options uses endpoint", () => {
7+
expect(asyncFieldOffline(true, CUSTOM_STRINGS_SOURCE.agency)).to.be.false;
8+
});
9+
10+
it("returns true when not online and options uses endpoint", () => {
11+
expect(asyncFieldOffline(false, CUSTOM_STRINGS_SOURCE.agency)).to.be.true;
12+
});
13+
14+
it("returns false when online and options does not use endpoint", () => {
15+
expect(asyncFieldOffline(true, "none-api-option-source")).to.be.false;
16+
});
17+
18+
it("returns false when offline and options does not use endpoint and required true", () => {
19+
expect(asyncFieldOffline(false, "none-api-option-source")).to.be.false;
20+
});
21+
});

app/javascript/components/record-form/form/utils/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ export { default as serviceIsReferrable } from "./service-is-referrable";
2424
export { default as shouldFieldUpdate } from "./should-field-update";
2525
export { default as updateSubformEntries } from "./update-subform-entries";
2626
export { default as withStickyOption } from "./with-sticky-option";
27-
export { default as isFieldRequired } from "./is-field-required";
27+
export { default as asyncFieldOffline } from "./async-field-offline";

app/javascript/components/record-form/form/utils/is-field-required.js

-11
This file was deleted.

app/javascript/components/record-form/form/utils/is-field-required.unit.test.js

-25
This file was deleted.

app/javascript/components/record-form/form/validations.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,15 @@ import {
1414
TALLY_FIELD
1515
} from "../constants";
1616

17-
import { isFieldRequired } from "./utils";
18-
import { ASYNC_OPTIONS } from "./constants";
17+
import { asyncFieldOffline } from "./utils";
1918

2019
const MAX_PERMITTED_INTEGER = 2147483647;
2120

2221
export const fieldValidations = (field, { i18n, online = false }) => {
2322
const { multi_select: multiSelect, name, type, required, option_strings_source: optionStringsSource } = field;
2423
const validations = {};
2524

26-
if (
27-
field.visible === false ||
28-
(!isFieldRequired(online, optionStringsSource, required, true) && ASYNC_OPTIONS.includes(optionStringsSource))
29-
) {
25+
if (field.visible === false || asyncFieldOffline(online, optionStringsSource)) {
3026
return validations;
3127
}
3228

0 commit comments

Comments
 (0)