import { useState, useEffect } from 'react' import { getProjectionDefs } from '../api' import { Spinner, EmptyState, HashBadge } from './Common' export default function ProjectionDefs() { const [data, setData] = useState([]) const [expanded, setExpanded] = useState>(new Set()) const [error, setError] = useState('') const [loading, setLoading] = useState(true) useEffect(() => { getProjectionDefs() .then((res) => setData(res.projection_defs)) .catch((e) => setError(e.message)) .finally(() => setLoading(false)) }, []) const toggleExpand = (hash: string) => { setExpanded((prev) => { const next = new Set(prev) if (next.has(hash)) { next.delete(hash) } else { next.add(hash) } return next }) } if (loading) return if (error) return
Error: {error}
return (

Projection Definitions

{data.length === 0 ? ( ) : (
{data.map((def, i) => (

{def.name}

{expanded.has(def.hash || i) && (
{def.sources && (
Sources:
{def.sources.map((s: any, i: number) => (
{s.event_def_hash}
bindings:{' '} {JSON.stringify(s.bindings)}
expression:{' '} {s.expression}
))}
)} {def.params && (
Params:
                        {JSON.stringify(def.params, null, 2)
                          .split('\n')
                          .map((line, i) => {
                            if (line.includes(':')) {
                              const [key, ...rest] = line.split(':')
                              return (
                                
{key}: {rest.join(':')}
) } return (
{line}
) })}
)} {def.value_schema && (
Value Schema:
                        {JSON.stringify(def.value_schema, null, 2)}
                      
)} {def.initial_value !== undefined && (
Initial Value:
                        {JSON.stringify(def.initial_value, null, 2)}
                      
)}
)}
))}
)}
) }