Skip to content

Commit f9d91ec

Browse files
feat: change the use of id to name (#518)
* feat: update build and workloads to use name instead of id * feat: convert resource ids to names * feat: disable editing of name * feat: fix backup and project creation * fix: handleDelete correctly * fix: show delete button if name or id is there * fix: onDelete for build * fix: user management page in team view * feat: update otomiApi.ts * fix: build status row * fix: users page --------- Co-authored-by: Ferruh Cihan <63190600+ferruhcihan@users.noreply.github.com>
1 parent 38f184d commit f9d91ec

34 files changed

+326
-691
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@
107107
"typescript": "4.7.3"
108108
},
109109
"engines": {
110-
"node": ">=20 <21",
111-
"npm": "^10"
110+
"node": ">=20 <21"
112111
},
113112
"lint-staged": {
114113
"*.{js,ts,tsx,json,md,yml,yaml}": [

src/App.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import Clusters from 'pages/Clusters'
1515
import Catalogs from 'pages/Catalogs'
1616
import Catalog from 'pages/Catalog'
1717
import Error from 'pages/Error'
18-
import Secret from 'pages/Secret'
1918
import SealedSecret from 'pages/SealedSecret'
20-
import Secrets from 'pages/Secrets'
2119
import SealedSecrets from 'pages/SealedSecrets'
2220
import Service from 'pages/Service'
2321
import Services from 'pages/Services'
@@ -108,7 +106,7 @@ function App() {
108106
exact
109107
/>
110108
<PrivateRoute
111-
path='/teams/:teamId/coderepositories/:coderepositoryId'
109+
path='/teams/:teamId/coderepositories/:codeRepositoryName'
112110
component={CodeRepository}
113111
exact
114112
/> */}
@@ -130,12 +128,11 @@ function App() {
130128
<PrivateRoute path='/catalogs/:teamId' component={Catalogs} exact />
131129
<PrivateRoute path='/catalogs/:teamId/:catalogName' component={Catalog} exact />
132130
<PrivateRoute
133-
path='/catalogs/:teamId/:catalogName/:workloadId'
131+
path='/catalogs/:teamId/:catalogName/:workloadName'
134132
component={Catalog}
135133
exact
136134
/>
137135
<PrivateRoute path='/services' component={Services} platformAdminRoute exact />
138-
<PrivateRoute path='/secrets' component={Secrets} platformAdminRoute exact />
139136
<PrivateRoute
140137
path='/sealed-secrets'
141138
component={SealedSecrets}
@@ -154,7 +151,6 @@ function App() {
154151
<PrivateRoute path='/teams/:teamId' component={Team} exact />
155152
<PrivateRoute path='/teams/:teamId/create-backup' component={Backup} exact />
156153
<PrivateRoute path='/teams/:teamId/create-netpol' component={Netpol} exact />
157-
<PrivateRoute path='/teams/:teamId/create-secret' component={Secret} exact />
158154
<PrivateRoute
159155
path='/teams/:teamId/create-sealedsecret'
160156
component={SealedSecret}
@@ -164,28 +160,26 @@ function App() {
164160
<PrivateRoute path='/teams/:teamId/create-user' component={User} exact />
165161
<PrivateRoute path='/teams/:teamId/create-project' component={Project} exact />
166162
<PrivateRoute path='/teams/:teamId/create-build' component={Build} exact />
167-
<PrivateRoute path='/teams/:teamId/secrets' component={Secrets} exact />
168163
<PrivateRoute path='/teams/:teamId/sealed-secrets' component={SealedSecrets} exact />
169-
<PrivateRoute path='/teams/:teamId/secrets/:secretId' component={Secret} exact />
170164
<PrivateRoute
171-
path='/teams/:teamId/sealed-secrets/:secretId'
165+
path='/teams/:teamId/sealed-secrets/:sealedSecretName'
172166
component={SealedSecret}
173167
exact
174168
/>
175169
<PrivateRoute path='/teams/:teamId/backups' component={Backups} exact />
176-
<PrivateRoute path='/teams/:teamId/backups/:backupId' component={Backup} exact />
170+
<PrivateRoute path='/teams/:teamId/backups/:backupName' component={Backup} exact />
177171
<PrivateRoute path='/teams/:teamId/netpols' component={Netpols} exact />
178-
<PrivateRoute path='/teams/:teamId/netpols/:netpolId' component={Netpol} exact />
172+
<PrivateRoute path='/teams/:teamId/netpols/:netpolName' component={Netpol} exact />
179173
<PrivateRoute path='/teams/:teamId/projects' component={Projects} exact />
180-
<PrivateRoute path='/teams/:teamId/projects/:projectId' component={Project} exact />
174+
<PrivateRoute path='/teams/:teamId/projects/:projectName' component={Project} exact />
181175
{/* <Route path='/teams/:teamId/builds' component={Builds} exact /> */}
182176
<PrivateRoute exact path='/teams/:teamId/builds' component={Builds} />
183-
<PrivateRoute path='/teams/:teamId/builds/:buildId' component={Build} exact />
177+
<PrivateRoute path='/teams/:teamId/builds/:buildName' component={Build} exact />
184178
<PrivateRoute path='/teams/:teamId/policies' component={Policies} exact />
185179
<PrivateRoute path='/teams/:teamId/policies/:policyId' component={Policy} exact />
186180
<PrivateRoute path='/teams/:teamId/workloads' component={Workloads} exact />
187181
<PrivateRoute path='/teams/:teamId/services' component={Services} exact />
188-
<PrivateRoute path='/teams/:teamId/services/:serviceId' component={Service} exact />
182+
<PrivateRoute path='/teams/:teamId/services/:serviceName' component={Service} exact />
189183
<PrivateRoute path='/maintenance' component={Maintenance} platformAdminRoute exact />
190184
<Route path='/logout' component={Logout} />
191185
<Route path='*'>

src/components/Backup.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ export const getBackupSchema = (teamId: string): any => {
1111
return schema
1212
}
1313

14-
export const getBackupUiSchema = (user: GetSessionApiResponse['user'], teamId: string): any => {
14+
export const getBackupUiSchema = (
15+
user: GetSessionApiResponse['user'],
16+
teamId: string,
17+
isNameEditable: boolean,
18+
): any => {
1519
const uiSchema = {
1620
id: { 'ui:widget': 'hidden' },
21+
name: { 'ui:readonly': !isNameEditable },
1722
teamId: { 'ui:widget': 'hidden' },
1823
namespace: teamId !== 'admin' && { 'ui:widget': 'hidden' },
1924
}
@@ -43,7 +48,7 @@ export default function ({ backup, teamId, ...other }: Props): React.ReactElemen
4348
// END HOOKS
4449
const formData = cloneDeep(data)
4550
const schema = getBackupSchema(teamId)
46-
const uiSchema = getBackupUiSchema(user, teamId)
51+
const uiSchema = getBackupUiSchema(user, teamId, !backup?.name)
4752
return (
4853
<Form
4954
schema={schema}

src/components/Backups.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface Row {
1515
}
1616

1717
const getBackupNames = (row: Row) => {
18-
const path = `/teams/${row.teamId}/backups/${encodeURIComponent(row.id)}`
18+
const path = `/teams/${row.teamId}/backups/${encodeURIComponent(row.name)}`
1919
return (
2020
<RLink to={path} label={row.name}>
2121
{row.name}

src/components/Build.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ export const getBuildSchema = (teamId: string): any => {
1111
return schema
1212
}
1313

14-
export const getBuildUiSchema = (user: GetSessionApiResponse['user'], teamId: string, formData: any): any => {
14+
export const getBuildUiSchema = (
15+
user: GetSessionApiResponse['user'],
16+
teamId: string,
17+
formData: any,
18+
isNameEditable: boolean,
19+
): any => {
1520
const uiSchema = {
1621
id: { 'ui:widget': 'hidden' },
1722
teamId: { 'ui:widget': 'hidden' },
23+
name: { 'ui:readonly': !isNameEditable },
1824
namespace: teamId !== 'admin' && { 'ui:widget': 'hidden' },
1925
secretName: !formData?.externalRepo && { 'ui:widget': 'hidden' },
2026
}
@@ -38,6 +44,6 @@ export default function ({ build, teamId, ...other }: Props): React.ReactElement
3844
// END HOOKS
3945
const formData = cloneDeep(data)
4046
const schema = getBuildSchema(teamId)
41-
const uiSchema = getBuildUiSchema(user, teamId, formData)
47+
const uiSchema = getBuildUiSchema(user, teamId, formData, !build?.name)
4248
return <Form schema={schema} uiSchema={uiSchema} data={formData} onChange={setData} resourceType='Build' {...other} />
4349
}

src/components/Builds.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface Row {
2323
}
2424

2525
const getBuildLink = (row: Row) => {
26-
const path = `/teams/${row.teamId}/builds/${encodeURIComponent(row.id)}`
26+
const path = `/teams/${row.teamId}/builds/${encodeURIComponent(row.name)}`
2727
return (
2828
<RLink to={path} label={row.name}>
2929
{row.name}
@@ -163,7 +163,7 @@ export default function ({ builds, teamId }: Props): React.ReactElement {
163163
{
164164
id: 'Status',
165165
label: 'Status',
166-
renderer: (row: Row) => getStatus(status?.builds?.[row.id]),
166+
renderer: (row: Row) => getStatus(status?.builds?.[row.name]),
167167
},
168168
]
169169

src/components/Catalog.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const getWorkloadSchema = (): any => {
8585
return cloneDeep(getSpec().components.schemas.Workload)
8686
}
8787

88-
export const getWorkloadUiSchema = (user: GetSessionApiResponse['user'], teamId: string): any => {
88+
export const getWorkloadUiSchema = (user: GetSessionApiResponse['user'], teamId: string, isNameEditable): any => {
8989
const uiSchema = {
9090
'ui:description': ' ',
9191
id: { 'ui:widget': 'hidden' },
@@ -100,6 +100,7 @@ export const getWorkloadUiSchema = (user: GetSessionApiResponse['user'], teamId:
100100
namespace: teamId !== 'admin' && { 'ui:widget': 'hidden' },
101101
createNamespace: teamId !== 'admin' && { 'ui:widget': 'hidden' },
102102
sidecarInject: teamId !== 'admin' && { 'ui:widget': 'hidden' },
103+
name: { 'ui:readonly': !isNameEditable },
103104
}
104105
applyAclToUiSchema(uiSchema, user, teamId, 'workload')
105106
return uiSchema
@@ -108,7 +109,7 @@ export const getWorkloadUiSchema = (user: GetSessionApiResponse['user'], teamId:
108109
interface Props extends CrudProps {
109110
teamId: string
110111
workload?: any
111-
workloadId?: string
112+
workloadName?: string
112113
values?: any
113114
createWorkload: any
114115
updateWorkload: any
@@ -120,7 +121,7 @@ interface Props extends CrudProps {
120121
export default function ({
121122
teamId,
122123
workload,
123-
workloadId,
124+
workloadName,
124125
values,
125126
createWorkload,
126127
updateWorkload,
@@ -144,7 +145,7 @@ export default function ({
144145
const [tab, setTab] = useState(defTab)
145146
const handleTabChange = (event, tab) => {
146147
// on the values tab, reset the values to see the comments in the code editor
147-
if (tab === 1 && !workloadId) setWorkloadValues(values)
148+
if (tab === 1 && !workloadName) setWorkloadValues(values)
148149
setTab(tab)
149150
}
150151
const [data, setData] = useState<any>(workload)
@@ -163,20 +164,20 @@ export default function ({
163164
const path = workload?.path
164165
const body = { ...workloadBody, chartMetadata, url: workload?.url, path }
165166
let res
166-
if (workloadId) {
167+
if (workloadName) {
167168
dispatch(setError(undefined))
168-
res = await updateWorkload({ teamId, workloadId, body })
169-
res = await updateWorkloadValues({ teamId, workloadId, body: { values: workloadValues } })
169+
res = await updateWorkload({ teamId, workloadName, body })
170+
res = await updateWorkloadValues({ teamId, workloadName, body: { values: workloadValues } })
170171
} else {
171172
res = await createWorkload({ teamId, body })
172-
res = await updateWorkloadValues({ teamId, workloadId: res.data.id, body: { values: workloadValues } })
173+
res = await updateWorkloadValues({ teamId, workloadName: res.data.name, body: { values: workloadValues } })
173174
}
174175
if (res.error) return
175176
history.push(`/teams/${teamId}/workloads`)
176177
}
177178

178179
const schema = getWorkloadSchema()
179-
const uiSchema = getWorkloadUiSchema(user, teamId)
180+
const uiSchema = getWorkloadUiSchema(user, teamId, !workload?.name)
180181

181182
return (
182183
<Box sx={{ width: '100%' }}>
@@ -210,9 +211,9 @@ export default function ({
210211
Submit
211212
</Button>
212213
)}
213-
{workloadId && (
214+
{workloadName && (
214215
<DeleteButton
215-
onDelete={() => deleteWorkload({ teamId, workloadId })}
216+
onDelete={() => deleteWorkload({ teamId, workloadName })}
216217
resourceName={workload?.name}
217218
resourceType='workload'
218219
data-cy='button-delete-workload'
@@ -334,9 +335,9 @@ export default function ({
334335
Submit
335336
</Button>
336337
)}
337-
{workloadId && (
338+
{workloadName && (
338339
<DeleteButton
339-
onDelete={() => deleteWorkload({ teamId, workloadId })}
340+
onDelete={() => deleteWorkload({ teamId, workloadName })}
340341
resourceName={workload?.name}
341342
resourceType='workload'
342343
data-cy='button-delete-workload'

src/components/Netpol.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ export const getNetpolSchema = (teamId: string, formData: any): any => {
2323
return schema
2424
}
2525

26-
export const getNetpolUiSchema = (user: GetSessionApiResponse['user'], teamId: string): any => {
26+
export const getNetpolUiSchema = (
27+
user: GetSessionApiResponse['user'],
28+
teamId: string,
29+
isNameEditable: boolean,
30+
): any => {
2731
const uiSchema = {
2832
id: { 'ui:widget': 'hidden' },
33+
name: { 'ui:readonly': !isNameEditable },
2934
teamId: { 'ui:widget': 'hidden' },
3035
}
3136
applyAclToUiSchema(uiSchema, user, teamId, 'netpol')
@@ -46,7 +51,7 @@ export default function ({ netpol, teamId, ...other }: Props): React.ReactElemen
4651
// END HOOKS
4752
const formData = cloneDeep(data)
4853
const schema = getNetpolSchema(teamId, formData)
49-
const uiSchema = getNetpolUiSchema(user, teamId)
54+
const uiSchema = getNetpolUiSchema(user, teamId, !netpol?.name)
5055
return (
5156
<Form schema={schema} uiSchema={uiSchema} data={formData} onChange={setData} resourceType='Netpol' {...other} />
5257
)

src/components/Netpols.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import ListTable from './ListTable'
88

99
const getNetpolLink = (isAdmin, ownerId) =>
1010
function (row) {
11-
const { teamId, id, name }: { teamId: string; id: string; name: string } = row
11+
const { teamId, name }: { teamId: string; id: string; name: string } = row
1212
if (!(isAdmin || teamId === ownerId)) return name
1313

1414
const path =
15-
isAdmin && !ownerId ? `/netpols/${encodeURIComponent(id)}` : `/teams/${teamId}/netpols/${encodeURIComponent(id)}`
15+
isAdmin && !ownerId
16+
? `/netpols/${encodeURIComponent(name)}`
17+
: `/teams/${teamId}/netpols/${encodeURIComponent(name)}`
1618
return (
1719
<RLink to={path} label={name}>
1820
{name}

0 commit comments

Comments
 (0)