import * as React from 'react' import { CollectionColumnTitle } from './collection-column-title' import { CollectionGroup } from './collection-group' import { CollectionViewProps } from '../types' import { cs } from '../utils' import { getCollectionGroups } from './collection-utils' import { Property } from './property' import { useNotionContext } from '../context' const defaultBlockIds = [] export const CollectionViewTable: React.FC = ({ collection, collectionView, collectionData, padding, width }) => { const isGroupedCollection = collectionView?.format?.collection_group_by if (isGroupedCollection) { const collectionGroups = getCollectionGroups( collection, collectionView, collectionData, padding, width ) return collectionGroups.map((group, index) => ( ( )} summaryProps={{ style: { paddingLeft: padding, paddingRight: padding } }} /> )) } const blockIds = (collectionData['collection_group_results']?.blockIds ?? collectionData.blockIds) || defaultBlockIds return (
) } function Table({ blockIds = [], collection, collectionView, width, padding }) { const { recordMap, linkTableTitleProperties } = useNotionContext() const tableStyle = React.useMemo( () => ({ width, maxWidth: width }), [width] ) const tableViewStyle = React.useMemo( () => ({ paddingLeft: padding, paddingRight: padding }), [padding] ) let properties = [] if (collectionView.format?.table_properties) { properties = collectionView.format.table_properties.filter( (p) => p.visible && collection.schema[p.property] ) } else { properties = [{ property: 'title' }].concat( Object.keys(collection.schema) .filter((p) => p !== 'title') .map((property) => ({ property })) ) } return (
{!!properties.length && ( <>
{properties.map((p) => { const schema = collection.schema?.[p.property] const isTitle = p.property === 'title' const style: React.CSSProperties = {} if (p.width) { style.width = p.width } else if (isTitle) { style.width = 280 } else { style.width = 200 // style.width = `${100.0 / properties.length}%` } return (
) })}
{blockIds?.map((blockId) => (
{properties.map((p) => { const schema = collection.schema?.[p.property] const block = recordMap.block[blockId]?.value const data = block?.properties?.[p.property] const isTitle = p.property === 'title' const style: React.CSSProperties = {} if (p.width) { style.width = p.width } else if (isTitle) { style.width = 280 } else { style.width = 200 // style.width = `${100.0 / properties.length}%` } return (
) })}
))}
)}
) }