-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ADded export to csv for my work tables * Initial export space proposals database * Fixed username issue * Fixed proposals export * Fixed broken type issues * refactor to export proposals * Renamed work to my-work * Fixed broken type issues * Refactored export my proposals * Fixed issue with view block not created * Added url column for my proposals * Move export proposals button to sidebar
- Loading branch information
Showing
14 changed files
with
359 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { prisma } from '@charmverse/core/prisma-client'; | ||
import { baseUrl } from '@root/config/constants'; | ||
|
||
import { getUserProposals } from './getUserProposals'; | ||
|
||
export async function exportMyProposals({ spaceId, userId }: { spaceId: string; userId: string }) { | ||
const space = await prisma.space.findUniqueOrThrow({ | ||
where: { | ||
id: spaceId | ||
}, | ||
select: { | ||
domain: true | ||
} | ||
}); | ||
const userProposals = await getUserProposals({ spaceId, userId }); | ||
|
||
let csvContent = ''; | ||
const rows: string[][] = [ | ||
[ | ||
'Title', | ||
'Status', | ||
'Current step', | ||
'Your review', | ||
'Approved', | ||
'Declined', | ||
'URL', | ||
...(userProposals.customColumns?.map((column) => column.title) ?? []) | ||
] | ||
]; | ||
|
||
const allProposals = [...userProposals.actionable, ...userProposals.authored, ...userProposals.review_completed]; | ||
|
||
allProposals.forEach((proposal) => { | ||
const row = [ | ||
proposal.title || 'Untitled', | ||
proposal.currentEvaluation?.result | ||
? proposal.currentEvaluation.result === 'pass' | ||
? 'Passed' | ||
: 'Declined' | ||
: 'In progress', | ||
proposal.status === 'draft' ? 'Draft' : proposal.currentEvaluation?.title || 'Evaluation', | ||
proposal.userReviewResult || '-', | ||
proposal.totalPassedReviewResults?.toString() || '-', | ||
proposal.totalFailedReviewResults?.toString() || '-', | ||
`${baseUrl}/${space.domain}/${proposal.path}`, | ||
...(userProposals.customColumns?.map((column) => { | ||
const customValue = proposal.customColumns?.find((c) => c.formFieldId === column.formFieldId)?.value; | ||
if (column.type === 'select' || column.type === 'multiselect') { | ||
return column.options.find((opt) => opt.id === customValue)?.name || '-'; | ||
} | ||
return (customValue as string) || '-'; | ||
}) ?? []) | ||
]; | ||
rows.push(row); | ||
}); | ||
|
||
rows.forEach((row) => { | ||
const encodedRow = row.join('\t'); | ||
csvContent += `${encodedRow}\r\n`; | ||
}); | ||
|
||
return csvContent; | ||
} |
Oops, something went wrong.