generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new console pages for config, data, database, enum, secret, and typealias #2617
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been personally finding that it's easier to make "dumb" components and feed the data into them, vs. having to have
useSchema
type hooks in the smaller sub components. This also makes them much easier to writestorybook
stories for since they don't have any real dependencies. Whatcha think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally I follow that pattern too, but in this case,
DeclLink
is used byTypeEl
, which in turn is used by most of the decl-type panels. We'd end up having to thread it through all the way, which would make the props for all of those components more complicated just for onlyDeclLink
to actually use the contents. It gets worse from there, becauseDeclLink
is probably going to end up all over the console once we're through, at which point we're basically passingschema
down through nearly every single component in the tree. That would almost completely defeat the purpose of the hook pattern to begin with. :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Yeah, definitely seems easier to keep this here then. Thanks for the clarification!