-
Notifications
You must be signed in to change notification settings - Fork 50
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(boards): visual overhaul #1532
Changes from all commits
bf71595
88f0285
e8778c3
b97be14
d9d60c2
7f09851
8ff6061
f1aeb39
7636b5d
def541f
1946000
73c86a3
cbb0e19
11e31ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Denne filen sin path burde endres, vi trenger ikke lenger organization id som param |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,59 @@ | ||
import { permanentRedirect } from 'next/navigation' | ||
import { SelectOrganization } from '../components/SelectOrganization' | ||
import { Search } from '../components/Search' | ||
import { FilterButton } from '../components/FilterButton' | ||
import { ToggleBoardsColumns } from '../components/ToggleBoardsColumns' | ||
import { BoardTable } from '../components/BoardTable' | ||
import { Metadata } from 'next' | ||
import React from 'react' | ||
import { | ||
getBoardsForOrganization, | ||
getBoardsForUser, | ||
getOrganizationIfUserHasAccess, | ||
getAllBoardsForUser, | ||
getOrganizationsForUser, | ||
} from 'app/(admin)/actions' | ||
import { initializeAdminApp } from 'app/(admin)/utils/firebase' | ||
import { getUserFromSessionCookie } from 'app/(admin)/utils/server' | ||
import { Heading1 } from '@entur/typography' | ||
import { TBoard, TBoardWithOrganization } from 'types/settings' | ||
|
||
initializeAdminApp() | ||
|
||
type TProps = { | ||
params: { id: string[] } | ||
export const metadata: Metadata = { | ||
title: `Tavler | Entur Tavla`, | ||
} | ||
|
||
export async function generateMetadata({ params }: TProps): Promise<Metadata> { | ||
const { id } = params | ||
|
||
const organization = id | ||
? await getOrganizationIfUserHasAccess(id[0] ?? '') | ||
: { name: 'Mine' } | ||
|
||
return { | ||
title: `${organization?.name} tavler | Entur Tavla`, | ||
} | ||
} | ||
|
||
async function OrganizationsBoardsPage({ params }: TProps) { | ||
const { id } = params | ||
async function OrganizationsBoardsPage() { | ||
const user = await getUserFromSessionCookie() | ||
if (!user) permanentRedirect('/') | ||
const organizations = await getOrganizationsForUser() | ||
const activeOrganization = await getOrganizationIfUserHasAccess( | ||
(id ?? '')[0], | ||
) | ||
|
||
const hasAccess = | ||
activeOrganization && | ||
(activeOrganization.owners?.includes(user.uid) || | ||
activeOrganization.editors?.includes(user.uid)) | ||
|
||
if (id && !hasAccess) { | ||
return <div>Du har ikke tilgang til denne organisasjonen</div> | ||
} | ||
const boards = await getAllBoardsForUser() | ||
|
||
const boards = id | ||
? await getBoardsForOrganization(id[0] ?? '') | ||
: await getBoardsForUser() | ||
const boardsWithOrganization = await getBoardsWithOrganization(boards) | ||
|
||
return ( | ||
<div className="flex flex-col md:flex-row gap-3 justify-center"> | ||
<SelectOrganization | ||
organizations={organizations} | ||
active={activeOrganization} | ||
/> | ||
<div className="flex flex-col mt-4 md:mt-8 gap-3 grow"> | ||
<div className="flex flex-col sm:flex-row md:items-center gap-3"> | ||
<Search /> | ||
<div className="flex flex-col md:flex-row gap-3"> | ||
<FilterButton boards={boards} /> | ||
<ToggleBoardsColumns /> | ||
</div> | ||
</div> | ||
<div className="overflow-x-auto"> | ||
<BoardTable boards={boards} /> | ||
</div> | ||
<div className="flex flex-col gap-8"> | ||
<Heading1>Tavler</Heading1> | ||
<div className="flex flex-col sm:flex-row md:items-center gap-3"> | ||
<Search /> | ||
<FilterButton boards={boards} /> | ||
</div> | ||
<BoardTable boardsWithOrgs={boardsWithOrganization} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default OrganizationsBoardsPage | ||
|
||
async function getBoardsWithOrganization(boards: TBoard[]) { | ||
const organizations = await getOrganizationsForUser() | ||
|
||
const boardsWithOrganization = boards.map((board: TBoard) => { | ||
const org = organizations.find((org) => | ||
org.boards?.includes(board.id ?? ''), | ||
) | ||
|
||
return { | ||
board: { ...board }, | ||
organization: { ...org }, | ||
} as TBoardWithOrganization | ||
}) | ||
|
||
return boardsWithOrganization | ||
} | ||
Comment on lines
+44
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Denne funksjonen trenger vi ikke hvis vi skriver om getAllBoardsForUser til å inkludere org direkte. Nå kjører vi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
'use client' | ||
import { TableHeader } from 'app/(admin)/boards/components/TableHeader' | ||
import { TableRows } from 'app/(admin)/boards/components/TableRows' | ||
import { TBoard } from 'types/settings' | ||
import { TBoardWithOrganization } from 'types/settings' | ||
import { isEmpty } from 'lodash' | ||
import { useSearchParam } from '../../hooks/useSearchParam' | ||
import { IllustratedInfo } from 'app/(admin)/components/IllustratedInfo' | ||
import { DEFAULT_BOARD_COLUMNS, TBoardsColumn } from 'app/(admin)/utils/types' | ||
import { Table, useSortableData } from '@entur/table' | ||
import { TableHeader } from '../TableHeader' | ||
|
||
function BoardTable({ boards }: { boards: TBoard[] }) { | ||
const value = useSearchParam('columns') | ||
const columns = value?.split(',') ?? DEFAULT_BOARD_COLUMNS | ||
function BoardTable({ | ||
boardsWithOrgs, | ||
}: { | ||
boardsWithOrgs: TBoardWithOrganization[] | ||
}) { | ||
const { sortedData, getSortableHeaderProps, getSortableTableProps } = | ||
useSortableData(boardsWithOrgs) | ||
|
||
if (isEmpty(boards)) | ||
if (isEmpty(boardsWithOrgs)) | ||
return ( | ||
<IllustratedInfo | ||
title="Her var det tomt" | ||
|
@@ -20,15 +23,10 @@ function BoardTable({ boards }: { boards: TBoard[] }) { | |
) | ||
|
||
return ( | ||
<div | ||
className="grid items-center" | ||
style={{ | ||
gridTemplateColumns: `repeat(${columns.length},auto)`, | ||
}} | ||
> | ||
<TableHeader columns={columns as TBoardsColumn[]} /> | ||
<TableRows boards={boards} /> | ||
</div> | ||
<Table {...getSortableTableProps}> | ||
<TableHeader getSortableHeaderProps={getSortableHeaderProps} /> | ||
<TableRows boardsWithOrgs={sortedData} /> | ||
</Table> | ||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jeg får opp flere problemer i node, virker som det skjer noe greier i Table komponenten som krasjer serveren. Prøv å import den uten ssr (lazy) og se om det funker da |
||
) | ||
} | ||
export { BoardTable } |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import { DEFAULT_BOARD_NAME } from 'app/(admin)/utils/constants' | ||
import { Column } from './Column' | ||
import { TBoard } from 'types/settings' | ||
import Link from 'next/link' | ||
|
||
function Name({ name = DEFAULT_BOARD_NAME }: { name?: string }) { | ||
return <Column column="name">{name}</Column> | ||
function Name({ board }: { board: TBoard }) { | ||
return ( | ||
<Column column="name"> | ||
<Link href={`/edit/${board.id}`} className="hover:underline"> | ||
{board.meta?.title ?? DEFAULT_BOARD_NAME} | ||
</Link> | ||
</Column> | ||
) | ||
} | ||
|
||
export { Name } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Link from 'next/link' | ||
import { Column } from './Column' | ||
import { TOrganization } from 'types/settings' | ||
|
||
function Organization({ organization }: { organization: TOrganization }) { | ||
const orgName = organization.name ?? 'Privat' | ||
|
||
return ( | ||
<Column column="organization"> | ||
{organization.id ? ( | ||
<Link | ||
href={`/organizations/${organization.id}`} | ||
className="hover:underline" | ||
> | ||
{orgName} | ||
</Link> | ||
) : ( | ||
<p>{orgName}</p> | ||
)} | ||
</Column> | ||
) | ||
} | ||
|
||
export { Organization } |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brukes denne funksjonen til noe nå eller kan den fjernes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nei, men jeg lurer på om det er greit at den bare ligger hvis vi skal vise alle private tavler til en person en gang? Det har vært litt snakk om å kanskje filterer på organisasjoner uansett på tavler-siden, og da skal vi også kunne filtrere på private tavler