current-file-container.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import ChangeEntry from './entries/change-entry'
  2. import AggregateChangeEntry from './entries/aggregate-change-entry'
  3. import CommentEntry from './entries/comment-entry'
  4. import AddCommentEntry from './entries/add-comment-entry'
  5. import BulkActionsEntry from './entries/bulk-actions-entry'
  6. import { useReviewPanelValueContext } from '../../context/review-panel/review-panel-context'
  7. import useCodeMirrorContentHeight from '../../hooks/use-codemirror-content-height'
  8. function CurrentFileContainer() {
  9. const { entries, openDocId, permissions } = useReviewPanelValueContext()
  10. const contentHeight = useCodeMirrorContentHeight()
  11. console.log('Review panel got content height', contentHeight)
  12. const currentDocEntries =
  13. openDocId && openDocId in entries ? entries[openDocId] : undefined
  14. return (
  15. <div
  16. id="review-panel-current-file"
  17. role="tabpanel"
  18. tabIndex={0}
  19. aria-labelledby="review-panel-tab-current-file"
  20. >
  21. <div
  22. className="rp-entry-list-inner"
  23. style={{ height: `${contentHeight}px` }}
  24. >
  25. {currentDocEntries &&
  26. Object.entries(currentDocEntries).map(([id, entry]) => {
  27. if (!entry.visible) {
  28. return null
  29. }
  30. if (entry.type === 'insert' || entry.type === 'delete') {
  31. return <ChangeEntry key={id} />
  32. }
  33. if (entry.type === 'aggregate-change') {
  34. return <AggregateChangeEntry key={id} />
  35. }
  36. if (entry.type === 'comment') {
  37. return <CommentEntry key={id} />
  38. }
  39. if (entry.type === 'add-comment' && permissions.comment) {
  40. return <AddCommentEntry key={id} />
  41. }
  42. if (entry.type === 'bulk-actions') {
  43. return <BulkActionsEntry key={id} />
  44. }
  45. return null
  46. })}
  47. </div>
  48. </div>
  49. )
  50. }
  51. export default CurrentFileContainer