row.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import { memo } from 'react';
  2. import { View, Row } from 'app/design/view';
  3. import Cell from './cell';
  4. import { useGrid } from './context';
  5. /**
  6. * One row of the grid. Memoized because the list re-renders on every fetch and
  7. * on every selection change, while a row itself only depends on its own data.
  8. * Column tracks and `field_id` come from the store — both are computed once per
  9. * grid, so subscribing here keeps `item` the only prop.
  10. */
  11. export default memo(function GridRow({ item }) {
  12. const columns = useGrid((state) => state.columns);
  13. const fieldId = useGrid((state) => state.fieldId);
  14. const id = item[fieldId];
  15. return (
  16. <Row className="w-full items-center gap-2 px-2 py-2 border-b border-border/60 web:hover:bg-muted/40">
  17. {columns.map((column, index) => (
  18. <View
  19. key={column.name + index}
  20. style={column.style}
  21. className={`justify-center min-h-9 min-w-0 ${column.align}`}
  22. >
  23. <Cell cell={item[column.name]} id={id} />
  24. </View>
  25. ))}
  26. </Row>
  27. );
  28. });