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

feat(columns): custom columns #1241

Merged
merged 28 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5dc7364
feat(columns): added toggleColumn action to reducer
fredrbus Sep 25, 2023
6d0ba9f
feat(types): rewrote column type to easily get label
fredrbus Sep 25, 2023
4ff13c4
feat(columns): added ToggleColumns-button with popover
fredrbus Sep 25, 2023
296550d
feat(columns): implemented fixed order for columns
fredrbus Sep 25, 2023
cb5f5b3
feat(columns): user can sort their columns
fredrbus Sep 26, 2023
d31c6ec
feat(column ordering): columns can be ordered by dragging and dropping
fredrbus Sep 26, 2023
4a2129d
feat(accessibility): added aria label to sort handle
fredrbus Sep 26, 2023
f8dab37
feat(columns): changed sortHandle-icon, restricting DnD-movement to y…
fredrbus Sep 26, 2023
3a9195d
chore(columns): changed from switch to object when conditionally rend…
fredrbus Sep 26, 2023
acbf3e6
feat(columns): whole column is sortable
fredrbus Sep 26, 2023
aedca88
fix(columns): removed ordering from toggle-popover
fredrbus Sep 27, 2023
a1a1c6e
feat(columns): ordering by dragging column header
fredrbus Sep 27, 2023
e203e04
feat(columns): added tooltip to draggable column header
fredrbus Sep 28, 2023
80b8ca6
fix(columns): purged columnOrder from TBoards-type
fredrbus Sep 28, 2023
474e76d
fix(columns): removed className from SortableColumn
fredrbus Sep 28, 2023
78bac01
fix(columns): reverting SortableHandle
fredrbus Sep 28, 2023
661b76d
fix(columns): minor code quality improvements
fredrbus Sep 28, 2023
a2a8d50
fix(columns): reverting to switch in <Column />
fredrbus Sep 28, 2023
5a4f913
fix(columns): using variable as table header color
fredrbus Sep 28, 2023
539727c
feat(columns): created hook for useSortableAttributes
fredrbus Sep 28, 2023
b4c52ee
chore(columns): removed unused export from useSortableColumnAttributes
fredrbus Sep 28, 2023
534bee4
feat(columns): changed toggle-button icon
fredrbus Sep 28, 2023
03e35ef
fix(semantics): changed from h4 to h2 in toggleBoardsColumns
fredrbus Oct 2, 2023
5936956
fix(useSortableColumnAttributes): cleaning up hook and hook references
fredrbus Oct 2, 2023
960b80e
fix(boards): added minimum height to rows
fredrbus Oct 2, 2023
1cccb0b
fix(columns): added drag-n-drop restriction to window edges
fredrbus Oct 2, 2023
a0a1b6b
feat(styling): added new global classes for flexbox and spacing
fredrbus Oct 2, 2023
ab65790
fix(styling): replaced custom classes with globals
fredrbus Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import { useLink } from '../../hooks/useLink'
import { useToast } from '@entur/alert'
import classes from './styles.module.css'
import { DeleteBoardButton } from '../Delete'
import { SortableColumn } from './SortableColumn'

function Actions({ board }: { board: TBoard }) {
const link = useLink(board.id)
return (
<div className={classes.actions}>
<Edit bid={board.id} />
<Copy link={link} />
<Open link={link} />
<Delete board={board} />
</div>
<SortableColumn column="actions">
<div className={classes.actions}>
<Edit bid={board.id} />
<Copy link={link} />
<Open link={link} />
<Delete board={board} />
</div>
</SortableColumn>
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { formatTimestamp } from 'Admin/utils/time'
import { SortableColumn } from './SortableColumn'

function LastModified({ timestamp }: { timestamp?: number }) {
return <div>{formatTimestamp(timestamp)}</div>
return (
<SortableColumn column="lastModified">
{formatTimestamp(timestamp)}
</SortableColumn>
)
}

export { LastModified }
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useLink } from '../../hooks/useLink'
import { SortableColumn } from './SortableColumn'

function Link({ bid }: { bid?: string }) {
const link = useLink(bid)

return <div>{link}</div>
return <SortableColumn column="url">{link}</SortableColumn>
}
export { Link }
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DEFAULT_BOARD_NAME } from 'Admin/utils/constants'
import { SortableColumn } from './SortableColumn'

function Name({ name = DEFAULT_BOARD_NAME }: { name?: string }) {
return <div>{name}</div>
return <SortableColumn column="name">{name}</SortableColumn>
}

export { Name }
fredrbus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { TBoardsColumn } from 'Admin/types/boards'
import classes from './styles.module.css'
import { useSortableColumnAttributes } from '../../hooks/useSortableColumnAttributes'

function SortableColumn({
column,
children,
}: {
column: TBoardsColumn
children: React.ReactNode
}) {
const { setNodeRef, style } = useSortableColumnAttributes(column)

return (
<div
ref={setNodeRef}
style={style}
id={column}
className={classes.column}
>
{children}
</div>
)
}

export { SortableColumn }
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
display: flex;
gap: 0.5em;
}

