import { useState } from "react"; import { useSortable } from "@dnd-kit/sortable"; import ReactMarkdown from 'react-markdown'; import { CSS } from "@dnd-kit/utilities"; import { Card, CardContent, CardActions, CardHeader, Button, Dialog, DialogTitle, DialogContent, Box, IconButton, Checkbox, Select, MenuItem, FormControl, FormControlLabel, Textarea, FormHelperText, TextField, Stack, Typography, } from '@mui/material'; import Grid from '@mui/material/Grid2'; import DragIndicatorIcon from '@mui/icons-material/DragIndicator'; import { set } from "yaml/dist/schema/yaml-1.1/set"; Object.defineProperty(String.prototype, 'capitalize', { value: function() { return this.charAt(0).toUpperCase() + this.slice(1); }, enumerable: false }); const StepCard = ({ type, module, toggleModule, enabledModules, configValues }: { type: string, module: object, toggleModule: any, enabledModules: any, configValues: any }) => { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: module.name }); const style = { transform: CSS.Transform.toString(transform), transition, zIndex: isDragging ? "100" : "auto", opacity: isDragging ? 0.3 : 1 }; let name = module.name; const [helpOpen, setHelpOpen] = useState(false); const [configOpen, setConfigOpen] = useState(false); const enabled = enabledModules[type].find((m: any) => m[0] === name)[1]; return ( } label={module.display_name} /> } action ={ } /> {enabled && module.configs && name != 'cli_feeder' ? ( ) : null} setHelpOpen(false)} maxWidth="lg" > {module.display_name} {module.manifest.description.split("\n").map((line: string) => line.trim()).join("\n")} {module.configs && name != 'cli_feeder' && } ) } function ConfigPanel({ module, open, setOpen, configValues }: { module: any, open: boolean, setOpen: any, configValues: any }) { function setConfigValue(config: any, value: any) { configValues[module.name][config] = value; } return ( <> setOpen(false)} maxWidth="lg" > {module.display_name} {Object.keys(module.configs).map((config_value: any) => { const config_args = module.configs[config_value]; const config_name = config_value.replace(/_/g," "); const config_display_name = config_name.capitalize(); const value = configValues[module.name][config_value] || config_args.default; return ( {config_display_name} { config_args.type === 'bool' ? { setConfigValue(config_value, e.target.checked); }} />} label={config_args.help} /> : ( config_args.choices !== undefined ? : ( config_args.type === 'json_loader' ? { try { let val = JSON.parse(e.target.value); setConfigValue(config_value, val); } catch (e) { console.log(e); } } } /> : { setConfigValue(config_value, e.target.value); }} /> ) ) } {config_args.type !== 'bool' && ( {config_args.help} )} ); })} ); } export default StepCard;