-
Notifications
You must be signed in to change notification settings - Fork 97
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
UI for Create Postgres Peer #456
Conversation
label: 'Port', | ||
stateHandler: (value: string, setter: PeerSetter) => | ||
setter((curr) => ({ ...curr, port: parseInt(value, 10) })), | ||
type: 'number', // type for textfield |
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.
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.
We could prevent typing of non-numbers but right now I personally think it's fine. Happy to discuss though
return ( | ||
<> | ||
{props.settings.map((setting, id) => { | ||
return ( |
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 think making the form config-driven is a good idea. But we maybe need to revisit things like how default values can be set. For Example port default value is 5432 in config state variable, but we are not using it anywhere. perhaps a crude way to do it could be as shown below by adding a default value
export default function PgConfig(props: ConfigProps) {
return (
<>
{props.settings.map((setting, id) => {
let _defaultValue = setting.type === "number" && setting.label === "Port" ? "5432" : "";
return (
<RowWithTextField
key={id}
label={<Label as='label'>{setting.label}</Label>}
action={
<TextField
variant='simple'
type={setting.type}
defaultValue={_defaultValue}
onChange={(e) =>
setting.stateHandler(e.target.value, props.setter)
}
/>
}
/>
);
})}
</>
);
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.
The default values are not really meant to be used in UI, but rather because protobuf-grpc doesn't seem to allow undefined values so we need dummies.
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.
Also thanks for the catch: the config value for the state here should be made generic to peer. fixed.
ui/app/peers/create/page.tsx
Outdated
<Button as={Link} href='/peers'> | ||
Cancel | ||
</Button> | ||
<Button |
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.
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.
Yup. Singled out postgres (for now) as the only option in the data source selection step.
ui/app/peers/create/page.tsx
Outdated
target='_blank' | ||
> | ||
Learn about peers | ||
</Action> | ||
</Panel> | ||
<Panel> | ||
<Label colorName='lowContrast' variant='subheadline'> |
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.
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.
Yup. Changed. Thanks
}).then((res) => res.text()); | ||
|
||
if (statusMessage !== 'created') { | ||
setMessage({ ok: false, msg: statusMessage }); |
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.
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.
The same issue for validate button
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.
Hey Joban. Couldn't reproduce this. Maybe we could investigate separately if this persists
export const checkFormFields = (peerType: string, config: PeerConfig) => { | ||
switch (peerType) { | ||
case 'POSTGRES': | ||
return pgSchema.validate(config); |
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.
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 think this is fine as the quotes does make the error more clear in a way
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.
For the Name field double quotes were not there, which is why I pointed it out. Looks a bit inconsistent
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.
Hey Joban there are no quotes now. Thanks
ui/app/api/peers/validate/route.ts
Outdated
export async function POST(request: Request) { | ||
let body = await request.json(); | ||
let name = body.name; | ||
let type = body.type; |
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.
Can be refactored as
let { name, type, config } = body;
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.
Fixed
@iskakaushik Did we consider using material-ui even if we want to use storybook, material-ui can be integrated with storybook (https://storybook.js.org/recipes/@mui/material). The out-of-the-box components provided by the storybook lib look pretty primitive (in styling, shimmering/loading behavior, etc.) . I think we should consider libraries like material-ui/Chara-ui etc from the starting stage of the UI, Please let me know your thoughts on this |
8806a93
to
f61e422
Compare
ui/package.json
Outdated
@@ -31,6 +31,7 @@ | |||
"@types/react": "18.2.21", | |||
"@types/react-dom": "18.2.7", | |||
"classnames": "^2.3.2", | |||
"joi": "^17.10.2", |
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.
Let's use zod
instead, it feels like more idiomatic typescript.
ui/app/peers/create/page.tsx
Outdated
<Button | ||
disabled={!peerType} | ||
onClick={() => { | ||
router.push(`/peers/create/configuration?dbtype=${peerType}`); |
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.
should we use next/link
instead? https://nextjs.org/blog/next-13-2#statically-typed-links
ui/app/api/peers/create/route.ts
Outdated
CreatePeerStatus, | ||
} from '@/grpc_generated/route'; | ||
import { GetFlowServiceClient } from '@/rpc/rpc'; | ||
import { constructPeer } from '../util'; |
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.
lets move this method to this class, there isn't much happening in the utils still.
ui/app/api/peers/create/route.ts
Outdated
const body = await request.json(); | ||
const { name, type, config } = body; | ||
const flowServiceAddress = process.env.PEERDB_FLOW_SERVER_ADDRESS!; | ||
const flowServiceClient = GetFlowServiceClient(flowServiceAddress); |
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.
isn't there a helper for this already? Maybe we should have a method GetFlowServiceClientFromEnv
, and update usage elsewhere too?
ui/app/api/peers/create/route.ts
Outdated
import { GetFlowServiceClient } from '@/rpc/rpc'; | ||
import { constructPeer } from '../util'; | ||
|
||
export async function POST(request: Request) { |
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.
can we move this to peers/route.ts
and service both validate and create based on a param in the json or something else?
}; | ||
|
||
// API call to create peer | ||
export const handleCreate = async ( |
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.
lets discuss the need for this
e1153f0
to
d4aed5f
Compare
APIs for create peer and validate peer are present in
app/api/peers/validate
andapp/api/peers/create
respectively.Makes progress towards #431