Skip to content

Commit 5a6f90d

Browse files
committed
feat: disable editing of name
1 parent 03980ea commit 5a6f90d

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

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/Catalog.tsx

Lines changed: 3 additions & 2 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' },
@@ -98,6 +98,7 @@ export const getWorkloadUiSchema = (user: GetSessionApiResponse['user'], teamId:
9898
chart: { 'ui:widget': 'hidden' },
9999
revision: { 'ui:widget': 'hidden' },
100100
namespace: teamId !== 'admin' && { 'ui:widget': 'hidden' },
101+
name: { 'ui:readonly': !isNameEditable },
101102
}
102103
applyAclToUiSchema(uiSchema, user, teamId, 'workload')
103104
return uiSchema
@@ -187,7 +188,7 @@ export default function ({
187188
}
188189

189190
const schema = getWorkloadSchema()
190-
const uiSchema = getWorkloadUiSchema(user, teamId)
191+
const uiSchema = getWorkloadUiSchema(user, teamId, !workload?.name)
191192

192193
return (
193194
<Box sx={{ width: '100%' }}>

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/Project.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ const getProjectSchema = (): any => {
3434
return schema
3535
}
3636

37-
const getProjectUiSchema = (user: GetSessionApiResponse['user'], teamId: string): any => {
37+
const getProjectUiSchema = (user: GetSessionApiResponse['user'], teamId: string, isNameEditable: boolean): any => {
3838
const uiSchema = {
3939
id: { 'ui:widget': 'hidden' },
40+
name: { 'ui:readonly': !isNameEditable },
4041
teamId: { 'ui:widget': 'hidden' },
4142
build: { 'ui:widget': 'hidden' },
4243
workload: { 'ui:widget': 'hidden' },
@@ -220,7 +221,7 @@ export default function ({
220221
}, [project])
221222

222223
const projectSchema = getProjectSchema()
223-
const projectUiSchema = getProjectUiSchema(user, teamId)
224+
const projectUiSchema = getProjectUiSchema(user, teamId, !project?.name)
224225

225226
const buildSchema = getBuildSchema(teamId)
226227
const buildUiSchema = getBuildUiSchema(user, teamId, formData?.build, !project?.build?.name)
@@ -244,7 +245,7 @@ export default function ({
244245
const { data: k8sServices } = useGetTeamK8SServicesQuery({ teamId })
245246
const { data: secrets } = useGetSecretsFromK8SQuery({ teamId })
246247
const serviceSchema = getServiceSchema(appsEnabled, settings, formData?.service, teamId, secrets, k8sServices)
247-
const serviceUiSchema = getServiceUiSchema(appsEnabled, formData?.service, user, teamId)
248+
const serviceUiSchema = getServiceUiSchema(appsEnabled, formData?.service, user, teamId, !formData?.service.name)
248249
serviceUiSchema.name = { 'ui:widget': 'hidden' }
249250

250251
const teamSubdomain = getHost(formData?.name, teamId)

src/components/Service.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const getServiceUiSchema = (
135135
formData: GetServiceApiResponse,
136136
user: GetSessionApiResponse['user'],
137137
teamId: string,
138+
isNameEditable: boolean,
138139
isKsvc = false,
139140
): any => {
140141
const ing = formData?.ingress as Record<string, any>
@@ -145,6 +146,7 @@ export const getServiceUiSchema = (
145146
: { 'ui:widget': 'hidden' }
146147
const uiSchema: any = {
147148
id: { 'ui:widget': 'hidden' },
149+
name: { 'ui:readonly': !isNameEditable },
148150
teamId: { 'ui:widget': 'hidden' },
149151
ksvc: { 'ui:widget': ksvcWidget },
150152
ingress: {
@@ -214,7 +216,7 @@ export default function ({ service, k8sServices, secrets, teamId, ...other }: Pr
214216
updateIngressField(formData, defaultSubdomain, isKsvc)
215217
// pass to the schema getters that manipulate the schemas based on form data
216218
const schema = getServiceSchema(appsEnabled, settings, formData, teamId, secrets, k8sServices)
217-
const uiSchema = getServiceUiSchema(appsEnabled, formData, user, teamId, isKsvc)
219+
const uiSchema = getServiceUiSchema(appsEnabled, formData, user, teamId, !service?.name, isKsvc)
218220
return (
219221
<Form schema={schema} uiSchema={uiSchema} data={formData} onChange={setData} resourceType='Service' {...other} />
220222
)

src/components/rjsf/Form.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export default function ({
9393
const id = data?.[idProp]
9494
const initialNameRef = useRef(data?.[nameProp]) // Store initial name once
9595
const originalName = initialNameRef.current // Always refer to the initial name
96-
console.log('data', originalName)
9796
const docUrl =
9897
schema && schema['x-externalDocsPath'] ? `https://apl-docs.net/${schema['x-externalDocsPath']}` : undefined
9998
const keepValues = [[{}]] // rjsf structs that open parts of the form, may not be stripped

0 commit comments

Comments
 (0)