Skip to content

Commit

Permalink
Exclude and Archive
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 16, 2024
1 parent 3b0e301 commit 8bb6f50
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 11 deletions.
14 changes: 12 additions & 2 deletions apps/dashboard/src/actions/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ export const updateTransactionSchema = z.object({
assigned_id: z.string().uuid().optional(),
recurring: z.boolean().optional().nullable(),
frequency: z.enum(["weekly", "monthly", "annually"]).optional().nullable(),
status: z.enum(["deleted", "excluded", "posted", "completed"]).optional(),
status: z
.enum(["deleted", "excluded", "posted", "completed", "archived"])
.optional(),
internal: z.boolean().optional().nullable(),
});

Expand All @@ -222,7 +224,15 @@ export const deleteCategoriesSchema = z.object({
});

export const bulkUpdateTransactionsSchema = z.object({
type: z.enum(["category", "note", "assigned", "status", "recurring", "tags"]),
type: z.enum([
"category",
"note",
"assigned",
"status",
"recurring",
"tags",
"archive",
]),
data: z.array(updateTransactionSchema),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ export const searchParamsCache = createSearchParamsCache({
recurring: parseAsArrayOf(
parseAsStringLiteral(["all", "weekly", "monthly", "annually"] as const),
),
statuses: parseAsStringLiteral(["completed", "uncompleted"] as const),
statuses: parseAsStringLiteral([
"completed",
"uncompleted",
"archived",
"excluded",
] as const),
});
47 changes: 43 additions & 4 deletions apps/dashboard/src/components/bulk-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,23 @@ export function BulkActions({ ids, tags }: Props) {
<DropdownMenuSub>
<DropdownMenuSubTrigger>
<Icons.Visibility className="mr-2 h-4 w-4" />
<span>Visibility</span>
<span>Exclude</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent sideOffset={14}>
<DropdownMenuCheckboxItem
onCheckedChange={() => {
bulkUpdateTransactions.execute({
type: "status",
data: ids.map((transaction) => ({
id: transaction,
internal: true,
})),
});
}}
>
Yes
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
onCheckedChange={() => {
bulkUpdateTransactions.execute({
Expand All @@ -147,20 +160,46 @@ export function BulkActions({ ids, tags }: Props) {
});
}}
>
Include
No
</DropdownMenuCheckboxItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
</DropdownMenuGroup>

<DropdownMenuGroup>
<DropdownMenuSub>
<DropdownMenuSubTrigger>
<Icons.Files className="mr-2 h-4 w-4" />
<span>Archive</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent sideOffset={14}>
<DropdownMenuCheckboxItem
onCheckedChange={() => {
bulkUpdateTransactions.execute({
type: "status",
data: ids.map((transaction) => ({
id: transaction,
status: "archived",
})),
});
}}
>
Yes
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
onCheckedChange={() => {
bulkUpdateTransactions.execute({
type: "status",
data: ids.map((transaction) => ({
id: transaction,
internal: true,
status: "posted",
})),
});
}}
>
Exclude
No
</DropdownMenuCheckboxItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
Expand Down
9 changes: 8 additions & 1 deletion apps/dashboard/src/components/transactions-search-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const defaultSearch = {
const statusFilters = [
{ id: "completed", name: "Completed" },
{ id: "uncompleted", name: "Uncompleted" },
{ id: "archived", name: "Archived" },
{ id: "excluded", name: "Excluded" },
];

const attachmentsFilters = [
Expand Down Expand Up @@ -121,7 +123,12 @@ export function TransactionsSearchFilter({
parseAsStringLiteral(["all", "weekly", "monthly", "annually"] as const),
),
statuses: parseAsArrayOf(
parseAsStringLiteral(["completed", "uncompleted"] as const),
parseAsStringLiteral([
"completed",
"uncompleted",
"archived",
"excluded",
] as const),
),
},
{
Expand Down
6 changes: 4 additions & 2 deletions packages/supabase/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,12 @@ export async function getTransactionsQuery(
query.eq("is_fulfilled", false);
} else if (statuses?.includes("completed") || attachments === "include") {
query.eq("is_fulfilled", true);
} else if (statuses?.includes("excluded")) {
query.eq("internal", true);
}

if (statuses?.includes("excluded")) {
query.eq("status", "excluded");
if (statuses?.includes("archived")) {
query.eq("status", "archived");
} else {
query.or("status.eq.pending,status.eq.posted,status.eq.completed");
}
Expand Down
7 changes: 6 additions & 1 deletion packages/supabase/src/types/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,12 @@ export type Database = {
| "deposit"
| "wire"
| "fee"
transactionStatus: "posted" | "pending" | "excluded" | "completed"
transactionStatus:
| "posted"
| "pending"
| "excluded"
| "completed"
| "archived"
}
CompositeTypes: {
metrics_record: {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
MdOutlineAccountBalance,
MdOutlineAccountCircle,
MdOutlineApps,
MdOutlineArchive,
MdOutlineArrowDownward,
MdOutlineArrowForward,
MdOutlineArrowOutward,
Expand Down

0 comments on commit 8bb6f50

Please sign in to comment.