Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

174 - Refine UI styling Files Tab #175

Merged
merged 8 commits into from
Sep 25, 2023
15,454 changes: 8,459 additions & 6,995 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,18 @@ $navbar-brand-font-size: $dv-brand-font-size;

.navbar-collapse {
justify-content: end;
}

th {
vertical-align: middle;
}

.btn-group > div:not(:last-child) > .btn-group > .btn, .btn-group-vertical >div:not(:last-child) > .btn-group > .btn {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

.btn-group > div:not(:first-child) > .btn-group > .btn, .btn-group-vertical > div:not(:first-child) > .btn-group > .btn {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Button } from '../../components/button/Button'
import { ButtonToolbar } from '../../components/button-group/ButtonToolbar'
import { DropdownButton } from '../../components/dropdown-button/DropdownButton'
import { DropdownButtonItem } from '../../components/dropdown-button/dropdown-button-item/DropdownButtonItem'
import { Download, ThreeDotsVertical } from 'react-bootstrap-icons'
import { Tooltip } from '../../components/tooltip/Tooltip'

/**
* ## Description
Expand Down Expand Up @@ -76,3 +78,32 @@ export const NestedButtonGroups: Story = {
</ButtonToolbar>
)
}

export const ButtonGroupWithTooltips: Story = {
render: () => (
<ButtonGroup>
<Tooltip placement="top" overlay="Access File">
<DropdownButton
id={`action-button-access-file`}
title=""
asButtonGroup
variant="secondary"
icon={<Download aria-label="Access File" />}>
<DropdownButtonItem href="/item-1">Item 1</DropdownButtonItem>
<DropdownButtonItem href="/item-2">Item 2</DropdownButtonItem>
</DropdownButton>
</Tooltip>
<Tooltip placement="top" overlay={<span>File Options</span>}>
<DropdownButton
id={`file-options-file`}
title=""
asButtonGroup
variant="secondary"
icon={<ThreeDotsVertical aria-label="File Options" />}>
<DropdownButtonItem href="/item-1">Item 1</DropdownButtonItem>
<DropdownButtonItem href="/item-2">Item 2</DropdownButtonItem>
</DropdownButton>
</Tooltip>
</ButtonGroup>
)
}
19 changes: 19 additions & 0 deletions src/sections/dataset/dataset-files/files-table/FilesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,22 @@ export function FilesTable({ files, isLoading, paginationInfo }: FilesTableProps
</>
)
}

export function getCellStyle(cellId: string) {
const statusCellId = 'status'
const infoCellId = 'info'

if (cellId == 'select') {
return { verticalAlign: 'middle' }
}

if (cellId == statusCellId) {
return { borderWidth: '0 1px 0 0' }
}

if (cellId == infoCellId) {
return { borderWidth: '0 0 0 1px' }
}

return undefined
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { flexRender, Row } from '@tanstack/react-table'
import { File } from '../../../../files/domain/models/File'
import { useTranslation } from 'react-i18next'
import styles from './FilesTable.module.scss'
import { getCellStyle } from './FilesTable'

interface FilesTableBodyProps {
rows: Row<File>[]
Expand All @@ -17,8 +18,11 @@ export function FilesTableBody({ rows }: FilesTableBodyProps) {
return (
<tr key={row.id} className={row.getIsSelected() ? styles['selected-row'] : ''}>
{row.getVisibleCells().map((cell) => {
const cellIdWithoutPrefix = cell.id.split('_').slice(1).join('_')
return (
<td key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</td>
<td key={cell.id} style={getCellStyle(cellIdWithoutPrefix)}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
)
})}
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { flexRender, HeaderGroup } from '@tanstack/react-table'
import { File } from '../../../../files/domain/models/File'
import styles from './FilesTable.module.scss'
import { getCellStyle } from './FilesTable'

interface FilesTableHeaderProps {
headers: HeaderGroup<File>[]
Expand All @@ -13,7 +14,11 @@ export function FilesTableHeader({ headers }: FilesTableHeaderProps) {
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => {
return (
<th key={header.id} colSpan={header.colSpan} className={styles[header.id]}>
<th
key={header.id}
colSpan={header.colSpan}
className={styles[header.id]}
style={getCellStyle(header.id)}>
{header.isPlaceholder ? null : (
<>{flexRender(header.column.columnDef.header, header.getContext())}</>
)}
Expand Down
13 changes: 7 additions & 6 deletions tests/component/files/domain/models/FilesCountInfoMother.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,37 @@ import { FileAccessOption, FileTag } from '../../../../../src/files/domain/model

export class FilesCountInfoMother {
static create(props?: Partial<FilesCountInfo>): FilesCountInfo {
const total = props?.total ?? faker.datatype.number()
return {
total: faker.datatype.number(),
perFileType: [
{
type: new FileType(faker.system.fileType()),
count: faker.datatype.number()
count: faker.datatype.number({ max: total })
},
{
type: new FileType(faker.system.fileType()),
count: faker.datatype.number()
count: faker.datatype.number({ max: total })
}
],
perAccess: [
{
access: faker.helpers.arrayElement(Object.values(FileAccessOption)),
count: faker.datatype.number()
count: faker.datatype.number({ max: total })
},
{
access: faker.helpers.arrayElement(Object.values(FileAccessOption)),
count: faker.datatype.number()
count: faker.datatype.number({ max: total })
}
],
perFileTag: [
{
tag: new FileTag(faker.lorem.word()),
count: faker.datatype.number()
count: faker.datatype.number({ max: total })
},
{
tag: new FileTag(faker.lorem.word()),
count: faker.datatype.number()
count: faker.datatype.number({ max: total })
}
],
...props
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { FileMother } from '../../../../files/domain/models/FileMother'
import { FilesTable } from '../../../../../../src/sections/dataset/dataset-files/files-table/FilesTable'
import {
FilesTable,
getCellStyle
} from '../../../../../../src/sections/dataset/dataset-files/files-table/FilesTable'
import { FileSize, FileSizeUnit } from '../../../../../../src/files/domain/models/File'
import { SettingMother } from '../../../../settings/domain/models/SettingMother'
import { ZipDownloadLimit } from '../../../../../../src/settings/domain/models/ZipDownloadLimit'
Expand Down Expand Up @@ -144,4 +147,21 @@ describe('FilesTable', () => {

cy.findByRole('columnheader', { name: 'File Actions' }).should('exist')
})

describe('getCellStyle function', () => {
it('should return the correct style for status cell', () => {
const cellId = 'status'
cy.wrap(getCellStyle(cellId)).should('deep.equal', { borderWidth: '0 1px 0 0' })
})

it('should return the correct style for info cell', () => {
const cellId = 'info'
cy.wrap(getCellStyle(cellId)).should('deep.equal', { borderWidth: '0 0 0 1px' })
})

it('should return undefined for unknown cell', () => {
const cellId = 'unknown'
cy.wrap(getCellStyle(cellId)).should('be.undefined')
})
})
})
Loading