generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new console pages for config, data, database, enum, secret, and…
… typealias (#2617) Part 1 of #2616 Adds (or significantly adds to) pages for the following decl types: * config * data * database * enum * secret * typealias Not yet added: FSM, topic, subscription Adds components for: * `DeclLink`: takes a ref and links to the page for that decl * `TypeEl`: renders an appropriate string for a given Type, with links if appropriate * `PanelHeader` renders the standard decl panel page header (e.g. comments, export badge)
- Loading branch information
Showing
12 changed files
with
301 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
frontend/console/src/features/modules/decls/ConfigPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Config } from '../../../protos/xyz/block/ftl/v1/schema/schema_pb' | ||
import { PanelHeader } from './PanelHeader' | ||
import { TypeEl } from './TypeEl' | ||
|
||
export const ConfigPanel = ({ value, moduleName, declName }: { value: Config; moduleName: string; declName: string }) => { | ||
return ( | ||
<div className='py-2 px-4'> | ||
<PanelHeader exported={false} comments={value.comments}> | ||
Config: {moduleName}.{declName} | ||
</PanelHeader> | ||
<div className='text-sm my-4'> | ||
Type: <TypeEl t={value.type} /> | ||
</div> | ||
</div> | ||
) | ||
} |
25 changes: 11 additions & 14 deletions
25
frontend/console/src/features/modules/decls/DataPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
frontend/console/src/features/modules/decls/DatabasePanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Database } from '../../../protos/xyz/block/ftl/v1/schema/schema_pb' | ||
import { PanelHeader } from './PanelHeader' | ||
|
||
export const DatabasePanel = ({ value, moduleName, declName }: { value: Database; moduleName: string; declName: string }) => { | ||
return ( | ||
<div className='py-2 px-4'> | ||
<PanelHeader exported={false} comments={value.comments}> | ||
Database: {moduleName}.{declName} | ||
</PanelHeader> | ||
<div className='text-sm my-4'>Type: {value.type}</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useMemo } from 'react' | ||
import { Link } from 'react-router-dom' | ||
import { useSchema } from '../../../api/schema/use-schema' | ||
import type { PullSchemaResponse } from '../../../protos/xyz/block/ftl/v1/ftl_pb.ts' | ||
|
||
export const DeclLink = ({ moduleName, declName }: { moduleName?: string; declName: string }) => { | ||
const schema = useSchema() | ||
const decl = useMemo(() => { | ||
const modules = (schema?.data || []) as PullSchemaResponse[] | ||
const module = modules.find((m: PullSchemaResponse) => m.moduleName === moduleName) | ||
if (!module?.schema) { | ||
return | ||
} | ||
return module.schema.decls.find((d) => d.value.value?.name === declName) | ||
}, [moduleName, declName, schema?.data]) | ||
|
||
const str = moduleName ? `${moduleName}.${declName}` : declName | ||
|
||
if (!decl) { | ||
return str | ||
} | ||
|
||
return ( | ||
<Link | ||
className='rounded-md cursor-pointer text-indigo-600 dark:text-indigo-400 hover:bg-gray-100 hover:dark:bg-gray-700 p-1 -m-1' | ||
to={`/modules/${moduleName}/${decl.value.case}/${declName}`} | ||
> | ||
{str} | ||
</Link> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type { Enum, Type, Value } from '../../../protos/xyz/block/ftl/v1/schema/schema_pb' | ||
import { classNames } from '../../../utils' | ||
import { PanelHeader } from './PanelHeader' | ||
import { TypeEl } from './TypeEl' | ||
|
||
const VariantComments = ({ comments, fullRow }: { comments?: string[]; fullRow?: boolean }) => { | ||
if (!comments) { | ||
return | ||
} | ||
return comments.map((c, i) => ( | ||
<div key={i} className={classNames('text-gray-500 dark:text-gray-400 mb-0.5', fullRow ? 'col-start-1 col-end-3' : '')}> | ||
{c} | ||
</div> | ||
)) | ||
} | ||
|
||
const VariantValue = ({ name, value }: { name?: string; value?: Value }) => { | ||
const v = value?.value.value?.value | ||
if (v === undefined) { | ||
return | ||
} | ||
const valueText = value?.value.case === 'intValue' ? v.toString() : `"${v}"` | ||
return ( | ||
<div className='mb-3'> | ||
{name && `${name} = `} | ||
{valueText} | ||
</div> | ||
) | ||
} | ||
|
||
const VariantNameAndType = ({ name, t }: { name: string; t: Type }) => { | ||
return [ | ||
<span key='n' className='mb-3'> | ||
{name} | ||
</span>, | ||
<TypeEl key='t' t={t} />, | ||
] | ||
} | ||
|
||
const ValueEnumVariants = ({ value }: { value: Enum }) => { | ||
return value.variants.map((v) => [<VariantComments key='c' comments={v.comments} />, <VariantValue key='v' name={v.name} value={v.value} />]) | ||
} | ||
|
||
const TypeEnumVariants = ({ value }: { value: Enum }) => { | ||
return ( | ||
<div className='inline-grid grid-cols-2 gap-x-4' style={{ gridTemplateColumns: 'auto auto' }}> | ||
{value.variants.map((v) => [ | ||
<VariantComments key='c' fullRow comments={v.comments} />, | ||
<VariantNameAndType key='n' name={v.name} t={v.value?.value.value?.value as Type} />, | ||
])} | ||
</div> | ||
) | ||
} | ||
|
||
function enumType(value: Enum): string { | ||
if (!value.type) { | ||
return 'Type' | ||
} | ||
return value.type.value.case === 'string' ? 'String' : 'Int' | ||
} | ||
|
||
export const EnumPanel = ({ value, moduleName, declName }: { value: Enum; moduleName: string; declName: string }) => { | ||
const isValueEnum = value.type !== undefined | ||
return ( | ||
<div className='py-2 px-4'> | ||
<PanelHeader exported={value.export} comments={value.comments}> | ||
{enumType(value)} Enum: {moduleName}.{declName} | ||
</PanelHeader> | ||
<div className='mt-8'> | ||
<div className='mb-2'>Variants</div> | ||
<div className='text-xs font-mono'>{isValueEnum ? <ValueEnumVariants value={value} /> : <TypeEnumVariants value={value} />}</div> | ||
</div> | ||
</div> | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
frontend/console/src/features/modules/decls/PanelHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ReactNode } from 'react' | ||
import { Badge } from '../../../components/Badge' | ||
|
||
export const PanelHeader = ({ children, exported, comments }: { children?: ReactNode; exported: boolean; comments?: string[] }) => { | ||
return ( | ||
<div className='flex-1'> | ||
{exported && ( | ||
<div className='mb-2'> | ||
<Badge name='Exported' /> | ||
</div> | ||
)} | ||
{children} | ||
{comments && comments.length > 0 && <p className='text-xs my-1'>{comments}</p>} | ||
</div> | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
frontend/console/src/features/modules/decls/SecretPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Secret } from '../../../protos/xyz/block/ftl/v1/schema/schema_pb' | ||
import { PanelHeader } from './PanelHeader' | ||
import { TypeEl } from './TypeEl' | ||
|
||
export const SecretPanel = ({ value, moduleName, declName }: { value: Secret; moduleName: string; declName: string }) => { | ||
return ( | ||
<div className='py-2 px-4'> | ||
<PanelHeader exported={false} comments={value.comments}> | ||
Secret: {moduleName}.{declName} | ||
</PanelHeader> | ||
<div className='text-sm my-4'> | ||
Type: <TypeEl t={value.type} /> | ||
</div> | ||
</div> | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
frontend/console/src/features/modules/decls/TypeAliasPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { TypeAlias } from '../../../protos/xyz/block/ftl/v1/schema/schema_pb' | ||
import { PanelHeader } from './PanelHeader' | ||
import { TypeEl } from './TypeEl' | ||
|
||
export const TypeAliasPanel = ({ value, moduleName, declName }: { value: TypeAlias; moduleName: string; declName: string }) => { | ||
return ( | ||
<div className='py-2 px-4'> | ||
<PanelHeader exported={value.export} comments={value.comments}> | ||
Type Alias: {moduleName}.{declName} | ||
</PanelHeader> | ||
<div className='text-sm my-4'> | ||
Underlying type: <TypeEl t={value.type} /> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { Optional, Ref, Array as SchArray, Map as SchMap, Type } from '../../../protos/xyz/block/ftl/v1/schema/schema_pb' | ||
import { DeclLink } from './DeclLink' | ||
|
||
// TypeParams ironically is built to work with the `Type` message, not the | ||
// `TypeParameter` message, which just has a simple string param name without | ||
// any higher level type information. | ||
const TypeParams = ({ types }: { types?: (Type | undefined)[] }) => { | ||
const definedTypes = types?.filter((t) => t !== undefined) | ||
if (!definedTypes || definedTypes.length === 0) { | ||
return | ||
} | ||
return ( | ||
<span> | ||
<span>{'<'}</span> | ||
{definedTypes.map((t, i) => [<TypeEl key='t' t={t} />, i === definedTypes.length - 1 ? '' : ', '])} | ||
<span>{'>'}</span> | ||
</span> | ||
) | ||
} | ||
|
||
export const TypeEl = ({ t }: { t?: Type }) => { | ||
if (!t) { | ||
return '' | ||
} | ||
|
||
const v = t.value.value | ||
if (!v) { | ||
return t.value.case | ||
} | ||
|
||
switch (t.value.case) { | ||
case 'array': | ||
return ( | ||
<span> | ||
array | ||
<TypeParams types={[(v as SchArray).element]} /> | ||
</span> | ||
) | ||
case 'map': | ||
return ( | ||
<span> | ||
map | ||
<TypeParams types={[(v as SchMap).key, (v as SchMap).value]} /> | ||
</span> | ||
) | ||
case 'optional': | ||
return ( | ||
<span> | ||
optional | ||
<TypeParams types={[(v as Optional).type]} /> | ||
</span> | ||
) | ||
case 'ref': | ||
return ( | ||
<span> | ||
<DeclLink moduleName={(v as Ref).module} declName={(v as Ref).name} /> | ||
<TypeParams types={(v as Ref).typeParameters} /> | ||
</span> | ||
) | ||
default: | ||
return t.value.case || '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters