Fixed warnings and bugs.
This commit is contained in:
parent
8f369d777d
commit
476a01eafb
@ -68,6 +68,38 @@ const ObjectChildTable = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const mainTableWrapperRef = useRef(null)
|
const mainTableWrapperRef = useRef(null)
|
||||||
const rollupTableWrapperRef = useRef(null)
|
const rollupTableWrapperRef = useRef(null)
|
||||||
|
const generatedRowKeysRef = useRef(new WeakMap())
|
||||||
|
const generatedRowKeyCountRef = useRef(0)
|
||||||
|
|
||||||
|
const getFallbackRowKey = (record) => {
|
||||||
|
if (!record || typeof record !== 'object') {
|
||||||
|
return `object-child-table-row-${String(record)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (record._objectChildTableKey != null) {
|
||||||
|
return record._objectChildTableKey
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = generatedRowKeysRef.current.get(record)
|
||||||
|
if (existing) return existing
|
||||||
|
|
||||||
|
const generated = `object-child-table-row-${generatedRowKeyCountRef.current}`
|
||||||
|
generatedRowKeyCountRef.current += 1
|
||||||
|
generatedRowKeysRef.current.set(record, generated)
|
||||||
|
return generated
|
||||||
|
}
|
||||||
|
|
||||||
|
const getResolvedRecordKey = (record) => {
|
||||||
|
if (typeof rowKey === 'function') {
|
||||||
|
return rowKey(record) ?? getFallbackRowKey(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof rowKey === 'string' && rowKey.length > 0) {
|
||||||
|
return record?.[rowKey] ?? getFallbackRowKey(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
return getFallbackRowKey(record)
|
||||||
|
}
|
||||||
|
|
||||||
const propertyMap = useMemo(() => {
|
const propertyMap = useMemo(() => {
|
||||||
const map = new Map()
|
const map = new Map()
|
||||||
@ -130,10 +162,14 @@ const ObjectChildTable = ({
|
|||||||
const currentItems = Array.isArray(itemsSource)
|
const currentItems = Array.isArray(itemsSource)
|
||||||
? [...itemsSource]
|
? [...itemsSource]
|
||||||
: []
|
: []
|
||||||
|
const existingRowKey = getResolvedRecordKey(record)
|
||||||
const updatedItem = {
|
const updatedItem = {
|
||||||
...currentItems[index],
|
...currentItems[index],
|
||||||
[property.name]: resolved
|
[property.name]: resolved
|
||||||
}
|
}
|
||||||
|
// Preserve fallback row identity across immutable updates so the row
|
||||||
|
// is not remounted while typing (which causes input focus loss).
|
||||||
|
generatedRowKeysRef.current.set(updatedItem, existingRowKey)
|
||||||
currentItems[index] = updatedItem
|
currentItems[index] = updatedItem
|
||||||
if (typeof onChange === 'function') {
|
if (typeof onChange === 'function') {
|
||||||
onChange(currentItems)
|
onChange(currentItems)
|
||||||
@ -186,10 +222,11 @@ const ObjectChildTable = ({
|
|||||||
(item) => item[rowKey] !== record[rowKey]
|
(item) => item[rowKey] !== record[rowKey]
|
||||||
)
|
)
|
||||||
} else if (typeof rowKey === 'function') {
|
} else if (typeof rowKey === 'function') {
|
||||||
// If rowKey is a function, find the item by comparing the resolved keys
|
// If rowKey is a function, find the item by comparing resolved keys.
|
||||||
const recordKey = rowKey(record, index)
|
// Ant Design deprecates index-based rowKey callbacks.
|
||||||
newItems = currentItems.filter((item, i) => {
|
const recordKey = getResolvedRecordKey(record)
|
||||||
const itemKey = rowKey(item, i)
|
newItems = currentItems.filter((item) => {
|
||||||
|
const itemKey = getResolvedRecordKey(item)
|
||||||
return itemKey !== recordKey
|
return itemKey !== recordKey
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -216,6 +253,7 @@ const ObjectChildTable = ({
|
|||||||
resolvedProperties,
|
resolvedProperties,
|
||||||
additionalColumns,
|
additionalColumns,
|
||||||
isEditing,
|
isEditing,
|
||||||
|
canAddRemove,
|
||||||
itemsSource,
|
itemsSource,
|
||||||
onChange,
|
onChange,
|
||||||
rowKey
|
rowKey
|
||||||
@ -237,7 +275,7 @@ const ObjectChildTable = ({
|
|||||||
}, [itemsSource, loading, skeletonData])
|
}, [itemsSource, loading, skeletonData])
|
||||||
|
|
||||||
const resolvedRowKey =
|
const resolvedRowKey =
|
||||||
typeof rowKey === 'function' ? rowKey : (_record, index) => index
|
(record) => getResolvedRecordKey(record)
|
||||||
|
|
||||||
const scrollConfig =
|
const scrollConfig =
|
||||||
scrollHeight != null
|
scrollHeight != null
|
||||||
@ -281,7 +319,9 @@ const ObjectChildTable = ({
|
|||||||
|
|
||||||
// Single summary row where each rollup value is placed under
|
// Single summary row where each rollup value is placed under
|
||||||
// the column that matches its `property` field.
|
// the column that matches its `property` field.
|
||||||
const summaryRow = {}
|
const summaryRow = {
|
||||||
|
_objectChildTableKey: 'object-child-table-rollup-summary'
|
||||||
|
}
|
||||||
|
|
||||||
properties.forEach((property) => {
|
properties.forEach((property) => {
|
||||||
const rollup = rollups.find(
|
const rollup = rollups.find(
|
||||||
@ -354,7 +394,7 @@ const ObjectChildTable = ({
|
|||||||
...propertyColumns,
|
...propertyColumns,
|
||||||
...(blankDeleteColumn ? [blankDeleteColumn] : [])
|
...(blankDeleteColumn ? [blankDeleteColumn] : [])
|
||||||
]
|
]
|
||||||
}, [properties, rollups, isEditing])
|
}, [properties, rollups, isEditing, canAddRemove])
|
||||||
|
|
||||||
const hasRollups = useMemo(
|
const hasRollups = useMemo(
|
||||||
() => Array.isArray(rollups) && rollups.length > 0,
|
() => Array.isArray(rollups) && rollups.length > 0,
|
||||||
@ -414,7 +454,7 @@ const ObjectChildTable = ({
|
|||||||
dataSource={rollupDataSource}
|
dataSource={rollupDataSource}
|
||||||
showHeader={false}
|
showHeader={false}
|
||||||
columns={rollupColumns}
|
columns={rollupColumns}
|
||||||
loading={{ spinning: loading, indicator: <></> }}
|
loading={{ spinning: loading, indicator: null }}
|
||||||
pagination={false}
|
pagination={false}
|
||||||
size={size}
|
size={size}
|
||||||
rowKey={resolvedRowKey}
|
rowKey={resolvedRowKey}
|
||||||
|
|||||||
@ -291,6 +291,9 @@ const AuthProvider = ({ children }) => {
|
|||||||
})
|
})
|
||||||
}, [authenticated, token, expiresAt, userProfile, persistSession])
|
}, [authenticated, token, expiresAt, userProfile, persistSession])
|
||||||
|
|
||||||
|
const profileImageDependency =
|
||||||
|
userProfile?.profileImage?._id ?? userProfile?.profileImage
|
||||||
|
|
||||||
// Fetch and cache profile image when userProfile.profileImage changes
|
// Fetch and cache profile image when userProfile.profileImage changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const profileImage = userProfile?.profileImage
|
const profileImage = userProfile?.profileImage
|
||||||
@ -365,7 +368,7 @@ const AuthProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
setProfileImageUrl(null)
|
setProfileImageUrl(null)
|
||||||
}
|
}
|
||||||
}, [userProfile?.profileImage?._id ?? userProfile?.profileImage, token])
|
}, [profileImageDependency, token])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('userProfile', userProfile)
|
console.log('userProfile', userProfile)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user