Skip to content

Commit 8825bf2

Browse files
committed
fix: address PR review comments - type safety and code organization
1 parent 3eec61d commit 8825bf2

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

frontend/common/types/requests.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
Segment,
1111
Tag,
1212
ProjectFlag,
13-
Project,
1413
Environment,
1514
UserGroup,
1615
AttributeName,
@@ -29,18 +28,14 @@ import { UtmsType } from './utms'
2928

3029
export type UpdateProjectBody = {
3130
name: string
32-
} & Partial<
33-
Pick<
34-
Project,
35-
| 'hide_disabled_flags'
36-
| 'prevent_flag_defaults'
37-
| 'enable_realtime_updates'
38-
| 'minimum_change_request_approvals'
39-
| 'stale_flags_limit_days'
40-
| 'only_allow_lower_case_feature_names'
41-
| 'feature_name_regex'
42-
>
43-
>
31+
hide_disabled_flags?: boolean
32+
prevent_flag_defaults?: boolean
33+
enable_realtime_updates?: boolean
34+
minimum_change_request_approvals?: number | null
35+
stale_flags_limit_days?: number | null
36+
only_allow_lower_case_feature_names?: boolean
37+
feature_name_regex?: string | null
38+
}
4439

4540
export type PagedRequest<T> = T & {
4641
page?: number

frontend/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ declare global {
6565
const Select: typeof _Select
6666
const Column: typeof Component
6767
const Loader: typeof Component
68+
const Input: typeof Component
69+
const Button: typeof Component
6870
const E2E: boolean
6971
const closeModal: () => void
7072
const closeModal2: () => void

frontend/web/components/pages/project-settings/ProjectSettingsPage.tsx

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react'
1+
import React, { ReactNode, useEffect } from 'react'
22
import PageTitle from 'components/PageTitle'
33
import Tabs from 'components/navigation/TabMenu/Tabs'
44
import TabItem from 'components/navigation/TabMenu/TabItem'
@@ -16,10 +16,19 @@ import { PermissionsTab } from './tabs/PermissionsTab'
1616
import { CustomFieldsTab } from './tabs/CustomFieldsTab'
1717
import { ImportTab } from './tabs/ImportTab'
1818

19+
type ProjectSettingsTab = {
20+
component: ReactNode
21+
isVisible: boolean
22+
key: string
23+
label: ReactNode
24+
labelString?: string
25+
}
26+
1927
const ProjectSettingsPage = () => {
2028
const { environmentId, projectId } = useRouteContext()
2129
const {
2230
data: project,
31+
error,
2332
isLoading,
2433
isUninitialized,
2534
} = useGetProjectQuery({ id: String(projectId) }, { skip: !projectId })
@@ -28,7 +37,6 @@ const ProjectSettingsPage = () => {
2837
API.trackPage(Constants.pages.PROJECT_SETTINGS)
2938
}, [])
3039

31-
// Show loader only on initial load (not during refetches from mutations)
3240
const isInitialLoading = isUninitialized || (isLoading && !project)
3341

3442
if (isInitialLoading) {
@@ -42,24 +50,23 @@ const ProjectSettingsPage = () => {
4250
)
4351
}
4452

45-
const hasEnvironments = !!project?.environments?.length
46-
const hasFeatureHealth = Utils.getFlagsmithHasFeature('feature_health')
47-
48-
// Derive organisationId from project data (not available in route params)
49-
const organisationId = project?.organisation
50-
51-
if (!project || !projectId || !organisationId) {
53+
if (error || !project || !projectId || !project?.organisation) {
5254
return (
5355
<div className='app-container container'>
5456
<PageTitle title='Project Settings' />
55-
<div className='text-center'>
56-
<Loader />
57+
<div className='alert alert-danger mt-4 text-center'>
58+
Failed to load project settings. Please try again.
5759
</div>
5860
</div>
5961
)
6062
}
6163

62-
const tabs = [
64+
// Derive data from project after all early returns
65+
const hasEnvironments = !!project.environments?.length
66+
const hasFeatureHealth = Utils.getFlagsmithHasFeature('feature_health')
67+
const organisationId = project.organisation
68+
69+
const tabs: ProjectSettingsTab[] = [
6370
{
6471
component: <GeneralTab project={project} environmentId={environmentId} />,
6572
isVisible: true,
@@ -122,25 +129,22 @@ const ProjectSettingsPage = () => {
122129
key: 'export',
123130
label: 'Export',
124131
},
125-
]
132+
].filter(({ isVisible }) => isVisible)
126133

127134
return (
128135
<div className='app-container container'>
129136
<PageTitle title='Project Settings' />
130137
<Tabs urlParam='tab' className='mt-0' uncontrolled>
131-
{tabs.map(
132-
({ component, isVisible, key, label, labelString }) =>
133-
isVisible && (
134-
<TabItem
135-
key={key}
136-
tabLabel={label}
137-
data-test={key}
138-
tabLabelString={labelString}
139-
>
140-
{component}
141-
</TabItem>
142-
),
143-
)}
138+
{tabs.map(({ component, key, label, labelString }) => (
139+
<TabItem
140+
key={key}
141+
tabLabel={label}
142+
data-test={key}
143+
tabLabelString={labelString}
144+
>
145+
{component}
146+
</TabItem>
147+
))}
144148
</Tabs>
145149
</div>
146150
)

frontend/web/components/pages/project-settings/tabs/general-tab/sections/ProjectInformation.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export const ProjectInformation = ({ project }: ProjectInformationProps) => {
5353
}
5454
isValid={!!name && name.length > 0}
5555
type='text'
56-
title={<label>Project Name</label>}
5756
placeholder='My Project Name'
5857
/>
5958
</Flex>

0 commit comments

Comments
 (0)