Compare commits

...

3 Commits

4 changed files with 59 additions and 17 deletions

View File

@ -47,6 +47,7 @@ const createSkeletonRows = (rowCount, keyPrefix, keyName) => {
const ObjectChildTable = ({
maxWidth = '100%',
name,
properties = [],
columns = [],
visibleColumns = {},
@ -264,6 +265,17 @@ const ObjectChildTable = ({
const rollupDataSource = useMemo(() => {
if (!rollups || rollups.length === 0) return []
// Use value from form/props, or fall back to objectData when entering edit mode
// (form may not have populated the field yet)
const itemsForRollup =
value ?? (name && objectData ? objectData[name] : null) ?? []
// Build parent object with children array for rollup functions (e.g. objectData.parts)
const updatedObjectData = { ...objectData }
if (name) {
updatedObjectData[name] = itemsForRollup
}
// Single summary row where each rollup value is placed under
// the column that matches its `property` field.
const summaryRow = {}
@ -275,8 +287,6 @@ const ObjectChildTable = ({
if (rollup && typeof rollup.value === 'function') {
try {
const updatedObjectData = { ...objectData }
updatedObjectData[property.name] = value
summaryRow[property.name] = rollup.value(updatedObjectData)
} catch (e) {
// Fail quietly but log for debugging
@ -289,7 +299,7 @@ const ObjectChildTable = ({
})
return [summaryRow]
}, [properties, rollups, objectData, value])
}, [properties, rollups, objectData, value, name])
const rollupColumns = useMemo(() => {
const propertyColumns = properties.map((property, index) => {
@ -455,6 +465,7 @@ const ObjectChildTable = ({
}
ObjectChildTable.propTypes = {
name: PropTypes.string,
properties: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,

View File

@ -31,12 +31,33 @@ const ObjectDisplay = ({
setObjectData((prev) => merge({}, prev, value))
}, [])
// Detect minimal objects that only contain an _id
// Ensure ID is valid before hydrate/subscribe (non-empty, not null/undefined)
const isValidId = useCallback((id) => {
return id != null && String(id).trim() !== ''
}, [])
// Extract string ID from object; handles both primitive _id and populated ref (_id as object)
const getStringId = useCallback((obj) => {
const id = obj?._id
if (id == null) return null
if (typeof id === 'string') return id
if (typeof id === 'object' && id !== null && typeof id._id === 'string')
return id._id
return null
}, [])
// Detect minimal objects that only contain an _id (must be string, not populated object)
const isMinimalObject = useCallback((obj) => {
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return false
const keys = Object.keys(obj)
return keys.length === 1 && keys[0] === '_id' && obj._id
}, [])
const id = obj._id
return (
keys.length === 1 &&
keys[0] === '_id' &&
typeof id === 'string' &&
isValidId(id)
)
}, [isValidId])
// If only an _id is provided, fetch the full object via spotlight
const fetchFullObjectIfNeeded = useCallback(
@ -64,9 +85,10 @@ const ObjectDisplay = ({
// Subscribe to object updates when component mounts
useEffect(() => {
if (object?._id && objectType && connected && token != null) {
const id = getStringId(object)
if (isValidId(id) && objectType && connected && token != null) {
const objectUpdatesUnsubscribe = subscribeToObjectUpdates(
object._id,
id,
objectType,
updateObjectEventHandler
)
@ -76,27 +98,31 @@ const ObjectDisplay = ({
}
}
}, [
object?._id,
object,
objectType,
subscribeToObjectUpdates,
connected,
token,
updateObjectEventHandler
updateObjectEventHandler,
isValidId,
getStringId
])
// Update local state when object prop changes
useEffect(() => {
if (token == null) return
const id = getStringId(object)
if (!isValidId(id)) return
const isMinimal = isMinimalObject(object)
// Only skip re-fetch when we have a minimal object and already hydrated this id
if (isMinimal && idRef.current === object?._id) return
if (isMinimal && idRef.current === id) return
let cancelled = false
if (isMinimal) setIsHydrating(true)
const hydrateObject = async () => {
const fullObject = await fetchFullObjectIfNeeded(object)
if (!cancelled) {
setObjectData((prev) => merge({}, prev, fullObject))
if (isMinimal) idRef.current = object?._id
if (isMinimal) idRef.current = id
setIsHydrating(false)
}
}
@ -105,7 +131,7 @@ const ObjectDisplay = ({
cancelled = true
setIsHydrating(false)
}
}, [object, fetchFullObjectIfNeeded, isMinimalObject, token])
}, [object, fetchFullObjectIfNeeded, isMinimalObject, isValidId, getStringId, token])
if (!objectData) {
return <Text type='secondary'>n/a</Text>
}
@ -137,7 +163,7 @@ const ObjectDisplay = ({
var hyperlink = null
const defaultModelActions =
model.actions?.filter((action) => action.default == true) || []
const objectId = objectData._id
const objectId = getStringId(objectData)
if (defaultModelActions.length >= 1 && objectId) {
hyperlink = defaultModelActions[0].url(objectId)
@ -229,9 +255,9 @@ const ObjectDisplay = ({
<div style={{ minWidth: 0 }}>
{renderNameDisplay()}
{objectData?._id && !objectData?.name ? (
{objectId && !objectData?.name ? (
<IdDisplay
id={objectData?._id}
id={objectId}
reference={objectData?._reference || undefined}
type={objectType}
longId={false}

View File

@ -407,6 +407,7 @@ const ObjectProperty = ({
case 'objectChildren': {
return (
<ObjectChildTable
name={name}
value={value}
properties={properties}
objectData={objectData}
@ -797,6 +798,7 @@ const ObjectProperty = ({
case 'objectChildren': {
return (
<ObjectChildTable
name={name}
properties={properties}
objectData={objectData}
isEditing={true}

View File

@ -12,6 +12,7 @@ import { AuthContext } from './AuthContext'
import { ApiServerContext } from './ApiServerContext'
import NotificationCenter from '../common/NotificationCenter'
import Notification from '../common/Notification'
import { useMediaQuery } from 'react-responsive'
const NotificationContext = createContext()
@ -34,6 +35,8 @@ const NotificationProvider = ({ children }) => {
const [notifications, setNotifications] = useState([])
const [notificationsLoading, setNotificationsLoading] = useState(false)
const isMobile = useMediaQuery({ maxWidth: 768 })
const fetchNotifications = useCallback(async () => {
if (!authenticated) return []
setNotificationsLoading(true)
@ -174,7 +177,7 @@ const NotificationProvider = ({ children }) => {
<Drawer
title='Notifications'
placement='right'
width={400}
width={isMobile ? '100%' : 460}
onClose={() => setNotificationCenterVisible(false)}
open={notificationCenterVisible}
>