Compare commits

..

No commits in common. "bef3e47d29235fece6534034c01ae4514ec943d3" and "8f369d777d249aa62f8da9a7350157964ec7c247" have entirely different histories.

6 changed files with 62 additions and 140 deletions

View File

@ -82,7 +82,7 @@ const ExportListButton = ({
}, },
{ {
key: 'rss', key: 'rss',
label: 'RSS Feed', label: 'RSS Feed Connection',
icon: <RssIcon />, icon: <RssIcon />,
onClick: () => setRssModalOpen(true) onClick: () => setRssModalOpen(true)
} }

View File

@ -136,7 +136,7 @@ const FilterSidebar = ({
} }
return ( return (
<Card style={{ flexShrink: 0, height: '100%' }}> <Card style={{ width: '25%', flexShrink: 0, height: '100%' }}>
<Flex vertical gap='middle'> <Flex vertical gap='middle'>
<Flex justify='space-between'> <Flex justify='space-between'>
<Dropdown menu={menuItems} trigger={['hover']} placement='bottomLeft'> <Dropdown menu={menuItems} trigger={['hover']} placement='bottomLeft'>
@ -158,14 +158,14 @@ const FilterSidebar = ({
value={row.field || undefined} value={row.field || undefined}
onChange={(v) => changeField(row.field, v)} onChange={(v) => changeField(row.field, v)}
options={availableOptions(row.field)} options={availableOptions(row.field)}
style={{ minWidth: 80 }} style={{ minWidth: 80, flex: 1 }}
allowClear={false} allowClear={false}
/> />
<Input <Input
placeholder='Value' placeholder='Value'
value={row.value} value={row.value}
onChange={(e) => changeValue(row.field, e.target.value)} onChange={(e) => changeValue(row.field, e.target.value)}
style={{ flex: 1 }} style={{ width: 160 }}
/> />
<Button <Button
icon={<CloseOutlined />} icon={<CloseOutlined />}

View File

@ -1,11 +1,11 @@
import { useMemo, useEffect, useRef, useState } from 'react' import { useMemo, useEffect, useRef } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Table, Skeleton, Card, Button, Flex, Typography, Modal } from 'antd' import { Table, Skeleton, Card, Button, Flex, Typography } from 'antd'
import PlusIcon from '../../Icons/PlusIcon' import PlusIcon from '../../Icons/PlusIcon'
import ObjectProperty from './ObjectProperty' import ObjectProperty from './ObjectProperty'
import { LoadingOutlined } from '@ant-design/icons' import { LoadingOutlined } from '@ant-design/icons'
import BinIcon from '../../Icons/BinIcon' import BinIcon from '../../Icons/BinIcon'
const { Text, Link, Title } = Typography const { Text } = Typography
const DEFAULT_COLUMN_WIDTHS = { const DEFAULT_COLUMN_WIDTHS = {
text: 200, text: 200,
@ -64,44 +64,10 @@ const ObjectChildTable = ({
value = [], value = [],
rollups = [], rollups = [],
onChange, onChange,
minimal = false,
label = '',
...tableProps ...tableProps
}) => { }) => {
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 [minimalModelOpen, setMinimalModelOpen] = useState(false)
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()
@ -164,14 +130,10 @@ 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)
@ -224,11 +186,10 @@ 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 resolved keys. // If rowKey is a function, find the item by comparing the resolved keys
// Ant Design deprecates index-based rowKey callbacks. const recordKey = rowKey(record, index)
const recordKey = getResolvedRecordKey(record) newItems = currentItems.filter((item, i) => {
newItems = currentItems.filter((item) => { const itemKey = rowKey(item, i)
const itemKey = getResolvedRecordKey(item)
return itemKey !== recordKey return itemKey !== recordKey
}) })
} else { } else {
@ -255,7 +216,6 @@ const ObjectChildTable = ({
resolvedProperties, resolvedProperties,
additionalColumns, additionalColumns,
isEditing, isEditing,
canAddRemove,
itemsSource, itemsSource,
onChange, onChange,
rowKey rowKey
@ -276,7 +236,8 @@ const ObjectChildTable = ({
return itemsSource return itemsSource
}, [itemsSource, loading, skeletonData]) }, [itemsSource, loading, skeletonData])
const resolvedRowKey = (record) => getResolvedRecordKey(record) const resolvedRowKey =
typeof rowKey === 'function' ? rowKey : (_record, index) => index
const scrollConfig = const scrollConfig =
scrollHeight != null scrollHeight != null
@ -320,9 +281,7 @@ 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(
@ -395,7 +354,7 @@ const ObjectChildTable = ({
...propertyColumns, ...propertyColumns,
...(blankDeleteColumn ? [blankDeleteColumn] : []) ...(blankDeleteColumn ? [blankDeleteColumn] : [])
] ]
}, [properties, rollups, isEditing, canAddRemove]) }, [properties, rollups, isEditing])
const hasRollups = useMemo( const hasRollups = useMemo(
() => Array.isArray(rollups) && rollups.length > 0, () => Array.isArray(rollups) && rollups.length > 0,
@ -455,14 +414,13 @@ const ObjectChildTable = ({
dataSource={rollupDataSource} dataSource={rollupDataSource}
showHeader={false} showHeader={false}
columns={rollupColumns} columns={rollupColumns}
loading={{ spinning: loading, indicator: null }} loading={{ spinning: loading, indicator: <></> }}
pagination={false} pagination={false}
size={size} size={size}
rowKey={resolvedRowKey} rowKey={resolvedRowKey}
scroll={scrollConfig} scroll={scrollConfig}
locale={{ emptyText }} locale={{ emptyText }}
bordered={true} style={{ maxWidth, minWidth: 0 }}
style={{ maxWidth: minimal ? '100%' : maxWidth, minWidth: 0 }}
className='rollup-table' className='rollup-table'
/> />
</div> </div>
@ -472,14 +430,13 @@ const ObjectChildTable = ({
<Flex vertical> <Flex vertical>
<div ref={mainTableWrapperRef}> <div ref={mainTableWrapperRef}>
<Table <Table
style={{ maxWidth: minimal ? '100%' : maxWidth, minWidth: 0 }} style={{ maxWidth, minWidth: 0 }}
dataSource={dataSource} dataSource={dataSource}
columns={tableColumns} columns={tableColumns}
loading={{ spinning: loading, indicator: <LoadingOutlined spin /> }} loading={{ spinning: loading, indicator: <LoadingOutlined spin /> }}
size={size} size={size}
rowKey={resolvedRowKey} rowKey={resolvedRowKey}
scroll={scrollConfig} scroll={scrollConfig}
bordered={true}
locale={{ emptyText }} locale={{ emptyText }}
pagination={false} pagination={false}
className={hasRollups ? 'child-table-rollups' : 'child-table'} className={hasRollups ? 'child-table-rollups' : 'child-table'}
@ -512,34 +469,6 @@ const ObjectChildTable = ({
) )
} }
if (minimal == true) {
return (
<>
<Link
onClick={() => {
setMinimalModelOpen(true)
}}
>
{value?.length || 0} {value?.length == 1 ? 'item' : 'items'}
</Link>
<Modal
open={minimalModelOpen}
onCancel={() => setMinimalModelOpen(false)}
footer={null}
width='860px'
>
<Title
level={2}
style={{ marginTop: 0, lineHeight: '0.7', marginBottom: 20 }}
>
{label}
</Title>
{tableComponent}
</Modal>
</>
)
}
return tableComponent return tableComponent
} }
@ -561,15 +490,13 @@ ObjectChildTable.propTypes = {
skeletonRows: PropTypes.number, skeletonRows: PropTypes.number,
additionalColumns: PropTypes.arrayOf(PropTypes.object), additionalColumns: PropTypes.arrayOf(PropTypes.object),
emptyText: PropTypes.node, emptyText: PropTypes.node,
label: PropTypes.string,
isEditing: PropTypes.bool, isEditing: PropTypes.bool,
value: PropTypes.arrayOf(PropTypes.object), value: PropTypes.arrayOf(PropTypes.object),
onChange: PropTypes.func, onChange: PropTypes.func,
maxWidth: PropTypes.string, maxWidth: PropTypes.string,
rollups: PropTypes.arrayOf(PropTypes.object), rollups: PropTypes.arrayOf(PropTypes.object),
objectData: PropTypes.object, objectData: PropTypes.object,
canAddRemove: PropTypes.bool, canAddRemove: PropTypes.bool
minimal: PropTypes.bool
} }
export default ObjectChildTable export default ObjectChildTable

View File

@ -422,8 +422,6 @@ const ObjectProperty = ({
loading={loading} loading={loading}
rollups={rollups} rollups={rollups}
size={size} size={size}
minimal={minimal}
label={label}
canAddRemove={canAddRemove} canAddRemove={canAddRemove}
/> />
) )

View File

@ -19,8 +19,7 @@ import {
Input, Input,
Space, Space,
Tooltip, Tooltip,
Form, Form
Splitter
} from 'antd' } from 'antd'
import { LoadingOutlined } from '@ant-design/icons' import { LoadingOutlined } from '@ant-design/icons'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
@ -941,8 +940,6 @@ const ObjectTable = forwardRef(
const tableContent = ( const tableContent = (
<Flex gap={'middle'} vertical style={{ flex: 1, minWidth: 0 }}> <Flex gap={'middle'} vertical style={{ flex: 1, minWidth: 0 }}>
<Splitter className={'farmcontrol-splitter'}>
<Splitter.Panel>
{cards ? ( {cards ? (
<Spin indicator={<LoadingOutlined />} spinning={loading}> <Spin indicator={<LoadingOutlined />} spinning={loading}>
{renderCards()} {renderCards()}
@ -956,10 +953,7 @@ const ObjectTable = forwardRef(
pagination={false} pagination={false}
scroll={{ y: adjustedScrollHeight }} scroll={{ y: adjustedScrollHeight }}
rowKey='_id' rowKey='_id'
loading={{ loading={{ spinning: loading, indicator: <LoadingOutlined spin /> }}
spinning: loading,
indicator: <LoadingOutlined spin />
}}
onScroll={handleScroll} onScroll={handleScroll}
onChange={handleTableChange} onChange={handleTableChange}
showSorterTooltip={false} showSorterTooltip={false}
@ -969,20 +963,26 @@ const ObjectTable = forwardRef(
onRow={onRow} onRow={onRow}
/> />
)} )}
</Splitter.Panel> </Flex>
{showFilterSidebar && ( )
<Splitter.Panel>
if (showFilterSidebar) {
return (
<Flex
gap='middle'
align='flex-start'
style={{ width: '100%', height: '100%' }}
>
{tableContent}
<FilterSidebar <FilterSidebar
type={type} type={type}
filter={sidebarFilter} filter={sidebarFilter}
onFilterChange={handleSidebarFilterChange} onFilterChange={handleSidebarFilterChange}
masterFilter={masterFilter} masterFilter={masterFilter}
/> />
</Splitter.Panel>
)}
</Splitter>
</Flex> </Flex>
) )
}
return tableContent return tableContent
} }

View File

@ -291,9 +291,6 @@ 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
@ -368,7 +365,7 @@ const AuthProvider = ({ children }) => {
} }
setProfileImageUrl(null) setProfileImageUrl(null)
} }
}, [profileImageDependency, token]) }, [userProfile?.profileImage?._id ?? userProfile?.profileImage, token])
useEffect(() => { useEffect(() => {
console.log('userProfile', userProfile) console.log('userProfile', userProfile)