Skip to content

Commit 8bd964b

Browse files
author
Claudio Gonzalez
committed
Fix runtime errors and deprecation warnings - Add safety checks for undefined displayEntity in utils.js and FormStack.js - Fix deprecated onFilterDropdownVisibleChange to filterDropdownProps.onOpenChange in Table.js and Collection.js - Update Collapse component to use items prop instead of children in Form.js - Remove unused Panel import from Form.js - Fix all Ant Design v5 deprecation warnings - Prevent runtime errors when entities are not loaded yet
1 parent dbbc3a0 commit 8bd964b

5 files changed

Lines changed: 41 additions & 25 deletions

File tree

src/components/Form/Collection.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,12 @@ const Collection = ({
270270
.toLowerCase()
271271
.includes(value.toLowerCase())
272272
: '',
273-
onFilterDropdownVisibleChange: (visible) => {
274-
if (visible) {
275-
setTimeout(() => searchInputRef.current.select(), 100);
276-
}
273+
filterDropdownProps: {
274+
onOpenChange: (visible) => {
275+
if (visible) {
276+
setTimeout(() => searchInputRef.current.select(), 100);
277+
}
278+
},
277279
},
278280
});
279281

src/components/Form/Form.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useIntl } from 'react-intl';
77
import { isDate } from './utils';
88
import moment from 'moment';
99

10-
const { Panel } = Collapse;
10+
1111

1212
const Form = ({
1313
displayEntity = null,
@@ -67,20 +67,20 @@ const Form = ({
6767
{collectionFields.length > 0 && (
6868
<Row>
6969
<Col span={22}>
70-
<Collapse style={{ marginBottom: 20, marginLeft: 10 }}>
71-
{collectionFields.map((field, index) => {
70+
<Collapse
71+
style={{ marginBottom: 20, marginLeft: 10 }}
72+
items={collectionFields.map((field, index) => {
7273
let data = [];
7374
if (initialValues) {
7475
data = initialValues[field.name];
7576
}
76-
return (
77-
<Panel
78-
header={intl.formatMessage({
79-
id: `entity.${displayEntity.name}.fields.${field.name}`,
80-
defaultMessage: field.name,
81-
})}
82-
key={index}
83-
>
77+
return {
78+
key: index,
79+
label: intl.formatMessage({
80+
id: `entity.${displayEntity.name}.fields.${field.name}`,
81+
defaultMessage: field.name,
82+
}),
83+
children: (
8484
<Collection
8585
key={field.name}
8686
field={field}
@@ -94,10 +94,10 @@ const Form = ({
9494
mode={mode}
9595
openForResult={openForResultHandler}
9696
/>
97-
</Panel>
98-
);
97+
),
98+
};
9999
})}
100-
</Collapse>
100+
/>
101101
</Col>
102102
</Row>
103103
)}

src/components/Form/FormStack.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import { EntitiesContext } from '../entities-context';
1515
import { InstancesContext } from './InstancesContext';
1616

1717
const FormStack = ({ displayEntity = null, onSuccess, mode, id }) => {
18+
// Safety check for displayEntity
19+
if (!displayEntity) {
20+
console.warn('FormStack: displayEntity is null or undefined');
21+
return null;
22+
}
23+
1824
const [entitiesStack, setEntitiesStack] = useState([
1925
{
2026
caller: undefined,
@@ -83,7 +89,7 @@ const FormStack = ({ displayEntity = null, onSuccess, mode, id }) => {
8389
);
8490

8591
useEffect(() => {
86-
if (mode === 'UPDATE') {
92+
if (mode === 'UPDATE' && displayEntity) {
8793
const filtersForEntity = {};
8894
filtersForEntity.id = {
8995
value: id,

src/components/Table/Table.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,14 @@ const Table = ({
473473
filterIcon: (filtered) => (
474474
<SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} />
475475
),
476-
onFilterDropdownVisibleChange: (visible) => {
477-
if (visible) {
478-
setTimeout(() => searchInput?.current?.select(), 100);
479-
} else {
480-
setSelectValues(undefined);
481-
}
476+
filterDropdownProps: {
477+
onOpenChange: (visible) => {
478+
if (visible) {
479+
setTimeout(() => searchInput?.current?.select(), 100);
480+
} else {
481+
setSelectValues(undefined);
482+
}
483+
},
482484
},
483485
};
484486
},

src/components/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ export const requestEntity = async (
218218
sort,
219219
entities
220220
) => {
221+
// Safety check for undefined displayEntities
222+
if (!displayEntities || !displayEntities.fields) {
223+
console.warn('displayEntities is undefined or missing fields');
224+
return null;
225+
}
226+
221227
const entityName = displayEntities.queryAll;
222228
const fields = displayEntities.fields;
223229
let queryFields = [];

0 commit comments

Comments
 (0)