-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from sinamics/annotation
[Feat] Member Anotation
- Loading branch information
Showing
21 changed files
with
887 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.