-
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
Conversation
Jeg opprettet en ny bruker og gikk inn på tavlesiden. Der får jeg opp mange tavler, selv om jeg ikke har laget noen enda. Mistenker det er tavler til de andre brukerne i db 🤔 Skjer det bare hos meg? |
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.
Jeg tror det er et problem i tavlesiden hvor man kan få inn tavlene til andre brukere. Jeg opprettet en ny bruker og hadde mange tavler på min tavleside da jeg sjekket det ut lokalt 🤔 💭
next-tavla/app/(admin)/boards/components/Column/Organization.tsx
Outdated
Show resolved
Hide resolved
Her har det gått fort i svingene 😅 Har fikset det nå! |
49a4b94
to
73c86a3
Compare
next-tavla/app/(admin)/boards/components/Column/Organization.tsx
Outdated
Show resolved
Hide resolved
@@ -75,7 +75,7 @@ export async function getBoardsForOrganization(oid: TOrganizationID) { | |||
.flat() | |||
} | |||
|
|||
export async function getBoardsForUser() { | |||
export async function getPrivateBoardsForUser() { |
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
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 | ||
} |
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.
Denne funksjonen trenger vi ikke hvis vi skriver om getAllBoardsForUser til å inkludere org direkte. Nå kjører vi getOrganizationsForUser
to ganger nesten rett etter hverandre (første i getAllBoardsForUser
på linje 26 og deretter i denne funksjonen)
<Table {...getSortableTableProps}> | ||
<TableHeader getSortableHeaderProps={getSortableHeaderProps} /> | ||
<TableRows boardsWithOrgs={sortedData} /> | ||
</Table> |
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.
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
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.
Denne filen sin path burde endres, vi trenger ikke lenger organization id som param
next-tavla/app/(admin)/actions.ts
Outdated
export async function getAllBoardsForUser() { | ||
const user = await getUser() | ||
if (!user) | ||
throw new TavlaError({ | ||
code: 'NOT_FOUND', | ||
message: `Found no user`, | ||
}) | ||
|
||
const privateBoardIDs = concat(user.owner ?? [], user.editor ?? []) | ||
|
||
const organizations = await getOrganizationsForUser() | ||
const organizationBoardIDs = organizations.map((o) => o.boards) | ||
|
||
const boardIDs = concat(privateBoardIDs, organizationBoardIDs.flat()) | ||
|
||
const batchedBoardIDs = chunk(boardIDs, 20) | ||
|
||
const boardQueries = batchedBoardIDs.map((batch) => | ||
firestore() | ||
.collection('boards') | ||
.where(firestore.FieldPath.documentId(), 'in', batch) | ||
.get(), | ||
) | ||
|
||
const boardRefs = await Promise.all(boardQueries) | ||
|
||
return boardRefs | ||
.map((ref) => | ||
ref.docs.map((doc) => ({ id: doc.id, ...doc.data() } as TBoard)), | ||
) | ||
.flat() | ||
} |
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.
Foreslår å hente ut all informasjonen vi trenger direkte her.
En mulig måte å gjøre dette på:
export async function getBoards(ids?: TBoardID[]) {
if (!ids) return []
const batches = chunk(ids, 20)
const queries = batches.map((batch) =>
firestore()
.collection('boards')
.where(firestore.FieldPath.documentId(), 'in', batch)
.get(),
)
const refs = await Promise.all(queries)
return refs
.map((ref) =>
ref.docs.map((doc) => ({ id: doc.id, ...doc.data() } as TBoard)),
)
.flat()
}
export async function getAllBoardsForUser(): Promise<
{ board: TBoard; organization?: TOrganization }[]
> {
const user = await getUser()
if (!user) return redirect('/')
const privateBoardIDs = concat(user.owner ?? [], user.editor ?? [])
const privateBoards = (await getBoards(privateBoardIDs)).map((board) => ({
board,
}))
const organizations = await getOrganizationsForUser()
const organizationsBoards = flattenDeep(
await Promise.all(
organizations.map(async (organization) =>
(
await getBoards(organization.boards)
).map((board) => ({
board,
organization,
})),
),
),
)
return [...organizationsBoards, ...privateBoards]
}
board
-object og etorganization
-objekt. Det er dette objektet som blir brukt til å sorteres på.