Skip to content

Commit

Permalink
Merge pull request #67 from sinamics/annotation
Browse files Browse the repository at this point in the history
[Feat] Member Anotation
  • Loading branch information
sinamics authored Jul 28, 2023
2 parents 3e59ea9 + 9a1a16e commit f2932a2
Show file tree
Hide file tree
Showing 21 changed files with 887 additions and 202 deletions.
24 changes: 11 additions & 13 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": "Next ZTNet dev",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": ["../docker-compose.yml", "docker-compose.yml"],

"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "next_ztnet",
Expand All @@ -19,7 +20,10 @@
"customizations": {
"vscode": {
"settings": {
"git.path": ["/usr/bin/git", "C:/Program Files/Git/bin/git.exe"]
"git.path": [
"/usr/bin/git",
"C:/Program Files/Git/bin/git.exe"
]
},
"extensions": [
"esbenp.prettier-vscode",
Expand All @@ -30,29 +34,23 @@
"bradlc.vscode-tailwindcss",
"austenc.tailwind-docs",
"bourhaouta.tailwindshades",
"Gruntfuggly.todo-tree"
"Gruntfuggly.todo-tree",
"yoavbls.pretty-ts-errors"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": []

// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],

// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "chmod +x .devcontainer/init-cmd.sh"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
}
40 changes: 40 additions & 0 deletions prisma/migrations/20230728082722_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- AlterTable
ALTER TABLE "GlobalOptions" ADD COLUMN "showNotationMarkerInTableRow" BOOLEAN DEFAULT false,
ADD COLUMN "useNotationColorAsBg" BOOLEAN DEFAULT false;

-- CreateTable
CREATE TABLE "Notation" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"color" TEXT,
"description" TEXT,
"creationTime" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedTime" TIMESTAMP(3) NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"nwid" TEXT NOT NULL,
"icon" TEXT,
"orderIndex" INTEGER,
"visibility" TEXT,

CONSTRAINT "Notation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "NetworkMemberNotation" (
"notationId" INTEGER NOT NULL,
"nodeid" INTEGER NOT NULL,

CONSTRAINT "NetworkMemberNotation_pkey" PRIMARY KEY ("notationId","nodeid")
);

-- CreateIndex
CREATE UNIQUE INDEX "Notation_name_nwid_key" ON "Notation"("name", "nwid");

-- AddForeignKey
ALTER TABLE "Notation" ADD CONSTRAINT "Notation_nwid_fkey" FOREIGN KEY ("nwid") REFERENCES "network"("nwid") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NetworkMemberNotation" ADD CONSTRAINT "NetworkMemberNotation_notationId_fkey" FOREIGN KEY ("notationId") REFERENCES "Notation"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NetworkMemberNotation" ADD CONSTRAINT "NetworkMemberNotation_nodeid_fkey" FOREIGN KEY ("nodeid") REFERENCES "network_members"("nodeid") ON DELETE RESTRICT ON UPDATE CASCADE;
71 changes: 44 additions & 27 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ model GlobalOptions {
// Notifications
userRegistrationNotification Boolean @default(false)
// networks
useNotationColorAsBg Boolean? @default(false)
showNotationMarkerInTableRow Boolean? @default(true)
}

enum Role {
Expand Down Expand Up @@ -69,23 +72,52 @@ model network_members {
vRev Int?
ipAssignments String[]
noAutoAssignIps Boolean? @default(false)
notations NetworkMemberNotation[]
@@unique([id, nwid])
}
model network {
nwid String @id
nwname String
description String?
creationTime DateTime?
lastModifiedTime DateTime?
flowRule String?
autoAssignIp Boolean? @default(true)
ipAssignments String
nw_userid User @relation(fields: [authorId], references: [id])
authorId Int
tagsByName Json?
capabilitiesByName Json?
nwid String @id
nwname String
description String?
creationTime DateTime?
lastModifiedTime DateTime?
flowRule String?
autoAssignIp Boolean? @default(true)
ipAssignments String
nw_userid User @relation(fields: [authorId], references: [id])
authorId Int
tagsByName Json?
capabilitiesByName Json?
network_members network_members[]
notations Notation[]
}

model Notation {
id Int @id @default(autoincrement())
name String
color String?
description String?
creationTime DateTime @default(now())
updatedTime DateTime @updatedAt
isActive Boolean @default(true)
nwid String
network network @relation(fields: [nwid], references: [nwid])
network_members NetworkMemberNotation[]
icon String?
orderIndex Int?
visibility String?
@@unique([name, nwid])
}

model NetworkMemberNotation {
notationId Int
nodeid Int
label Notation @relation(fields: [notationId], references: [id])
member network_members @relation(fields: [nodeid], references: [nodeid])
@@id([notationId, nodeid])
}

// Necessary for Next auth
Expand Down Expand Up @@ -160,18 +192,3 @@ model VerificationToken {
// generate local draft
// npx prisma migrate dev --create-only --preview-feature

// Update postgres from cmd line
// su auvnet
// UPDATE users SET role = 'ADMIN' WHERE email = 'bernt.christian.egeland@gmail.com';
// INSERT INTO settings VALUES(1, false);
// SELECT * FROM settings;

// ----------- Deploy proccess --------------
// git pull
// npm run prisma-gen
// npx prisma migrate deploy --preview-feature
// pm2 restart ztnet


// Seeding prisma
// npx prisma db seed --preview-feature --schema=./prisma/schema.prisma
110 changes: 63 additions & 47 deletions src/components/elements/input.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,77 @@
import { useEffect, useRef } from "react";
import { forwardRef, useEffect } from "react";

interface PasswordInputProps {
interface InputProps {
placeholder: string;
value?: string | number;
name: string;
type: string;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
onBlur?: (event: React.ChangeEvent<HTMLInputElement>) => void;
ref?: React.RefObject<HTMLInputElement>;
focus?: boolean;
className?: string;
defaultValue?: string | number;
list?: string;
}

const Input = ({
placeholder,
value,
name,
onChange,
type,
className = "",
defaultValue,
focus = false,
...rest
}: PasswordInputProps) => {
const inputRef = useRef<HTMLInputElement>(null);
const Input = forwardRef<HTMLInputElement, InputProps>(
(
{
value,
name,
onChange,
onBlur,
className = "",
defaultValue,
focus = false,
...rest
}: InputProps,
forwardedRef
) => {
const handleRef = (instance: HTMLInputElement | null) => {
if (typeof forwardedRef === "function") {
forwardedRef(instance);
} else if (forwardedRef) {
forwardedRef.current = instance;
}
};

useEffect(() => {
if (focus && inputRef.current) {
inputRef.current.focus();
}
}, [focus]);
useEffect(() => {
if (focus && forwardedRef && "current" in forwardedRef) {
forwardedRef.current?.focus();
}
}, [focus, forwardedRef]);

useEffect(() => {
if (defaultValue && inputRef.current && onChange) {
const event = {
target: {
name: inputRef.current.name,
value: defaultValue,
},
};
onChange(event as React.ChangeEvent<HTMLInputElement>);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<input
type={type}
name={name}
placeholder={placeholder}
defaultValue={defaultValue}
value={value}
onChange={onChange}
className={`input w-full max-w-xs ${className}`}
ref={inputRef}
{...rest}
/>
);
};
useEffect(() => {
if (
defaultValue &&
forwardedRef &&
"current" in forwardedRef &&
onChange
) {
const event = {
target: {
name: forwardedRef.current?.name || "",
value: defaultValue,
},
};
onChange(event as React.ChangeEvent<HTMLInputElement>);
}
}, [defaultValue, onChange, forwardedRef]);

return (
<input
name={name}
defaultValue={defaultValue}
value={value}
onChange={onChange}
onBlur={onBlur}
className={`input w-full max-w-xs ${className}`}
ref={handleRef}
{...rest}
/>
);
}
);
Input.displayName = "Input";
export default Input;
16 changes: 14 additions & 2 deletions src/components/modules/accountTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export const Accounts = () => {
desc: false,
},
]);
const { data: members, refetch: refetchUsers } =
api.admin.getUsers.useQuery();
const {
data: members,
refetch: refetchUsers,
isLoading: loadingUsers,
} = api.admin.getUsers.useQuery();
const columnHelper = createColumnHelper<MembersEntity>();
const columns = useMemo<ColumnDef<MembersEntity>[]>(
() => [
Expand Down Expand Up @@ -186,6 +189,15 @@ export const Accounts = () => {
},
});

if (loadingUsers) {
return (
<div className="flex flex-col items-center justify-center">
<h1 className="text-center text-2xl font-semibold">
<progress className="progress progress-primary w-56"></progress>
</h1>
</div>
);
}
return (
<div className="mx-auto flex w-full flex-col justify-center space-y-5 bg-base-100 p-3 sm:w-8/12">
<div className="overflow-x-auto">
Expand Down
Loading

0 comments on commit f2932a2

Please sign in to comment.