MCPcopy Create free account
hub / github.com/SplootCode/splootcode / ConfigPanel

Function ConfigPanel

packages/editor/src/components/config_panel.tsx:241–306  ·  view source on GitHub ↗
(props: ConfigPanelProps)

Source from the content-addressed store, hash-verified

239}
240
241export function ConfigPanel(props: ConfigPanelProps) {
242 const { project, startDrag } = props
243
244 const [envVars, setEnvVars] = React.useState(Object.fromEntries(project.environmentVars))
245 const varOrder = Object.keys(envVars)
246 varOrder.sort()
247
248 const updateEnvironmentVars = useCallback(() => {
249 setEnvVars(Object.fromEntries(project.environmentVars))
250 }, [project])
251
252 useEffect(() => {}, [updateEnvironmentVars])
253
254 const deleteVar = (name: string) => {
255 project.deleteEnvironmentVar(name)
256 setEnvVars(Object.fromEntries(project.environmentVars))
257 }
258
259 const updateVar = (prevName: string, newName: string, value: string, secret: boolean) => {
260 if (prevName !== newName) {
261 project.deleteEnvironmentVar(prevName)
262 }
263 project.setEnvironmentVar(newName, value, secret)
264 setEnvVars(Object.fromEntries(project.environmentVars))
265 }
266
267 const newVar = () => {
268 const newEnvVars = { '': ['', false] as [string, boolean], ...envVars }
269 setEnvVars(newEnvVars)
270 }
271
272 const numberOfValidVars = varOrder.filter((name) => name !== '').length
273
274 return (
275 <div className="config-panel">
276 <Box py={1} px={3}>
277 <HStack justifyContent={'space-between'}>
278 <Text as="h3" fontSize="md" py={2}>
279 Environment Variables
280 </Text>
281 <ButtonGroup>
282 <IconButton size="sm" aria-label="New variable" icon={<AddIcon />} onClick={() => newVar()}></IconButton>
283 </ButtonGroup>
284 </HStack>
285 {varOrder.length === 0 ? (
286 <Text fontStyle={'italic'} color="gray.400" py={3}>
287 No environment variables set.
288 </Text>
289 ) : null}
290 {varOrder.map((name) => {
291 return (
292 <EnvironmentVar
293 key={name}
294 name={name}
295 value={envVars[name][0]}
296 secret={envVars[name][1]}
297 deleteVar={deleteVar}
298 updateVar={updateVar}

Callers

nothing calls this directly

Calls 1

newVarFunction · 0.85

Tested by

no test coverage detected