diff --git a/flipper-plugin-realm/src/components/DataTable.tsx b/flipper-plugin-realm/src/components/DataTable.tsx index a2e149b..05f5c76 100644 --- a/flipper-plugin-realm/src/components/DataTable.tsx +++ b/flipper-plugin-realm/src/components/DataTable.tsx @@ -2,6 +2,7 @@ import { PlusOutlined } from '@ant-design/icons'; import { Button, Table } from 'antd'; import { ColumnsType, + ExpandableConfig, FilterValue, SorterResult, TablePaginationConfig, @@ -25,10 +26,9 @@ export type ColumnType = { type DataTableProps = { - columns: ColumnType[]; objects: DeserializedRealmObject[]; schemas: SortedObjectSchema[]; - currentSchema: Realm.CanonicalObjectSchema; + currentSchema: SortedObjectSchema; sortingDirection?: 'ascend' | 'descend' | null; sortingColumn: string | null; generateMenuItems?: MenuItemGenerator; @@ -46,9 +46,10 @@ type DataTableProps = { wipeStacks?: boolean, ) => void; clickAction?: (object: DeserializedRealmObject) => void; + getObject: (object: RealmObjectReference, objectSchemaName: string) => Promise; }; -type ClickableTextType = { +type ClickableTextProps = { displayText: string | number | JSX.Element; isLongString: boolean; value: PlainRealmObject | RealmObjectReference; @@ -57,7 +58,7 @@ type ClickableTextType = { }; // Receives a schema and returns column objects for the table. -export const schemaObjToColumns = ( +const schemaObjectToColumns = ( schema: SortedObjectSchema, ): ColumnType[] => { return schema.order.map((propertyName) => { @@ -75,7 +76,6 @@ export const schemaObjToColumns = ( export const DataTable = (dataTableProps: DataTableProps) => { const { - columns, objects, schemas, currentSchema, @@ -90,6 +90,7 @@ export const DataTable = (dataTableProps: DataTableProps) => { totalObjects = 0, fetchMore = () => undefined, clickAction, + getObject, } = dataTableProps; const instance = usePlugin(plugin); const state = useValue(instance.state); @@ -108,13 +109,14 @@ export const DataTable = (dataTableProps: DataTableProps) => { expandedRowRender: () => { return <>; }, + expandedRowKeys: [], showExpandColumn: false, - }); + } as ExpandableConfig); /** Hook to close the nested Table when clicked outside of it. */ useEffect(() => { const closeNestedTable = () => { - setRowExpansionProp({ ...rowExpansionProp }); + setRowExpansionProp({ ...rowExpansionProp, expandedRowKeys: [] }); }; document.body.addEventListener('click', closeNestedTable); return () => document.body.removeEventListener('click', closeNestedTable); @@ -139,7 +141,7 @@ export const DataTable = (dataTableProps: DataTableProps) => { value, inspectorView, isReference = false, - }: ClickableTextType) => { + }: ClickableTextProps) => { const [isHovering, setHovering] = useState(false); return (
@@ -171,20 +173,18 @@ export const DataTable = (dataTableProps: DataTableProps) => { }; /** Definition of antd-specific columns. This constant is passed to the antd table as a property. */ - const antdColumns:ColumnsType = columns.map((column) => { + const antdColumns:ColumnsType = schemaObjectToColumns(currentSchema).map((column) => { const property: Realm.CanonicalObjectSchemaProperty = currentSchema.properties[column.name]; - + const linkedSchema = schemas.find( + (schema) => property && schema.name === property.objectType, + ); /* A function that is applied for every cell to specify what to render in each cell on top of the pure value specified in the 'dataSource' property of the antd table.*/ - const render = (value: PlainRealmObject, row: DeserializedRealmObject) => { + const render = (value: PlainRealmObject | RealmObjectReference, row: DeserializedRealmObject) => { /** Apply the renderValue function on the value in the cell to create a standard cell. */ const cellValue = renderValue(value, property, schemas); - const linkedSchema = schemas.find( - (schema) => schema.name === property.objectType, - ); - /** Render buttons to expand the row and a clickable text if the cell contains a linked or embedded Realm object. */ if (value !== null && linkedSchema && property.type === 'object') { const isEmbedded = linkedSchema.embedded; @@ -197,21 +197,26 @@ export const DataTable = (dataTableProps: DataTableProps) => { gap: '5px', }} > -