Skip to content

Commit 94ef999

Browse files
committed
Revert "feat: [APL-898] - Network Policies Page (#609)"
This reverts commit 159e317.
1 parent 3e27463 commit 94ef999

19 files changed

Lines changed: 133 additions & 1284 deletions

public/i18n/en/common.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
"SealedSecret_plural": "Sealed Secrets",
4646
"Netpol": "Network Policy",
4747
"Netpol_plural": "Network Policies",
48-
"Inbound Rule_plural": "Inbound Rules",
49-
"Outbound Rule_plural": "Outbound Rules",
5048
"Secrets": "Secrets",
5149
"Service": "Service",
5250
"Service_plural": "Services",
@@ -106,7 +104,5 @@
106104
"Code-repository": "Code Repository",
107105
"Code-repository_plural": "Code Repositories",
108106
"TITLE_CODE_REPOSITORY": "Code repository details",
109-
"TITLE_CODE_REPOSITORIES": "Code repositories - {{scope}}",
110-
"TITLE_NETWORK_POLICY": "Network policy details",
111-
"TITLE_NETWORK_POLICIES": "Network policies - {{scope}}"
107+
"TITLE_CODE_REPOSITORIES": "Code repositories - {{scope}}"
112108
}

src/App.tsx

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CacheProvider } from '@emotion/react'
55
import { CssBaseline } from '@mui/material'
66
import cookie from 'cookie'
77
import Backups from 'pages/Backups'
8+
import Netpols from 'pages/Netpols'
89
import Workloads from 'pages/Workloads'
910
import OtomiApp from 'pages/App'
1011
import Apps from 'pages/Apps'
@@ -26,6 +27,7 @@ import { Provider } from 'react-redux'
2627
import { Route, BrowserRouter as Router, Switch } from 'react-router-dom'
2728
import { store } from 'redux/store'
2829
import Backup from 'pages/Backup'
30+
import Netpol from 'pages/Netpol'
2931
import LoadingScreen from 'components/LoadingScreen'
3032
import Dashboard from 'pages/Dashboard'
3133
import Users from 'pages/Users'
@@ -45,9 +47,6 @@ import BuildsCreateEditPage from 'pages/builds/create-edit/BuildsCreateEditPage'
4547
import BuildsOverviewPage from 'pages/builds/overview/BuildsOverviewPage'
4648
import CodeRepositoriesCreateEditPage from 'pages/code-repositories/create-edit/CodeRepositoriesCreateEditPage'
4749
import CodeRepositoriesOverviewPage from 'pages/code-repositories/overview/CodeRepositoriesOverviewPage'
48-
import NetworkPoliciesOverviewPage from 'pages/network-policies/overview/NetworkPoliciesOverviewPage'
49-
import NetworkPoliciesIngressCreateEditPage from 'pages/network-policies/create-edit/NetworkPoliciesIngressCreateEditPage'
50-
import NetworkPoliciesEgressCreateEditPage from 'pages/network-policies/create-edit/NetworkPoliciesEgressCreateEditPage'
5150
import SecretOverviewPage from 'pages/secrets/overview/SecretOverviewPage'
5251
import SecretCreateEditPage from 'pages/secrets/create-edit/SecretCreateEditPage'
5352
import ServicesCreateEditPage from 'pages/services/create-edit/ServicesCreateEditPage'
@@ -126,12 +125,6 @@ function App() {
126125
platformAdminRoute
127126
exact
128127
/>
129-
<PrivateRoute
130-
path='/network-policies'
131-
component={NetworkPoliciesOverviewPage}
132-
platformAdminRoute
133-
exact
134-
/>
135128
<PrivateRoute path='/policies' component={Policies} platformAdminRoute exact />
136129
<PrivateRoute
137130
path='/policies/:policyName'
@@ -174,16 +167,7 @@ function App() {
174167
<PrivateRoute path='/teams' component={TeamsOverviewPage} platformAdminRoute exact />
175168
<PrivateRoute path='/teams/:teamId' component={TeamsCreateEditPage} exact />
176169
<PrivateRoute path='/teams/:teamId/backups/create' component={Backup} exact />
177-
<PrivateRoute
178-
path='/teams/:teamId/network-policies/inbound-rules/create'
179-
component={NetworkPoliciesIngressCreateEditPage}
180-
exact
181-
/>
182-
<PrivateRoute
183-
path='/teams/:teamId/network-policies/outbound-rules/create'
184-
component={NetworkPoliciesEgressCreateEditPage}
185-
exact
186-
/>
170+
<PrivateRoute path='/teams/:teamId/network-policies/create' component={Netpol} exact />
187171
<PrivateRoute
188172
path='/teams/:teamId/secrets/create'
189173
component={SecretCreateEditPage}
@@ -209,19 +193,10 @@ function App() {
209193
/>
210194
<PrivateRoute path='/teams/:teamId/backups' component={Backups} exact />
211195
<PrivateRoute path='/teams/:teamId/backups/:backupName' component={Backup} exact />
196+
<PrivateRoute path='/teams/:teamId/network-policies' component={Netpols} exact />
212197
<PrivateRoute
213-
path='/teams/:teamId/network-policies'
214-
component={NetworkPoliciesOverviewPage}
215-
exact
216-
/>
217-
<PrivateRoute
218-
path='/teams/:teamId/network-policies/inbound-rules/:networkPolicyName'
219-
component={NetworkPoliciesIngressCreateEditPage}
220-
exact
221-
/>
222-
<PrivateRoute
223-
path='/teams/:teamId/network-policies/outbound-rules/:networkPolicyName'
224-
component={NetworkPoliciesEgressCreateEditPage}
198+
path='/teams/:teamId/network-policies/:netpolName'
199+
component={Netpol}
225200
exact
226201
/>
227202
<PrivateRoute path='/teams/:teamId/projects' component={Projects} exact />

src/components/HeaderTitle.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ const useStyles = makeStyles()((theme) => ({
1313
padding: '16px !important',
1414
},
1515
},
16-
headTitle: {
17-
fontSize: '1.5rem',
18-
},
1916
headBackground: {
2017
backgroundColor: theme.palette.background.default,
2118
},
@@ -49,7 +46,7 @@ export default function HeaderTitle({
4946
return (
5047
<>
5148
<div className={cx(classes.head, altColor ? classes.headBackgroundAlt : classes.headBackground)}>
52-
<Typography variant='h4' className={classes.headTitle} data-cy={`heading-${resourceTypeLow}`}>
49+
<Typography variant='h4' data-cy={`heading-${resourceTypeLow}`}>
5350
{title}
5451
</Typography>
5552
{docUrl && <HelpButton id='form' size='small' href={`${docUrl}`} />}

src/components/ListTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export default function ({
3939
const { t } = useTranslation()
4040
// END HOOKS
4141
const resourceTypePlural = `${resourceType}_plural`
42-
const title = t('LIST_TITLE_NOSCOPE', { model: t(resourceTypePlural) })
42+
let title
43+
if ((adminOnly || !teamId) && !hasTeamScope) title = t('LIST_TITLE_NOSCOPE', { model: t(resourceTypePlural) })
44+
if ((adminOnly || !teamId) && hasTeamScope) title = t('LIST_TITLE', { model: t(resourceTypePlural) })
45+
if (!adminOnly && teamId) title = t('LIST_TITLE_TEAM', { model: t(resourceTypePlural), teamId })
4346
const resourceTypeLow = t(resourceTypePlural).replaceAll(' ', '-').toLowerCase()
4447
const redirect = to || (adminOnly ? `/${resourceTypeLow}/create` : `/teams/${oboTeamId}/${resourceTypeLow}/create`)
4548
return (
Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import MuiAutocomplete from '@mui/material/Autocomplete'
22
import React, { JSX, useState } from 'react'
3-
import ArrowDropDownIcon from '@mui/icons-material/ExpandMore'
43

5-
import type {
6-
AutocompleteChangeDetails,
7-
AutocompleteChangeReason,
8-
AutocompleteProps,
9-
AutocompleteRenderInputParams,
10-
} from '@mui/material/Autocomplete'
4+
import type { AutocompleteProps, AutocompleteRenderInputParams } from '@mui/material/Autocomplete'
5+
import ArrowDropDownIcon from '@mui/icons-material/ExpandMore'
116
import { TextField } from './TextField'
7+
128
import type { TextFieldProps } from './TextField'
139

1410
export interface EnhancedAutocompleteProps<
15-
T,
11+
T extends { label: string },
1612
Multiple extends boolean | undefined = undefined,
1713
DisableClearable extends boolean | undefined = undefined,
1814
FreeSolo extends boolean | undefined = undefined,
@@ -23,8 +19,6 @@ export interface EnhancedAutocompleteProps<
2319
helperText?: TextFieldProps['helperText']
2420
/** A required label for the Autocomplete to ensure accessibility. */
2521
label: string
26-
/** Optional field to hide label, mostly used in Key value components */
27-
hideLabel?: boolean
2822
/** Removes the top margin from the input label, if desired. */
2923
noMarginTop?: boolean
3024
/** Element to show when the Autocomplete search yields no results. */
@@ -33,105 +27,76 @@ export interface EnhancedAutocompleteProps<
3327
renderInput?: (_params: AutocompleteRenderInputParams) => React.ReactNode
3428
/** Label for the "select all" option. */
3529
selectAllLabel?: string
36-
/** Removes the "select all" option for multiselect */
37-
disableSelectAll?: boolean
3830
textFieldProps?: Partial<TextFieldProps>
3931
width?: 'small' | 'medium' | 'large'
4032
}
4133

34+
/**
35+
* An Autocomplete component that provides a user-friendly select input
36+
* allowing selection between options.
37+
*
38+
* @example
39+
* <Autocomplete
40+
* label="Select a Fruit"
41+
* onSelectionChange={(selected) => console.log(selected)}
42+
* options={[
43+
* {
44+
* label: 'Apple',
45+
* value: 'apple',
46+
* }
47+
* ]}
48+
* />
49+
*/
4250
export function Autocomplete<
43-
T,
51+
T extends { label: string },
4452
Multiple extends boolean | undefined = undefined,
4553
DisableClearable extends boolean | undefined = undefined,
4654
FreeSolo extends boolean | undefined = undefined,
4755
>(props: EnhancedAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>) {
4856
const {
4957
clearOnBlur,
5058
defaultValue,
51-
disablePortal = false,
59+
disablePortal = true,
5260
errorText = '',
5361
helperText,
54-
hideLabel = false,
5562
label,
5663
limitTags = 2,
5764
loading = false,
5865
loadingText,
59-
multiple,
60-
disableSelectAll = false,
6166
noOptionsText,
6267
onBlur,
6368
options,
6469
placeholder,
6570
renderInput,
66-
selectAllLabel = '',
6771
textFieldProps,
6872
value,
6973
onChange,
7074
width = 'medium',
7175
...rest
7276
} = props
73-
7477
const [inPlaceholder, setInPlaceholder] = useState('')
7578

76-
// --- select-all logic ---
77-
const isSelectAllActive = multiple && Array.isArray(value) && value.length === options.length
78-
79-
const selectAllText = isSelectAllActive ? 'Deselect All' : 'Select All'
80-
const selectAllOption = { label: `${selectAllText} ${selectAllLabel}` } as unknown as T
81-
const optionsWithSelectAll = [selectAllOption, ...options]
82-
83-
const handleChange: AutocompleteProps<T, Multiple, DisableClearable, FreeSolo>['onChange'] = (
84-
e,
85-
newValue,
86-
reason: AutocompleteChangeReason,
87-
details?: AutocompleteChangeDetails<T>,
88-
) => {
89-
if (!onChange) return
90-
91-
// if they clicked the "Select All" option
92-
if (details?.option === selectAllOption) {
93-
const next = isSelectAllActive ? ([] as unknown as typeof newValue) : (options as unknown as typeof newValue)
94-
onChange(e, next, reason, details)
95-
} else onChange(e, newValue, reason, details)
96-
}
97-
// --------------------------
98-
9979
return (
10080
<MuiAutocomplete
101-
options={multiple && !disableSelectAll && options.length > 0 ? optionsWithSelectAll : options}
102-
multiple={multiple}
103-
disableCloseOnSelect={multiple}
104-
clearOnBlur={clearOnBlur}
105-
data-qa-autocomplete={label}
106-
defaultValue={defaultValue}
107-
disablePortal={disablePortal}
108-
limitTags={limitTags}
109-
loading={loading}
110-
loadingText={loadingText || 'Loading...'}
111-
noOptionsText={noOptionsText || <i>You have no options to choose from</i>}
112-
onBlur={onBlur}
113-
onOpen={() => setInPlaceholder('Search')}
114-
onClose={() => setInPlaceholder(placeholder || '')}
115-
popupIcon={<ArrowDropDownIcon />}
81+
options={options}
11682
renderInput={
11783
renderInput ||
11884
((params) => (
11985
<TextField
120-
hideLabel={hideLabel}
12186
label={label}
12287
width={width}
12388
loading={loading}
124-
placeholder={inPlaceholder || placeholder || 'Select an option'}
89+
placeholder={inPlaceholder || (placeholder ?? 'Select an option')}
12590
{...params}
12691
error={!!errorText}
12792
helperText={helperText}
12893
InputProps={{
12994
...params.InputProps,
13095
...textFieldProps?.InputProps,
13196
sx: {
132-
display: 'flex',
133-
flexWrap: 'wrap',
134-
gap: 1,
97+
overflow: 'hidden',
98+
whiteSpace: 'nowrap',
99+
textOverflow: 'ellipsis',
135100
paddingRight: '44px',
136101
},
137102
}}
@@ -141,9 +106,21 @@ export function Autocomplete<
141106
/>
142107
))
143108
}
109+
clearOnBlur={clearOnBlur}
110+
data-qa-autocomplete={label}
111+
defaultValue={defaultValue}
112+
disablePortal={disablePortal}
113+
limitTags={limitTags}
114+
loading={loading}
115+
loadingText={loadingText || 'Loading...'}
116+
noOptionsText={noOptionsText || <i>You have no options to choose from</i>}
117+
onBlur={onBlur}
118+
onOpen={() => setInPlaceholder('Search')}
119+
onClose={() => setInPlaceholder(placeholder || '')}
120+
popupIcon={<ArrowDropDownIcon />}
144121
value={value}
145-
onChange={handleChange}
146122
{...rest}
123+
onChange={onChange}
147124
/>
148125
)
149126
}

0 commit comments

Comments
 (0)