-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor Code and Implement details and list page for httpproxy #2
base: main
Are you sure you want to change the base?
Conversation
@meysam-jeffrey Jan, if you possible, attach a demo for changes. |
@meysam-jeffrey Jan, I think it's better to use yarn and remove of the package-lock.json, what do you think? |
Using sub-components in large React components is a best practice that leads to:
|
src/components/chart/chart.tsx
Outdated
<ChartLine | ||
key={series.name} | ||
data={series.data} | ||
style={{ | ||
data: { | ||
stroke: series.color, | ||
}, | ||
}} | ||
/> |
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.
@meysam-jeffrey Jan, my suggestion is to extract this implementation to another sub-component like this:
interface ChartSeriesProps {
series: {
name: string;
data: { x: number; y: number }[];
color: string;
};
}
const ChartSeries: React.FC<ChartSeriesProps> = ({ series }) => {
const lineStyle = {
data: {
stroke: series.color,
},
};
return <ChartLine key={series.name} data={series.data} style={lineStyle} />;
};
and finally the usage of this component like this:
<ChartGroup>
{chartData.map((series: any, index) => (
<ChartSeries key={series.name} series={series} />
))}
</ChartGroup>
src/components/chart/chart.type.tsx
Outdated
export interface ChartMetricProps { | ||
title: string; | ||
name: string; | ||
chartData: []; | ||
width?: number; | ||
height?: number; | ||
legendPosition?: ChartProps['legendPosition']; | ||
yAxisTickValues?: number[]; | ||
xAxisTickValues?: (string | number)[]; | ||
themeColor?; | ||
showGrid?: boolean; | ||
padding?: { | ||
top?: number; | ||
bottom?: number; | ||
left?: number; | ||
right?: number; | ||
}; | ||
} |
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.
@meysam-jeffrey Jan, there is no any dependency between props?
src/components/form/ContourForm.tsx
Outdated
useEffect(() => { | ||
onChange(formData); | ||
}, [formData]); |
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.
You can remove this useEffect based on this description:
https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
src/components/form/ContourForm.tsx
Outdated
updateFormData((prev) => ({ | ||
...prev, | ||
routes: [...prev.routes, { ...DEFAULT_ROUTE }], | ||
})); |
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.
My suggestion is to use Immerjs for better readability and writability.
https://immerjs.github.io/immer/
src/components/form/RouteForm.tsx
Outdated
<div className="pf-u-pt-md"> | ||
<Flex justifyContent={{ default: 'justifyContentSpaceBetween' }}> | ||
<FlexItem> | ||
{onDelete && ( |
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.
It's better using ternary operator instead of and-sign.
src/components/form/RouteForm.tsx
Outdated
<div key={index} className="pf-u-mb-md"> | ||
<div> | ||
{route.services.length > 1 && ( | ||
<Button | ||
className="delete-button" | ||
variant="link" | ||
onClick={() => removeService(index)} | ||
> | ||
<span className="fa fa-minus-circle pf-u-mr-xs"></span> | ||
{t('remove_service')} | ||
</Button> | ||
)} | ||
<ServiceForm | ||
service={service} | ||
onChange={(updatedService) => | ||
updateService(index, updatedService) | ||
} | ||
availableServices={availableServices} | ||
availablePorts={availablePorts} | ||
availableSecrets={availableSecrets} | ||
/> | ||
</div> | ||
</div> |
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 it's better to extract in a sub-component for better readability.
src/components/form/ServiceForm.tsx
Outdated
<Flex> | ||
<FlexItem> | ||
<FormGroup fieldId="idle" label="Idle Connection Timeout (seconds)"> | ||
<TextInput | ||
type="number" | ||
value={service.idleConnection} | ||
onChange={(value) => | ||
onChange({ ...service, idleConnection: value }) | ||
} | ||
/> | ||
</FormGroup> | ||
</FlexItem> | ||
<FlexItem> | ||
<FormGroup fieldId="response" label="Response Timeout (minutes)"> | ||
<TextInput | ||
type="number" | ||
value={service.responseTimeout} | ||
onChange={(value) => | ||
onChange({ ...service, responseTimeout: value }) | ||
} | ||
/> | ||
</FormGroup> | ||
</FlexItem> | ||
</Flex> |
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 it's better to move it to a sub-component for better readability.
src/components/modal/index.tsx
Outdated
@@ -0,0 +1,41 @@ | |||
import * as React from 'react'; |
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.
@meysam-jeffrey Jan, if you possible add rule in webpack config that we don't need import react each file.
add plugins in webpack
import { ProvidePlugin } from 'webpack';
...
plugins: [
new ProvidePlugin({
React: 'react',
}),
...
add these two lines in tsconfig:
"jsx": "react-jsx",
"jsxImportSource": "react"
and finally add this section to the eslint.yml:
plugins:
- prettier
- react
- '@typescript-eslint'
rules:
prettier/prettier:
- error
react/jsx-uses-react: 'off'
react/jsx-uses-vars: 'warn'
react/prop-types: 'off'
settings:
react:
version: detect
src/pages/details.tsx
Outdated
<Grid hasGutter={true}> | ||
<GridItem span={6}> | ||
<Text className="pf-u-mt-xl"> | ||
<strong>{t('details_name')}</strong> | ||
</Text> | ||
<Text>{router?.metadata?.name}</Text> | ||
<Text className="pf-u-mt-xl"> | ||
<strong>{t('details_namespace')}</strong> | ||
</Text> | ||
<Text> | ||
<Badge className="pf-u-mr-xs">{t('ns')}</Badge> | ||
{router?.metadata?.namespace} | ||
</Text> | ||
<Text className="pf-u-mt-xl"> | ||
<strong>{t('details_created')}</strong> | ||
</Text> | ||
<Text>{router?.metadata?.creationTimestamp}</Text> | ||
</GridItem> | ||
<GridItem span={6}> | ||
<Text className="pf-u-mt-xl"> | ||
<strong>{t('location')}</strong> | ||
</Text> | ||
<Text> | ||
<a target="_blank" href={location}> | ||
{location} | ||
</a> | ||
</Text> | ||
<Text className="pf-u-mt-xl"> | ||
<strong>{t('details_status')}</strong> | ||
</Text> | ||
<Badge className="pf-u-mr-xs">{t('accepted')}</Badge> | ||
<Text className="pf-u-mt-xl"> | ||
<strong>{t('details_fqdn')}</strong> | ||
</Text> | ||
<Text>{router?.spec?.virtualhost?.fqdn}</Text> | ||
<Text className="pf-u-mt-xl"> | ||
<strong>{t('router_canonical')}</strong> | ||
</Text> | ||
<Text> | ||
{router?.status?.loadBalancer?.ingress?.[0]?.ip || | ||
'-'} | ||
</Text> | ||
</GridItem> | ||
</Grid> |
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 it to a sub-component?
Objective