Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions app/lib/csvToDoneEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class DoneEntryCsvRow extends S.Class<DoneEntryCsvRow>("DoneEntryCsvRow")({
date: S.String,
content: S.String,
likes: S.String,
timestamp: S.String,
}) {}

export const csvToDoneEntries = (csvData: string) =>
Expand All @@ -26,7 +25,7 @@ export const csvToDoneEntries = (csvData: string) =>
const contact = yield* contacts.findBy("userName", row.userName.toLowerCase())

// `likes` comes in as as serialized array of user names; need to convert that to contactIDs
const likesUserNames = JSON.parse(row.likes) as string[]
const likesUserNames = (row.likes ? JSON.parse(row.likes) : []) as string[]
const likes = [] as ContactId[]
for (const userName of likesUserNames) {
const contact = yield* contacts.findBy("userName", userName.toLowerCase())
Expand All @@ -39,7 +38,6 @@ export const csvToDoneEntries = (csvData: string) =>
date: row.date,
content: row.content,
likes,
timestamp: Number(row.timestamp),
})
}).pipe(E.mapError(cause => new DoneEntryCsvParseError({ input, index, cause })))
})
Expand Down
15 changes: 1 addition & 14 deletions app/lib/test/csvToDoneEntries.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { clients } from "data/clients"
import { contacts } from "data/contacts"
import { projects } from "data/projects"
import { $, E, pipe } from "lib/Effect"
import { type BaseTestCase } from "lib/runTestCases"
import { ClientCollection, ProvidedClients } from "schema/ClientCollection"
import { ContactCollection, ProvidedContacts } from "schema/ContactCollection"
import { ProjectCollection, ProvidedProjects } from "schema/ProjectCollection"
import { assert, expect, test } from "vitest"
import { csvToDoneEntries } from "../csvToDoneEntries"

Expand Down Expand Up @@ -62,19 +58,10 @@ const label = ({ label, input }: TestCase) =>

const errorPadding = Math.max(...testCases.filter(tc => tc.error).map(tc => label(tc).length))

const TestProjects = new ProjectCollection(projects)
const TestClients = new ClientCollection(clients)
const TestContacts = new ContactCollection(contacts)

const decode = (csv: string) =>
pipe(
csv,
csvToDoneEntries,
E.provideService(ProvidedContacts, TestContacts),
E.provideService(ProvidedProjects, TestProjects),
E.provideService(ProvidedClients, TestClients),
$,
)
pipe(csv, csvToDoneEntries, E.provideService(ProvidedContacts, TestContacts), $)

for (const testCase of testCases) {
const { input, only, skip } = testCase
Expand Down
12 changes: 7 additions & 5 deletions app/routes/_private+/devtools+/danger+/ui/DoneEntryImporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export const DoneEntryImporter = ({ add = NO_OP, destroyAll = NO_OP, contacts =
const [doneEntries, setDones] = useState<DoneEntry[]>([])
const [successMessage, setSuccessMessage] = useState<string | undefined>(undefined)

const decode = (csv: string) =>
pipe(
const decode = (csv: string) => {
return pipe(
csv,
csvToDoneEntries,
E.provideService(ProvidedContacts, new ContactCollection(contacts)),
$,
)
}

const onImportDataChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const csv = event.target.value
Expand Down Expand Up @@ -48,10 +49,11 @@ export const DoneEntryImporter = ({ add = NO_OP, destroyAll = NO_OP, contacts =
cols={200}
placeholder={[
"Enter comma-delimited entries, one per line in this format: ",
"contactId,date,content ",
"contactId,date,content,likes",
"",
"Example: ",
"brent,2023-01-27,Added feature X",
"Examples: ",
"brent,2023-01-27,Added feature X,[]",
'herb,2023-01-27,"Updated weekly meeting template to be a ""custom building block""","[""shane"",""ritika"",""aasit"",""reid"",""colleen""]"',
].join("\n")}
></textarea>
<div className="-mt-1 mb-2 rounded-md rounded-t-none border border-t-0 bg-neutral-50 p-2 pt-3">
Expand Down
Loading