Added own dropdown to Type
This commit is contained in:
parent
db9cc5e052
commit
7309a36aa8
3 changed files with 57 additions and 48 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { PopoverAnchor } from "@radix-ui/react-popover";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { DropDownComponentType } from "../../types/components";
|
import { DropDownComponentType } from "../../types/components";
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
|
|
@ -13,6 +14,7 @@ import {
|
||||||
} from "../ui/command";
|
} from "../ui/command";
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
PopoverContentWithoutPortal,
|
PopoverContentWithoutPortal,
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from "../ui/popover";
|
} from "../ui/popover";
|
||||||
|
|
@ -25,16 +27,22 @@ export default function Dropdown({
|
||||||
onSelect,
|
onSelect,
|
||||||
editNode = false,
|
editNode = false,
|
||||||
id = "",
|
id = "",
|
||||||
|
children,
|
||||||
}: DropDownComponentType): JSX.Element {
|
}: DropDownComponentType): JSX.Element {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(children ? true : false);
|
||||||
|
|
||||||
const refButton = useRef<HTMLButtonElement>(null);
|
const refButton = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
|
const PopoverContentDropdown = children ? PopoverContent : PopoverContentWithoutPortal;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{Object.keys(options)?.length > 0 ? (
|
{Object.keys(options)?.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<Popover open={open} onOpenChange={setOpen}>
|
<Popover open={open} onOpenChange={children ? () => {} : setOpen}>
|
||||||
|
{children ? (
|
||||||
|
<PopoverAnchor>{children}</PopoverAnchor>
|
||||||
|
) : (
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|
@ -66,9 +74,10 @@ export default function Dropdown({
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContentWithoutPortal
|
)}
|
||||||
className="nocopy nowheel nopan nodelete nodrag noundo w-full p-0"
|
<PopoverContentDropdown
|
||||||
style={{ minWidth: refButton?.current?.clientWidth ?? "200px" }}
|
className="nocopy nowheel nopan nodelete nodrag noundo p-0"
|
||||||
|
style={children ? {} : { minWidth: refButton?.current?.clientWidth ?? "200px" }}
|
||||||
>
|
>
|
||||||
<Command>
|
<Command>
|
||||||
<CommandInput placeholder="Search options..." className="h-9" />
|
<CommandInput placeholder="Search options..." className="h-9" />
|
||||||
|
|
@ -98,7 +107,7 @@ export default function Dropdown({
|
||||||
</CommandGroup>
|
</CommandGroup>
|
||||||
</CommandList>
|
</CommandList>
|
||||||
</Command>
|
</Command>
|
||||||
</PopoverContentWithoutPortal>
|
</PopoverContentDropdown>
|
||||||
</Popover>
|
</Popover>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { Button } from "../../../../components/ui/button";
|
||||||
import { ColDef, ColGroupDef, SelectionChangedEvent } from "ag-grid-community";
|
import { ColDef, ColGroupDef, SelectionChangedEvent } from "ag-grid-community";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import AddNewVariableButton from "../../../../components/addNewVariableButtonComponent/addNewVariableButton";
|
import AddNewVariableButton from "../../../../components/addNewVariableButtonComponent/addNewVariableButton";
|
||||||
|
import Dropdown from "../../../../components/dropdownComponent";
|
||||||
import ForwardedIconComponent from "../../../../components/genericIconComponent";
|
import ForwardedIconComponent from "../../../../components/genericIconComponent";
|
||||||
import TableComponent from "../../../../components/tableComponent";
|
import TableComponent from "../../../../components/tableComponent";
|
||||||
import { Badge } from "../../../../components/ui/badge";
|
import { Badge } from "../../../../components/ui/badge";
|
||||||
|
|
@ -19,6 +20,14 @@ export default function GlobalVariablesPage() {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DropdownEditor = ({ options, value, onValueChange }) => {
|
||||||
|
return (
|
||||||
|
<Dropdown options={options} value={value} onSelect={onValueChange}>
|
||||||
|
<div className="-mt-1.5 w-full"></div>
|
||||||
|
</Dropdown>
|
||||||
|
);
|
||||||
|
};
|
||||||
// Column Definitions: Defines the columns to be displayed.
|
// Column Definitions: Defines the columns to be displayed.
|
||||||
const [colDefs, setColDefs] = useState<(ColDef<any> | ColGroupDef<any>)[]>([
|
const [colDefs, setColDefs] = useState<(ColDef<any> | ColGroupDef<any>)[]>([
|
||||||
{
|
{
|
||||||
|
|
@ -32,10 +41,9 @@ export default function GlobalVariablesPage() {
|
||||||
{
|
{
|
||||||
field: "type",
|
field: "type",
|
||||||
cellRenderer: BadgeRenderer,
|
cellRenderer: BadgeRenderer,
|
||||||
cellEditor: "agSelectCellEditor",
|
cellEditor: DropdownEditor,
|
||||||
cellEditorParams: {
|
cellEditorParams: {
|
||||||
values: ["Prompt", "Credential"],
|
options: ["Prompt", "Credential"],
|
||||||
valueListGap: 10,
|
|
||||||
},
|
},
|
||||||
flex: 1,
|
flex: 1,
|
||||||
editable: true,
|
editable: true,
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ export type DropDownComponentType = {
|
||||||
onSelect: (value: string) => void;
|
onSelect: (value: string) => void;
|
||||||
editNode?: boolean;
|
editNode?: boolean;
|
||||||
id?: string;
|
id?: string;
|
||||||
|
children?: ReactNode;
|
||||||
};
|
};
|
||||||
export type ParameterComponentType = {
|
export type ParameterComponentType = {
|
||||||
data: NodeDataType;
|
data: NodeDataType;
|
||||||
|
|
@ -80,15 +81,6 @@ export type InputGlobalComponentType = {
|
||||||
editNode?: boolean;
|
editNode?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type InputGlobalComponentType = {
|
|
||||||
disabled: boolean;
|
|
||||||
onChange: (value: string) => void;
|
|
||||||
setDb: (value: boolean) => void;
|
|
||||||
name: string;
|
|
||||||
data: NodeDataType;
|
|
||||||
editNode?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type KeyPairListComponentType = {
|
export type KeyPairListComponentType = {
|
||||||
value: any;
|
value: any;
|
||||||
onChange: (value: Object[]) => void;
|
onChange: (value: Object[]) => void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue