Skip to content

Commit 72fca2a

Browse files
committed
173: Removed default props from components
1 parent fe93945 commit 72fca2a

File tree

10 files changed

+35
-70
lines changed

10 files changed

+35
-70
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"allowImportExportEverywhere": true
1414
},
1515
"rules": {
16+
"react/require-default-props": "off",
1617
"react/jsx-filename-extension": [
1718
"warn",
1819
{

src/components/util/forms/form-checkbox.jsx

+5-12
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ import { FormCheck, FormGroup } from "react-bootstrap";
88
* @param {string} props The props.
99
* @param {string} props.name The name of the checkbox
1010
* @param {string} props.label The label for the checkbox
11-
* @param {string} props.helpText The helptext for the checkbox, if it is needed.
11+
* @param {string} props.helpText The help text for the checkbox, if it is needed.
1212
* @param {string} props.value The value of the checkbox
1313
* @param {Function} props.onChange The callback for changes in the checkbox
14-
* @param {string} props.formGroupClasses Classes for the formgroup
15-
* @param {boolean} props.required Whether the checkbox is required.
14+
* @param {string} props.formGroupClasses Classes for the form group
1615
* @returns {object} A checkbox.
1716
*/
1817
function FormCheckbox({
1918
name,
2019
label,
21-
helpText,
2220
onChange,
23-
value,
24-
formGroupClasses,
21+
helpText = "",
22+
formGroupClasses = "",
23+
value = false,
2524
}) {
2625
/**
2726
* Transforms the target to something the form-components understand.
@@ -49,12 +48,6 @@ function FormCheckbox({
4948
);
5049
}
5150

52-
FormCheckbox.defaultProps = {
53-
helpText: "",
54-
formGroupClasses: "",
55-
value: false,
56-
};
57-
5851
FormCheckbox.propTypes = {
5952
name: PropTypes.string.isRequired,
6053
value: PropTypes.oneOfType([

src/components/util/forms/multiselect-dropdown/screens/screens-dropdown.jsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import MultiSelectComponent from "../multi-dropdown";
1515
*/
1616
function ScreensDropdown({
1717
handleScreenSelection,
18-
selected,
18+
errors = null,
19+
selected = [],
1920
name,
20-
errors,
2121
data,
2222
filterCallback,
2323
}) {
@@ -44,11 +44,6 @@ function ScreensDropdown({
4444
);
4545
}
4646

47-
ScreensDropdown.defaultProps = {
48-
errors: null,
49-
selected: [],
50-
};
51-
5247
ScreensDropdown.propTypes = {
5348
handleScreenSelection: PropTypes.func.isRequired,
5449
selected: PropTypes.arrayOf(

src/components/util/forms/multiselect-dropdown/tenants/tenants-dropdown.jsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import MultiSelectComponent from "../multi-dropdown";
1313
*/
1414
function TenantsDropdown({
1515
handleTenantSelection,
16-
selected,
16+
selected = [],
1717
name,
18-
errors,
18+
errors = null,
1919
data,
2020
}) {
2121
const { t } = useTranslation("common");
@@ -34,11 +34,6 @@ function TenantsDropdown({
3434
);
3535
}
3636

37-
TenantsDropdown.defaultProps = {
38-
errors: null,
39-
selected: [],
40-
};
41-
4237
TenantsDropdown.propTypes = {
4338
handleTenantSelection: PropTypes.func.isRequired,
4439
selected: PropTypes.arrayOf(

src/components/util/forms/rich-text/rich-text.jsx

+7-15
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import "./rich-text.scss";
1212
* @param {string} props The props.
1313
* @param {string} props.name The name of the rich text field
1414
* @param {string} props.label The label for the rich text field
15-
* @param {string} props.helpText The helptext for the rich text field, if it is needed.
15+
* @param {string} props.helpText The help text for the rich text field, if it is needed.
1616
* @param {string} props.value The value of the rich text field
1717
* @param {Function} props.onChange The callback for changes in the rich text field
18-
* @param {string} props.formGroupClasses Classes for the formgroup
18+
* @param {string} props.formGroupClasses Classes for the form group
1919
* @param {boolean} props.required Whether the rich text field is required.
2020
* @returns {object} A rich text field.
2121
*/
2222
function RichText({
2323
name,
24-
label,
25-
helpText,
26-
value,
2724
onChange,
28-
formGroupClasses,
29-
required,
25+
label = "",
26+
helpText = "",
27+
value = "",
28+
formGroupClasses = "",
29+
required = false,
3030
}) {
3131
/**
3232
* Transforms the target to something the form-components understand.
@@ -85,14 +85,6 @@ function RichText({
8585
);
8686
}
8787

88-
RichText.defaultProps = {
89-
label: "",
90-
helpText: "",
91-
value: "",
92-
formGroupClasses: "",
93-
required: false,
94-
};
95-
9688
RichText.propTypes = {
9789
name: PropTypes.string.isRequired,
9890
label: PropTypes.string,

src/components/util/list/checkbox-for-list.jsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import "./checkbox-for-list.scss";
88
* A checkbox for the list.
99
*
1010
* @param {object} props Props.
11-
* @param {Function} props.onSelected The callback for onselected.
11+
* @param {Function} props.onSelected The callback for on selected.
1212
* @param {boolean} props.selected Whether the checkbox should display selected.
1313
* @param {boolean} props.disabled Whether the checkbox is disabled
1414
* @param {string} props.title The title for the aria label
1515
* @returns {object} A checkbox for the list.
1616
*/
17-
function CheckboxForList({ selected, onSelected, disabled, title }) {
17+
function CheckboxForList({
18+
selected = false,
19+
onSelected,
20+
disabled = false,
21+
title,
22+
}) {
1823
const { t } = useTranslation("common", { keyPrefix: "checkbox-for-list" });
1924

2025
return (
@@ -33,11 +38,6 @@ function CheckboxForList({ selected, onSelected, disabled, title }) {
3338
);
3439
}
3540

36-
CheckboxForList.defaultProps = {
37-
selected: false,
38-
disabled: false,
39-
};
40-
4141
CheckboxForList.propTypes = {
4242
onSelected: PropTypes.func.isRequired,
4343
selected: PropTypes.bool,

src/components/util/list/link-for-list.jsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import idFromUrl from "../helpers/id-from-url";
1313
* @param {boolean} props.targetBlank Whether to open in a new tab.
1414
* @returns {object} A link for the list.
1515
*/
16-
function LinkForList({ id, param, targetBlank }) {
16+
function LinkForList({ id, param, targetBlank = false }) {
1717
const { t } = useTranslation("common", { keyPrefix: "link-for-list" });
1818
const newId = idFromUrl(id);
1919

@@ -29,10 +29,6 @@ function LinkForList({ id, param, targetBlank }) {
2929
);
3030
}
3131

32-
LinkForList.defaultProps = {
33-
targetBlank: false,
34-
};
35-
3632
LinkForList.propTypes = {
3733
id: PropTypes.string.isRequired,
3834
param: PropTypes.string.isRequired,

src/components/util/list/list-button.jsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import useModal from "../../../context/modal-context/modal-context-hook";
1313
* @param {string} props.dataKey The data key for mapping the data.
1414
* @returns {object} - The list button.
1515
*/
16-
function ListButton({ apiCall, redirectTo, displayData, modalTitle, dataKey }) {
16+
function ListButton({
17+
apiCall = () => {},
18+
dataKey = "",
19+
redirectTo,
20+
displayData,
21+
modalTitle,
22+
}) {
1723
const { setModal } = useModal();
1824
const [label, setLabel] = useState("");
1925
let data;
@@ -81,11 +87,6 @@ function ListButton({ apiCall, redirectTo, displayData, modalTitle, dataKey }) {
8187
);
8288
}
8389

84-
ListButton.defaultProps = {
85-
apiCall: () => {},
86-
dataKey: "",
87-
};
88-
8990
ListButton.propTypes = {
9091
displayData: PropTypes.oneOfType([
9192
PropTypes.arrayOf(PropTypes.any).isRequired,

src/context/modal-context/info-modal.jsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import idFromUrl from "../../components/util/helpers/id-from-url";
2222
function InfoModal({
2323
unSetModal,
2424
apiCall,
25-
displayData,
25+
displayData = [],
2626
modalTitle,
27-
dataKey,
27+
dataKey = "",
2828
redirectTo,
2929
}) {
3030
const { t } = useTranslation("common");
@@ -83,10 +83,6 @@ function InfoModal({
8383
</Modal>
8484
);
8585
}
86-
InfoModal.defaultProps = {
87-
displayData: [],
88-
dataKey: "",
89-
};
9086

9187
InfoModal.propTypes = {
9288
displayData: PropTypes.oneOfType([

src/error-boundary.jsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ErrorBoundary extends Component {
1414
}
1515

1616
componentDidCatch(error, errorInfo) {
17-
const { errorHandler } = this.props;
17+
const { errorHandler = null } = this.props;
1818

1919
if (errorHandler) {
2020
errorHandler(error, errorInfo);
@@ -38,10 +38,6 @@ class ErrorBoundary extends Component {
3838
}
3939
}
4040

41-
ErrorBoundary.defaultProps = {
42-
errorHandler: null,
43-
};
44-
4541
ErrorBoundary.propTypes = {
4642
children: PropTypes.node.isRequired,
4743
errorText: PropTypes.string.isRequired,

0 commit comments

Comments
 (0)