Skip to content

Commit 9530496

Browse files
committed
chore: move profile form into separate component
1 parent bf31648 commit 9530496

File tree

3 files changed

+103
-69
lines changed

3 files changed

+103
-69
lines changed
Lines changed: 10 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,21 @@
1-
import React, { FunctionComponent, useMemo } from 'react'
2-
import {
3-
BUILD_INFRA_BREADCRUMB,
4-
BuildInfraDescriptor,
5-
BuildInfraFooter,
6-
useBreadcrumb,
7-
BuildInfraConfigForm,
8-
useBuildInfraForm,
9-
DEFAULT_PROFILE_NAME,
10-
APIResponseHandler,
11-
ErrorScreenNotAuthorized,
12-
} from '@devtron-labs/devtron-fe-common-lib'
1+
import React, { FunctionComponent } from 'react'
2+
import { ErrorScreenNotAuthorized } from '@devtron-labs/devtron-fe-common-lib'
3+
import { importComponentFromFELibrary } from '../../../components/common'
134
import { BuildInfraProps } from './types'
14-
import './styles.scss'
5+
import ProfileForm from './ProfileForm'
156

16-
const BuildInfra: FunctionComponent<BuildInfraProps> = ({ isSuperAdmin }) => {
17-
const { breadcrumbs } = useBreadcrumb(BUILD_INFRA_BREADCRUMB)
18-
// Sending isSuperAdmin since don't even want to send API Request for that case
19-
const {
20-
isLoading,
21-
profileResponse,
22-
responseError,
23-
reloadRequest,
24-
profileInput,
25-
profileInputErrors,
26-
handleProfileInputChange,
27-
loadingActionRequest,
28-
handleSubmit,
29-
} = useBuildInfraForm({ name: DEFAULT_PROFILE_NAME, isSuperAdmin, editProfile: true })
30-
// Would use this to disable the save button, if all keys in profileInputErrors are null, then there are no errors
31-
// Might enhance this check later for other operations
32-
const formErrorCount = useMemo(
33-
() => Object.keys(profileInputErrors).filter((item) => profileInputErrors[item]).length,
34-
[profileInputErrors],
35-
)
36-
const showActionItems = isSuperAdmin && !isLoading && !responseError && profileInput?.configurations
7+
const BuildInfraRouter = importComponentFromFELibrary('BuildInfraRouter')
378

9+
export const BuildInfra: FunctionComponent<BuildInfraProps> = ({ isSuperAdmin }) => {
3810
if (!isSuperAdmin) {
3911
return <ErrorScreenNotAuthorized />
4012
}
4113

42-
return (
43-
<form className="h-100 flexbox-col build-infra pl pr pt pb dc__content-space bcn-0" onSubmit={handleSubmit}>
44-
<div className="flexbox-col dc__gap-24 pt pr pb pl h-100 dc__overflow-scroll">
45-
<BuildInfraDescriptor breadCrumbs={breadcrumbs} />
46-
47-
<APIResponseHandler
48-
isLoading={isLoading}
49-
progressingProps={{
50-
pageLoader: true,
51-
}}
52-
error={responseError}
53-
notAuthorized={!isSuperAdmin}
54-
reloadProps={{
55-
reload: reloadRequest,
56-
}}
57-
>
58-
<BuildInfraConfigForm
59-
profileInput={profileInput}
60-
profileInputErrors={profileInputErrors}
61-
handleProfileInputChange={handleProfileInputChange}
62-
isDefaultProfile
63-
unitsMap={profileResponse?.configurationUnits}
64-
/>
65-
</APIResponseHandler>
66-
</div>
14+
if (BuildInfraRouter) {
15+
return <BuildInfraRouter />
16+
}
6717

68-
{showActionItems && (
69-
<BuildInfraFooter
70-
disabled={formErrorCount !== 0}
71-
hideCancelButton
72-
editProfile
73-
loading={loadingActionRequest}
74-
/>
75-
)}
76-
</form>
77-
)
18+
return <ProfileForm />
7819
}
7920

8021
export default BuildInfra
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React, { FunctionComponent, useMemo } from 'react'
2+
import {
3+
BUILD_INFRA_BREADCRUMB,
4+
BuildInfraDescriptor,
5+
BuildInfraFooter,
6+
useBreadcrumb,
7+
BuildInfraConfigForm,
8+
useBuildInfraForm,
9+
DEFAULT_PROFILE_NAME,
10+
APIResponseHandler,
11+
BUILD_INFRA_TEXT,
12+
} from '@devtron-labs/devtron-fe-common-lib'
13+
import './styles.scss'
14+
15+
const ProfileForm: FunctionComponent = () => {
16+
const { breadcrumbs } = useBreadcrumb(BUILD_INFRA_BREADCRUMB)
17+
// Sending isSuperAdmin since don't even want to send API Request for that case
18+
const {
19+
isLoading,
20+
profileResponse,
21+
responseError,
22+
reloadRequest,
23+
profileInput,
24+
profileInputErrors,
25+
handleProfileInputChange,
26+
loadingActionRequest,
27+
handleSubmit,
28+
} = useBuildInfraForm({ name: DEFAULT_PROFILE_NAME, editProfile: true })
29+
// Would use this to disable the save button, if all keys in profileInputErrors are null, then there are no errors
30+
// Might enhance this check later for other operations
31+
const formErrorCount = useMemo(
32+
() =>
33+
Object.keys(profileInputErrors).filter(
34+
(item) => profileInputErrors[item] !== null && profileInputErrors[item] !== undefined,
35+
).length,
36+
[profileInputErrors],
37+
)
38+
39+
const showActionItems = !isLoading && !responseError && profileInput?.configurations
40+
41+
return (
42+
<form className="h-100 flexbox-col build-infra pl pr pt pb dc__content-space bcn-0" onSubmit={handleSubmit}>
43+
<div className="flexbox-col dc__gap-24 pt pr pb pl h-100 dc__overflow-scroll">
44+
<BuildInfraDescriptor breadCrumbs={breadcrumbs} />
45+
46+
<APIResponseHandler
47+
isLoading={isLoading}
48+
progressingProps={{
49+
pageLoader: true,
50+
}}
51+
error={responseError}
52+
reloadProps={{
53+
reload: reloadRequest,
54+
}}
55+
notFoundText={{
56+
title: BUILD_INFRA_TEXT.PROFILE_NOT_FOUND.title,
57+
subTitle: BUILD_INFRA_TEXT.PROFILE_NOT_FOUND.subTitle,
58+
}}
59+
>
60+
<BuildInfraConfigForm
61+
profileInput={profileInput}
62+
profileInputErrors={profileInputErrors}
63+
handleProfileInputChange={handleProfileInputChange}
64+
isDefaultProfile
65+
unitsMap={profileResponse?.configurationUnits}
66+
/>
67+
</APIResponseHandler>
68+
</div>
69+
70+
{showActionItems && (
71+
<BuildInfraFooter
72+
disabled={formErrorCount !== 0}
73+
hideCancelButton
74+
editProfile
75+
loading={loadingActionRequest}
76+
/>
77+
)}
78+
</form>
79+
)
80+
}
81+
82+
export default ProfileForm

src/css/base.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4130,3 +4130,14 @@ textarea::placeholder {
41304130
box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.35);
41314131
backdrop-filter: blur(5px);
41324132
}
4133+
4134+
4135+
// Tab behaviors
4136+
.dc__tab-focus {
4137+
outline: none;
4138+
}
4139+
4140+
.dc__tab-focus:focus-visible {
4141+
outline: 5px auto -webkit-focus-ring-color;
4142+
outline-offset: -2px;
4143+
}

0 commit comments

Comments
 (0)