Skip to content

Commit

Permalink
Merge pull request #81 from sinamics/rework_fetching
Browse files Browse the repository at this point in the history
Reduce reliance on the database
  • Loading branch information
sinamics committed Aug 9, 2023
2 parents 0600f8c + 51d06fb commit 615643b
Show file tree
Hide file tree
Showing 41 changed files with 542 additions and 442 deletions.
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"@tanstack/react-query": "^4.20.2",
"@tanstack/react-query-devtools": "^4.28.0",
"@tanstack/react-table": "^8.9.3",
"@trpc/client": "^10.33.1",
"@trpc/next": "^10.33.1",
"@trpc/react-query": "^10.33.1",
"@trpc/server": "^10.33.1",
"@trpc/client": "^10.37.1",
"@trpc/next": "^10.37.1",
"@trpc/react-query": "^10.37.1",
"@trpc/server": "^10.37.1",
"@uiw/codemirror-extensions-classname": "^4.21.7",
"@uiw/codemirror-theme-okaidia": "^4.21.7",
"@uiw/react-codemirror": "^4.21.7",
Expand Down
36 changes: 36 additions & 0 deletions prisma/migrations/20230808053939_db_rework/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Warnings:
- You are about to drop the column `ipAssignments` on the `network` table. All the data in the column will be lost.
- You are about to drop the column `activeBridge` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `authorized` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `capabilities` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `conStatus` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `identity` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `ipAssignments` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `lastAuthorizedTime` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `lastDeauthorizedTime` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `noAutoAssignIps` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `objtype` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `revision` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `tags` on the `network_members` table. All the data in the column will be lost.
- You are about to drop the column `vRev` on the `network_members` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "network" DROP COLUMN "ipAssignments";

-- AlterTable
ALTER TABLE "network_members" DROP COLUMN "activeBridge",
DROP COLUMN "authorized",
DROP COLUMN "capabilities",
DROP COLUMN "conStatus",
DROP COLUMN "identity",
DROP COLUMN "ipAssignments",
DROP COLUMN "lastAuthorizedTime",
DROP COLUMN "lastDeauthorizedTime",
DROP COLUMN "noAutoAssignIps",
DROP COLUMN "objtype",
DROP COLUMN "revision",
DROP COLUMN "tags",
DROP COLUMN "vRev";
16 changes: 1 addition & 15 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,10 @@ model network_members {
nwid String
lastSeen DateTime?
online Boolean? @default(false)
conStatus Int? @default(0)
deleted Boolean? @default(false)
name String?
activeBridge Boolean @default(false)
address String? @default("")
authorized Boolean @default(false)
creationTime DateTime
identity String?
lastAuthorizedTime Int?
lastDeauthorizedTime Int?
objtype String?
revision Int?
tags Json?
capabilities Json?
vRev Int?
ipAssignments String[]
noAutoAssignIps Boolean? @default(false)
notations NetworkMemberNotation[]
@@unique([id, nwid])
Expand All @@ -87,8 +74,7 @@ model network {
creationTime DateTime?
lastModifiedTime DateTime?
flowRule String?
autoAssignIp Boolean? @default(true)
ipAssignments String
autoAssignIp Boolean? @default(true)
nw_userid User @relation(fields: [authorId], references: [id])
authorId Int
tagsByName Json?
Expand Down
8 changes: 7 additions & 1 deletion rome.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
},
"suspicious": {
"noCommentText": "warn",
"noExplicitAny": "off"
"noExplicitAny": "error"
},
"nursery": {
"noConsoleLog": "error"
},
"correctness": {
"noUnusedVariables": "error"
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/elements/tableFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { useMemo } from "react";
import { DebouncedInput } from "./debouncedInput";
import { type Column, type Table } from "@tanstack/react-table";
import { type MemberEntity } from "~/types/local/member";

export const TableFilter = ({
column,
table,
}: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
column: Column<any, unknown>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
table: Table<any>;
column: Column<MemberEntity, unknown>;
table: Table<MemberEntity>;
}) => {
const firstValue = table
.getPreFilteredRowModel()
Expand Down
4 changes: 2 additions & 2 deletions src/components/layouts/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const LayoutPublic = ({ children }: Props): JSX.Element => {

export const LayoutAuthenticated = ({ children }: Props): JSX.Element => {
return (
<div className="main-content">
<div className="outer-content">
<Header />
<div className="grid md:grid-cols-[255px,minmax(0,1fr)]">
<Sidebar />
<div className="custom-overflow custom-scrollbar overflow-auto">
<div className="custom-overflow custom-scrollbar">
{children}
<Footer />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/modules/anotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Anotation = ({ nwid, nodeid }: IProps) => {
const { refetch: refetchNetworkById } = api.network.getNetworkById.useQuery(
{
nwid,
central: false,
},
{ enabled: !!nwid, networkMode: "online" },
);
Expand Down
44 changes: 44 additions & 0 deletions src/components/modules/debugController.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useState } from "react";
import CodeMirror from "@uiw/react-codemirror";
import { okaidia } from "@uiw/codemirror-theme-okaidia";
import { python } from "@codemirror/lang-python";

interface Idata {
data: unknown;
title: string;
isOpen?: () => void;
}

const DebugMirror = ({ data, title }: Idata) => {
const [isOpen, setIsOpen] = useState(false);

if (!data) return null;

return (
<div
tabIndex={0}
onClick={() => setIsOpen(!isOpen)}
className="collapse-arrow collapse w-full border border-base-300 bg-base-200"
>
<input type="checkbox" />
<div className="collapse-title">{title}</div>
<div className="collapse-content" style={{ width: "100%" }}>
<CodeMirror
tabIndex={0}
value={JSON.stringify(data, null, 2)}
maxHeight="1500px"
width="100%"
theme={okaidia}
extensions={[python()]}
basicSetup={{
lineNumbers: true,
highlightActiveLineGutter: false,
highlightActiveLine: false,
}}
/>
</div>
</div>
);
};

export default DebugMirror;
7 changes: 4 additions & 3 deletions src/components/modules/deletedNetworkMembersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const DeletedNetworkMembersTable = ({ nwid }) => {
api.network.getNetworkById.useQuery(
{
nwid: nwid as string,
central: false,
},
{ enabled: !!query.id },
);
Expand All @@ -45,12 +46,12 @@ export const DeletedNetworkMembersTable = ({ nwid }) => {
});
const columnHelper = createColumnHelper<MemberEntity>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const columns = useMemo<ColumnDef<MemberEntity, unknown>[]>(
const columns = useMemo<ColumnDef<MemberEntity>[]>(
() => [
columnHelper.accessor("authorized", {
header: () => <span>Authorized</span>,
id: "authorized",
cell: (info) => info.getValue(),
cell: () => <span>No</span>,
}),
columnHelper.accessor("name", {
header: () => <span>Member name</span>,
Expand Down Expand Up @@ -170,7 +171,7 @@ export const DeletedNetworkMembersTable = ({ nwid }) => {
<tr key={headerGroup.id}>
{
// Loop over the headers in each row
headerGroup.headers.map((header, idx) => (
headerGroup.headers.map((header) => (
<th
key={header.id}
colSpan={header.colSpan}
Expand Down
1 change: 0 additions & 1 deletion src/components/modules/mailForgotPasswordTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ const ForgotPasswordMailTemplate = () => {
);
};

const mailTemplate = mailTemplates as InviteUserTemplate;
if (loadingTemplates) {
return (
<div className="flex flex-col items-center justify-center">
Expand Down
Loading

0 comments on commit 615643b

Please sign in to comment.