Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Sep 5, 2024
1 parent fc32876 commit 6277798
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ docker/pgdata/

# Next.js
next-env.d.ts

apps/web/public/uploads
8 changes: 4 additions & 4 deletions apps/web/src/actions/datasets/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createDataset } from '@latitude-data/core/services/datasets/create'
import disk from '$/lib/disk'
import { z } from 'zod'

import { withProject } from '../procedures'
import { authProcedure } from '../procedures'

const ACCEPTED_FILE_TYPES = [
'text/csv',
Expand All @@ -15,12 +15,12 @@ const ACCEPTED_FILE_TYPES = [
const MAX_SIZE = 3
const MAX_UPLOAD_SIZE_IN_MB = 3 * 1024 * 1024

export const createDatasetAction = withProject
export const createDatasetAction = authProcedure
.createServerAction()
.input(
z.object({
name: z.string().min(1, { message: 'Name is required' }),
file: z
dataset_file: z
.instanceof(File)
.refine((file) => {
return !file || file.size <= MAX_UPLOAD_SIZE_IN_MB
Expand All @@ -38,7 +38,7 @@ export const createDatasetAction = withProject
disk: disk,
data: {
name: input.name,
file: input.file,
file: input.dataset_file,
},
})

Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/app/(private)/datasets/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import useLatitudeAction from '$/hooks/useLatitudeAction'
import { useNavigate } from '$/hooks/useNavigate'
import { ROUTES } from '$/services/routes'

// import useProjects from '$/stores/projects'

export default function NewDataset() {
const data = { name: '' }
const navigate = useNavigate()
const { executeFormAction } = useLatitudeAction(createDatasetAction)
const { error, executeFormAction } = useLatitudeAction(createDatasetAction)
const errors = error?.fieldErrors
return (
<Modal
open
Expand All @@ -42,16 +41,17 @@ export default function NewDataset() {
>
<FormWrapper>
<Input
required
type='text'
label='Name'
name='name'
errors={errors?.name}
defaultValue={data?.name}
placeholder='Amazing dataset'
/>
<DropzoneInput
label='Upload dataset'
name='dataset_file'
errors={errors?.dataset_file}
placeholder='Upload csv'
multiple={false}
accept='.csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/hooks/useLatitudeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export default function useLatitudeAction<
const errorCb = useCallback(
onError ||
((error: inferServerActionError<TServerAction>) => {
console.error(error)

if (error?.err?.code === 'INPUT_PARSE_ERROR') return

toast({
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/disk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const DIRNAME_PATH = path.dirname(fileURLToPath(import.meta.url))
export default new DiskWrapper({
local: {
publicPath: PUBLIC_PATH,
location: path.join(DIRNAME_PATH, `../../apps/web/public/${PUBLIC_PATH}`),
location: path.join(DIRNAME_PATH, `../../public/${PUBLIC_PATH}`),
},
})
5 changes: 2 additions & 3 deletions packages/core/src/lib/disk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { FSDriver } from 'flydrive/drivers/fs'
import { S3Driver } from 'flydrive/drivers/s3'
import { WriteOptions } from 'flydrive/types'

const generateUrl = (publicPath: string) => async (key: string) => {
;`/${publicPath}/${key}`
}
const generateUrl = (publicPath: string) => async (key: string) =>
`/${publicPath}/${key}`

function getAwsCredentials() {
const accessKeyId = env.AWS_ACCESS_KEY
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/datasets/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const createDataset = async (

const name = slugify(data.name)
const extension = path.extname(data.file.name)
const fileName = `workspaces/${workspace.id}/datasets/${name}.${extension}`
const fileName = `workspaces/${workspace.id}/datasets/${name}${extension}`

const diskResult = await disk.putFile(fileName, data.file)

Expand Down
6 changes: 2 additions & 4 deletions packages/env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if (environment !== 'production') {
dotenv.config({ path: pathToEnv })
}

export const DriveDiskSchema = z.union([z.literal('local'), z.literal('s3')])
export const env = createEnv({
skipValidation:
process.env.BUILDING_CONTAINER == 'true' || process.env.NODE_ENV === 'test',
Expand All @@ -45,13 +44,12 @@ export const env = createEnv({
REDIS_PASSWORD: z.string().optional(),
LATITUDE_URL: z.string().url(),
MAILER_API_KEY: z.string().optional(),
FROM_MAILER_EMAIL: z.string(),
LATITUDE_DOMAIN: z.string(),
FROM_MAILER_EMAIL: z.string(), LATITUDE_DOMAIN: z.string(),
AWS_REGION: z.string().optional(),
S3_BUCKET: z.string().optional(),
AWS_ACCESS_KEY: z.string().optional(),
AWS_ACCESS_SECRET: z.string().optional(),
DRIVE_DISK: DriveDiskSchema,
DRIVE_DISK: z.union([z.literal('local'), z.literal('s3')])
},
runtimeEnv: process.env,
})
1 change: 0 additions & 1 deletion packages/web-ui/src/ds/atoms/DropzoneInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function DropzoneInput({
const ref = useRef<HTMLInputElement>(null)
const onClickZone = useCallback(() => {
if (!ref.current) return
console.log('File input ref', ref.current)

ref.current.click()
}, [ref])
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/ds/atoms/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
{...props}
/>
)

if (props.hidden) return inputComp

return (
Expand Down

0 comments on commit 6277798

Please sign in to comment.