.column {
padding-left: 0.25em;
min-height: 2.25rem;
display: flex;
align-items: center;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { BoardsColumns, TBoardsColumn } from 'Admin/types/boards'
import classes from './styles.module.css'
import { Sort } from '../Sort'
import { Tooltip } from '@entur/tooltip'
import { useSortableColumnAttributes } from '../../hooks/useSortableColumnAttributes'

function ColumnHeader({ column }: { column: TBoardsColumn }) {
const { attributes, listeners, setNodeRef, style } =
useSortableColumnAttributes(column)

return (
<div
ref={setNodeRef}
style={style}
key={column}
className={classes.header}
>
<Tooltip placement="top" content="Dra for å flytte">
<div
{...attributes}
{...listeners}
id={column}
className={classes.title}
>
{BoardsColumns[column]}
</div>
</Tooltip>
<Sort column={column} />
</div>
)
}

export { ColumnHeader }
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
import { useCallback } from 'react'
import classes from './styles.module.css'
import { TBoardsColumn } from 'Admin/types/boards'
import { Sort } from '../Sort'
import { ColumnHeader } from './ColumnHeader'

function TableHeader({ columns }: { columns: TBoardsColumn[] }) {
const title = useCallback((column: TBoardsColumn) => {
switch (column) {
case 'name':
return 'Navn på tavle'
case 'url':
return 'Lenke'
case 'actions':
return 'Handlinger'
case 'lastModified':
return 'Sist oppdatert'
default:
return 'Ukjent kolonne'
}
}, [])

return (
<>
{columns.map((column) => (
<div key={column} className={classes.header}>
<div className={classes.title}>{title(column)}</div>
<Sort column={column} />
</div>
{columns.map((column: TBoardsColumn) => (
<ColumnHeader key={column} column={column} />
))}
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@
align-items: center;
gap: 0.5em;
border-bottom: var(--colors-blues-blue20) solid;
padding-bottom: 0.5em;
margin-bottom: 1em;
height: 3em;
}

.title {
display: flex;
height: 3em;
align-items: center;
font-weight: 500;
color: var(--colors-brand-lavender);
color: var(--border-color);
padding: 0 0.25rem;
border-top-right-radius: 0.25em;
border-top-left-radius: 0.25em;
}

.title:hover {
cursor: grab;
background-color: var(--tertiary-background-color);
}

.title:active {
cursor: grabbing;
background-color: var(--tertiary-background-color);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { TBoardsColumn } from 'Admin/types/boards'
import { useBoardsSettings } from '../../utils/context'
import { useSortBoardFunction } from '../../hooks/useSortBoardFunction'
import { DEFAULT_BOARD_NAME } from 'Admin/utils/constants'
import { Column } from '../Column'
import { Fragment } from 'react'
import { TBoard } from 'types/settings'
import { TBoardsColumn } from 'Admin/types/boards'

function TableRows() {
const settings = useBoardsSettings()
const { boards, columns, search } = useBoardsSettings()
const sortFunction = useSortBoardFunction()

const filter = new RegExp(settings.search, 'i')
const filter = new RegExp(search, 'i')
return (
<>
{settings.boards
{boards
.filter((board: TBoard) =>
filter.test(board?.meta?.title ?? DEFAULT_BOARD_NAME),
)
.sort(sortFunction)
.map((board: TBoard) => (
<Fragment key={board.id}>
{settings.columns.map((column: TBoardsColumn) => (
{columns.map((column: TBoardsColumn) => (
<Column
key={column}
board={board}
Expand Down
fredrbus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IconButton, SecondarySquareButton } from '@entur/button'
import { AdjustmentsIcon, CloseIcon } from '@entur/icons'
import classes from './styles.module.css'
import {
Popover,
PopoverCloseButton,
PopoverContent,
PopoverTrigger,
} from '@entur/tooltip'
import { Heading4 } from '@entur/typography'
import {
useBoardsSettings,
useBoardsSettingsDispatch,
} from '../../utils/context'
import { Checkbox } from '@entur/form'
import { BoardsColumns, TBoardsColumn } from 'Admin/types/boards'

function ToggleBoardsColumns() {
const { columns } = useBoardsSettings()
const dispatch = useBoardsSettingsDispatch()

return (
<Popover>
<PopoverTrigger>
<SecondarySquareButton className="flexColumn">
<AdjustmentsIcon />
</SecondarySquareButton>
</PopoverTrigger>
<PopoverContent>
<div className="p-1">
<div className="flexRow">
<Heading4 as="h2" className="m-1">
Velg kolonner
</Heading4>
<PopoverCloseButton>
<IconButton aria-label="Lukk popover">
<CloseIcon aria-hidden="true" />
</IconButton>
</PopoverCloseButton>
</div>
<div className={classes.contentList}>
{Object.entries(BoardsColumns).map(([column]) => (
<Checkbox
key={column}
checked={columns.includes(
column as TBoardsColumn,
)}
onChange={() =>
dispatch({
type: 'toggleColumn',
column: column as TBoardsColumn,
})
}
>
{BoardsColumns[column as TBoardsColumn]}
</Checkbox>
))}
</div>
</div>
</PopoverContent>
</Popover>
)
}

export { ToggleBoardsColumns }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.boardListOptions {
margin-left: auto;
}

.popoverHeading {
display: flex;
flex-direction: row;
justify-content: space-between;
}

.contentList {
padding: 0.5rem;
display: flex;
flex-direction: column;
gap: 0.25rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { CSSProperties } from 'react'
import { useSortable } from '@dnd-kit/sortable'
import { CSS } from '@dnd-kit/utilities'

export function useSortableColumnAttributes(column: string) {
const { attributes, listeners, transform, transition, active, setNodeRef } =
useSortable({ id: column })

const otherColumnActive = active && active.id !== column
const thisColumnActive = active && active.id === column

const activeStyle =
thisColumnActive &&
({
backgroundColor: 'var(--main-background-color)',
} as CSSProperties)

const style = {
transform: CSS.Translate.toString(transform),
transition: transition,
zIndex: thisColumnActive ? 10 : 0,
opacity: otherColumnActive ? 0.5 : 1,
...activeStyle,
}

if (thisColumnActive) style.backgroundColor = 'var(--main-background-color)'

return {
style,
attributes,
listeners,
transform,
transition,
active,
setNodeRef,
}
}
Loading