Skip to content

Commit

Permalink
Vault
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 30, 2023
1 parent 5daad25 commit 8aaf6c3
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 40 deletions.
16 changes: 8 additions & 8 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@
"@midday/supabase": "workspace:*",
"@midday/ui": "workspace:*",
"@novu/headless": "^0.21.0",
"@trigger.dev/nextjs": "^2.2.7",
"@trigger.dev/nextjs": "^2.2.9",
"@vercel/edge-config": "^0.4.1",
"@vercel/toolbar": "^0.1.5",
"@zip.js/zip.js": "^2.7.31",
"change-case": "^5.2.0",
"framer-motion": "^10.16.5",
"next": "14.0.4-canary.18",
"framer-motion": "^10.16.8",
"next": "14.0.4-canary.28",
"next-international": "^1.1.4",
"next-safe-action": "^5.1.3",
"next-safe-action": "^5.2.0",
"next-themes": "^0.2.1",
"next-usequerystate": "^1.13.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.48.2",
"recharts": "^2.10.1",
"sharp": "^0.32.6",
"recharts": "^2.10.2",
"sharp": "^0.33.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@midday/tsconfig": "workspace:*",
"@t3-oss/env-nextjs": "^0.7.1",
"@types/node": "^20.10.0",
"@types/react": "^18.2.38",
"@types/node": "^20.10.1",
"@types/react": "^18.2.39",
"@types/react-dom": "^18.2.17",
"typescript": "^5.3.2"
}
Expand Down
2 changes: 0 additions & 2 deletions apps/dashboard/src/app/api/download/file/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export async function GET(req, res) {
const path = requestUrl.searchParams.get("path");
const filename = requestUrl.searchParams.get("filename");

console.log(`${user.data.team_id}/${path}/${filename}`);

const { data } = await download(supabase, {
bucket: "vault",
path: `${user.data.team_id}/${path}/${filename}`,
Expand Down
5 changes: 1 addition & 4 deletions apps/dashboard/src/components/attachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { createAttachmentsAction } from "@/actions/create-attachments-action";
import { deleteAttachmentAction } from "@/actions/delete-attachment-action";
import { invalidateCacheAction } from "@/actions/invalidate-cache-action";
import { useUpload } from "@/hooks/use-upload";
import { formatSize } from "@/utils/format";
import { createClient } from "@midday/supabase/client";
Expand All @@ -11,7 +10,6 @@ import { Button } from "@midday/ui/button";
import { cn } from "@midday/ui/utils";
import { AnimatePresence, motion } from "framer-motion";
import { File, X } from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { useDropzone } from "react-dropzone";

Expand Down Expand Up @@ -70,7 +68,6 @@ type Attachment = {

export function Attachments({ id, data }) {
const supabase = createClient();
const router = useRouter();
const [files, setFiles] = useState<Attachment[]>([]);
const { uploadFile } = useUpload();

Expand Down Expand Up @@ -143,7 +140,7 @@ export function Attachments({ id, data }) {
</div>
<AnimatePresence>
<ul className="mt-4 space-y-4">
{files.map((file, index) => (
{files.map((file) => (
<Item
key={file.name}
id={id}
Expand Down
24 changes: 17 additions & 7 deletions apps/dashboard/src/components/tables/vault/data-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,23 @@ export function DataTableRow({ data }) {
<ContextMenuItem>Rename</ContextMenuItem>
)}
<ContextMenuItem>
<a
href={`/api/download/file?path=${folderPath}&filename=${data.name}`}
download
className="truncate"
>
Download
</a>
{data.isFolder ? (
<a
href={`/api/download/zip?path=${folderPath}&filename=${data.name}`}
download
className="truncate"
>
Download
</a>
) : (
<a
href={`/api/download/file?path=${folderPath}&filename=${data.name}`}
download
className="truncate"
>
Download
</a>
)}
</ContextMenuItem>
{!disableActions && !isDefaultFolder && (
<AlertDialogTrigger asChild>
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/tables/vault/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { DataTableRow } from "./data-table-row";
export function DataTable({ data }) {
return (
<Table>
<TableHeader>
<TableHeader className="border-0">
<TableRow>
<TableHead className="w-[60%]">Name</TableHead>
<TableHead className="w-[15%]">Created at</TableHead>
<TableHead className="w-full">Last modified at</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableBody className="border-r-0 border-l-0">
{data?.map((row) => (
<DataTableRow key={row.name} data={row} />
))}
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/tables/vault/empty-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function EmptyTable({ type }: Props) {
switch (type) {
case "inbox":
return (
<div className="border border-t-0 p-4 h-[calc(100vh-240px)] flex justify-center items-center">
<div className="h-[calc(100%-80px)] p-4 flex justify-center items-center">
<div className="items-center flex flex-col text-center">
<h2 className="mb-2">This is your inbox</h2>
<p className="text-sm text-[#878787]">
Expand All @@ -19,7 +19,7 @@ export function EmptyTable({ type }: Props) {

default:
return (
<div className="border border-t-0 p-4 h-[calc(100vh-240px)] flex justify-center items-center">
<div className="h-[calc(100%-80px)] p-4 flex justify-center items-center">
<div className="items-center flex flex-col text-center">
<h2 className="mb-2">Drop your files here</h2>
<p className="text-sm text-[#878787]">
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/tables/vault/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function Table({ path }) {
const { data } = await getVault({ path });

return (
<div className="mt-6">
<div className="mt-6 h-[calc(100vh-240px)] border">
<DataTable data={data} />
{data.length === 0 && <EmptyTable type={path} />}
</div>
Expand Down
8 changes: 4 additions & 4 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"@midday/location": "workspace:*",
"@midday/ui": "workspace:*",
"@vercel/analytics": "^1.1.1",
"next": "14.0.4-canary.18",
"next": "14.0.4-canary.28",
"next-international": "^1.1.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"sharp": "^0.32.6"
"sharp": "^0.33.0"
},
"devDependencies": {
"@midday/tsconfig": "workspace:*",
"@types/node": "^20.10.0",
"@types/react": "^18.2.38",
"@types/node": "^20.10.1",
"@types/react": "^18.2.39",
"@types/react-dom": "^18.2.17"
}
}
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"check:types": "turbo typecheck"
},
"dependencies": {
"@biomejs/biome": "1.3.3",
"@manypkg/cli": "^0.21.0",
"@biomejs/biome": "1.4.0",
"@manypkg/cli": "^0.21.1",
"turbo": "^1.10.16",
"typescript": "^5.3.2"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/jobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"check:types": "tsc --noEmit"
},
"dependencies": {
"@trigger.dev/react": "^2.2.7",
"@trigger.dev/sdk": "^2.2.7",
"@trigger.dev/supabase": "^2.2.7"
"@trigger.dev/react": "^2.2.9",
"@trigger.dev/sdk": "^2.2.9",
"@trigger.dev/supabase": "^2.2.9"
}
}

4 changes: 2 additions & 2 deletions packages/supabase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"dependencies": {
"@supabase/ssr": "^0.0.10",
"@supabase/supabase-js": "^2.38.5",
"supabase": "^1.113.3"
"@supabase/supabase-js": "^2.39.0",
"supabase": "^1.115.4"
},
"devDependencies": {
"typescript": "^5.3.2"
Expand Down
1 change: 0 additions & 1 deletion packages/supabase/src/queries/cached-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ export const getVault = async (params) => {
["vault", teamId],
{
tags: [`vault_${teamId}`],
revalidate: 10,
}
)(params);
};
58 changes: 58 additions & 0 deletions packages/supabase/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,61 @@ export async function share(
) {
return client.storage.from(bucket).createSignedUrl(path, expireIn, options);
}

export async function getAllItemsAlongFolder(folder) {
const items = [];

let formattedPathToFolder = "";
const { name, columnIndex, prefix } = folder;

if (prefix === undefined) {
const pathToFolder = this.openedFolders
.slice(0, columnIndex)
.map((folder) => folder.name)
.join("/");
formattedPathToFolder =
pathToFolder.length > 0 ? `${pathToFolder}/${name}` : name;
} else {
formattedPathToFolder = `${prefix}/${name}`;
}

const options = {
limit: 10000,
offset: OFFSET,
sortBy: { column: this.sortBy, order: this.sortByOrder },
};
let folderContents = [];

for (;;) {
const res = await post(
`${this.endpoint}/buckets/${this.selectedBucket.name}/objects/list`,
{
path: formattedPathToFolder,
options,
}
);
folderContents = folderContents.concat(res);
options.offset += options.limit;
if ((res || []).length < options.limit) {
break;
}
}

const subfolders = folderContents?.filter((item) => item.id === null) ?? [];
const folderItems = folderContents?.filter((item) => item.id !== null) ?? [];

folderItems.forEach((item) =>
items.push({ ...item, prefix: formattedPathToFolder })
);

const subFolderContents = await Promise.all(
subfolders.map((folder) =>
this.getAllItemsAlongFolder({ ...folder, prefix: formattedPathToFolder })
)
);
subFolderContents.map((subfolderContent) => {
subfolderContent.map((item) => items.push(item));
});

return items;
}
4 changes: 2 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"./utils": "./src/utils"
},
"dependencies": {
"@mui/icons-material": "^5.14.18",
"@mui/icons-material": "^5.14.19",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
Expand All @@ -80,7 +80,7 @@
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"date-fns": "^2.30.0",
"lucide-react": "^0.293.0",
"lucide-react": "^0.294.0",
"react-day-picker": "^8.9.1",
"react-icons": "^4.12.0",
"tailwind-merge": "^2.0.0",
Expand Down

0 comments on commit 8aaf6c3

Please sign in to comment.