/* * Copyright 2025 Commonwealth Scientific and Industrial Research * Organisation (CSIRO) ABN 41 687 119 230. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React from 'react'; import { QGroupContainerBox } from '../../Box.styles'; import TableContainer from '@mui/material/TableContainer'; import Paper from '@mui/material/Paper'; import Table from '@mui/material/Table'; import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; import { HeaderTableCell } from './Table.styles'; import TableCell from '@mui/material/TableCell'; import Divider from '@mui/material/Divider'; import AddRowButton from './AddRowButton'; import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4'; import type { PropsWithIsRepeatedAttribute, PropsWithParentIsReadOnlyAttribute, PropsWithParentStylesAttribute } from '../../../interfaces/renderProps.interface'; import type { GroupTableRowModel } from '../../../interfaces/groupTable.interface'; import GroupTableBody from './GroupTableBody'; import { useQuestionnaireStore, useRendererConfigStore } from '../../../stores'; import { interpolate } from '../../../i18n'; import { getGroupCollapsible } from '../../../utils/qItem'; import AccordionSummary from '@mui/material/AccordionSummary'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import AccordionDetails from '@mui/material/AccordionDetails'; import GroupHeading from '../GroupItem/GroupHeading'; import { StandardCheckbox } from '../../Checkbox.styles'; import { Box } from '@mui/material'; import { itemHasLabelHeadingContent } from '../../../utils/itemTextToDisplay'; import { isGroupAddItemButtonHidden } from '../../../utils/extensions'; import GroupAccordion from '../GroupItem/GroupAccordion'; interface GroupTableViewProps extends PropsWithIsRepeatedAttribute, PropsWithParentIsReadOnlyAttribute, PropsWithParentStylesAttribute { qItem: QuestionnaireItem; qItemsIndexMap: Record; groupCardElevation: number; readOnly: boolean; tableRows: GroupTableRowModel[]; selectedIds: string[]; visibleItemLabels: string[]; calculatedColumnWidths: { width: string; isFixed: boolean }[]; onAddRow: () => void; onRowChange: (newQrRow: QuestionnaireResponseItem, index: number) => void; onRemoveRow: (index: number) => void; onSelectRow: (rowId: string) => void; onSelectAll: () => void; onReorderRows: (newTableRows: GroupTableRowModel[]) => void; } function GroupTableView(props: GroupTableViewProps) { const { qItem, qItemsIndexMap, groupCardElevation, isRepeated, readOnly, tableRows, selectedIds, visibleItemLabels, calculatedColumnWidths, parentIsReadOnly, parentStyles, onAddRow, onRowChange, onRemoveRow, onSelectRow, onSelectAll, onReorderRows } = props; const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId(); const readOnlyVisualStyle = useRendererConfigStore.use.readOnlyVisualStyle(); const rendererStrings = useRendererConfigStore.use.rendererStrings(); const selectAllRowsLabel = interpolate(rendererStrings.selectAllRows, { label: qItem.text ?? interpolate(rendererStrings.unnamedItem, { type: qItem.type }) }); const groupCollapsibleValue = getGroupCollapsible(qItem); const indeterminateValue = selectedIds.length > 0 && selectedIds.length < tableRows.length; const checkedValue = tableRows.length > 0 && selectedIds.length === tableRows.length; const ariaCheckedValue = indeterminateValue ? 'mixed' : checkedValue ? 'true' : 'false'; const showExtraGTableInteractions = isRepeated && !readOnly; const showGroupHeading = itemHasLabelHeadingContent(qItem); // If the table is collapsible, wrap it in an accordion if (groupCollapsibleValue) { const isDefaultOpen = groupCollapsibleValue === 'default-open'; return ( } sx={{ minHeight: '28px' }}> {showGroupHeading ? ( ) : null} {showGroupHeading ? : null} {showExtraGTableInteractions && !isGroupAddItemButtonHidden(qItem) ? ( ) : null} {showExtraGTableInteractions ? ( ) : null} {visibleItemLabels.map((visibleItemLabel) => ( {visibleItemLabel} ))}
); } // Regular GTable return ( onFocusLinkId(qItem.linkId)} style={parentStyles || undefined}> {showGroupHeading ? ( <> ) : null} {showExtraGTableInteractions && !isGroupAddItemButtonHidden(qItem) ? ( ) : null} {showExtraGTableInteractions ? ( ) : null} {visibleItemLabels.map((visibleItemLabel) => ( {visibleItemLabel} ))}
); } export default GroupTableView;