Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #407 allowed only numbers as configuration value #419

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@
align-items: center;
justify-content: center;
}
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;

}

Expand Down
2 changes: 0 additions & 2 deletions app/graph/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ export default function Toolbar({ disabled, chartRef, onDeleteElement, onAddEnti
<div className="flex items-center gap-6 p-1">
<div className="flex gap-4">
<Button
disabled
variant="Secondary"
label="Add Entity"
className="flex items-center gap-2"
onClick={onAddEntity}
icon={<PlusCircle />}
/>
<Button
disabled
variant="Secondary"
className="flex items-center gap-2"
label="Add Relation"
Expand Down
72 changes: 46 additions & 26 deletions app/settings/Configurations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React, { useEffect, useState, KeyboardEvent } from "react";
import { Toast, cn, prepareArg, securedFetch } from "@/lib/utils";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { CheckCircle2, XCircle } from "lucide-react";
import Input from "../components/ui/Input";
import Button from "../components/ui/Button";

Expand Down Expand Up @@ -146,16 +147,7 @@ export default function Configurations() {
run()
}, [])

const handelSetConfig = async (e: KeyboardEvent<HTMLInputElement>, name: string) => {

if (e.code === "Escape") {
setEditable("")
setConfigValue("")
return
}

if (e.code !== "Enter") return

const handelSetConfig = async (name: string) => {
const result = await securedFetch(`api/graph/?config=${prepareArg(name)}&value=${prepareArg(configValue)}`, {
method: 'POST',
})
Expand All @@ -177,6 +169,19 @@ export default function Configurations() {
setConfigValue("")
}

const onKeyDown = (e: KeyboardEvent<HTMLInputElement>, name: string) => {

if (e.code === "Escape") {
setEditable("")
setConfigValue("")
return
}

if (e.code !== "Enter") return

handelSetConfig(name)
}

return (
<div className="h-full w-full border border-[#57577B] rounded-lg overflow-auto">
<Table>
Expand All @@ -192,26 +197,41 @@ export default function Configurations() {
<TableBody>
{
configs.map(({ name, description, value }, index) => (
<TableRow key={name} className={cn("border-none", !(index % 2) && "bg-[#57577B] hover:bg-[#57577B]")}>
<TableCell className="w-[20%] py-8">{name}</TableCell>
<TableRow key={name} className={cn("border-none", !(index % 2) && "bg-[#57577B]")}>
<TableCell className="py-8">{name}</TableCell>
<TableCell className="w-[70%]">{description}</TableCell>
<TableCell>
<TableCell className="w-[15%]">
{
editable === name && !disableRunTimeConfigs.has(name) ?
<Input
ref={(ref) => {
ref?.focus()
}}
className="w-20"
variant="Small"
onChange={(e) => setConfigValue(e.target.value)}
onBlur={() => setEditable("")}
onKeyDown={(e) => handelSetConfig(e, name)}
value={configValue}
/>
<div className="flex gap-2">
<Input
ref={(ref) => {
ref?.focus()
}}
className="w-20"
type="number"
variant="Small"
onChange={(e) => setConfigValue(e.target.value)}
onKeyDown={(e) => onKeyDown(e, name)}
value={configValue}
style={{
WebkitAppearance: 'none',
margin: 0,
}}
/>
<Button
icon={<XCircle color={!(index % 2) ? "#272746" : "#57577B"} />}
onClick={() => setEditable("")}
onMouseDown={(e) => e.preventDefault()}
/>
<Button
icon={<CheckCircle2 color={!(index % 2) ? "#272746" : "#57577B"} />}
onClick={() => handelSetConfig(name)}
onMouseDown={(e) => e.preventDefault()}
/>
</div>
: <Button
className={cn(disableRunTimeConfigs.has(name) && "cursor-default")}
label={typeof value === "number" ? value.toString() : value}
label={typeof value === "number" ? value.toString() : value}
onClick={() => {
setEditable(name)
setConfigValue(value.toString())
Expand Down
Loading