Skip to content

Commit 723eefe

Browse files
committed
[dashboard] Migrate patches to upstream project
[dashboard] Fix nested lists in addtiionalProperties Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 2ac533f commit 723eefe

8 files changed

Lines changed: 262 additions & 47 deletions

File tree

‎packages/system/dashboard/images/openapi-ui-k8s-bff/Dockerfile‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# imported from https://github.com/cozystack/openapi-ui-k8s-bff
22
ARG NODE_VERSION=20.18.1
33
FROM node:${NODE_VERSION}-alpine AS builder
4-
RUN apk add git
54
WORKDIR /src
65

7-
ARG COMMIT_REF=88531ed6881b4ce4808e56c00905951d7ba8031c
6+
ARG COMMIT_REF=92906a7f21050cfb8e352f98d36b209c57844f63
87
RUN wget -O- https://github.com/PRO-Robotech/openapi-ui-k8s-bff/archive/${COMMIT_REF}.tar.gz | tar xzf - --strip-components=1
98

10-
COPY patches /patches
11-
RUN git apply /patches/*.diff
12-
139
ENV PATH=/src/node_modules/.bin:$PATH
1410
RUN npm install
1511
RUN npm run build

‎packages/system/dashboard/images/openapi-ui-k8s-bff/patches/namespaces.diff‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎packages/system/dashboard/images/openapi-ui/Dockerfile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG NODE_VERSION=20.18.1
55
FROM node:${NODE_VERSION}-alpine AS openapi-k8s-toolkit-builder
66
RUN apk add git
77
WORKDIR /src
8-
ARG COMMIT=e5f16b45de19f892de269cc4ef27e74aa62f4c92
8+
ARG COMMIT=7086a2d8a07dcf6a94bb4276433db5d84acfcf3b
99
RUN wget -O- https://github.com/cozystack/openapi-k8s-toolkit/archive/${COMMIT}.tar.gz | tar -xzvf- --strip-components=1
1010

1111
COPY openapi-k8s-toolkit/patches /patches
@@ -22,7 +22,7 @@ FROM node:${NODE_VERSION}-alpine AS builder
2222
RUN apk add git
2323
WORKDIR /src
2424

25-
ARG COMMIT_REF=9ce4367657f49c0032d8016b1d9491f8abbd2b15
25+
ARG COMMIT_REF=fe237518348e94cead6d4f3283b2fce27f26aa12
2626
RUN wget -O- https://github.com/PRO-Robotech/openapi-ui/archive/${COMMIT_REF}.tar.gz | tar xzf - --strip-components=1
2727

2828
COPY openapi-ui/patches /patches
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
diff --git a/src/components/molecules/BlackholeForm/molecules/FormObjectFromSwagger/FormObjectFromSwagger.tsx b/src/components/molecules/BlackholeForm/molecules/FormObjectFromSwagger/FormObjectFromSwagger.tsx
2+
index a7135d4..2fea0bb 100644
3+
--- a/src/components/molecules/BlackholeForm/molecules/FormObjectFromSwagger/FormObjectFromSwagger.tsx
4+
+++ b/src/components/molecules/BlackholeForm/molecules/FormObjectFromSwagger/FormObjectFromSwagger.tsx
5+
@@ -68,13 +68,60 @@ export const FormObjectFromSwagger: FC<TFormObjectFromSwaggerProps> = ({
6+
properties?: OpenAPIV2.SchemaObject['properties']
7+
required?: string
8+
}
9+
+
10+
+ // Check if the field name exists in additionalProperties.properties
11+
+ // If so, use the type from that property definition
12+
+ const nestedProp = addProps?.properties?.[additionalPropValue] as OpenAPIV2.SchemaObject | undefined
13+
+ let fieldType: string = addProps.type
14+
+ let fieldItems: { type: string } | undefined = addProps.items
15+
+ let fieldNestedProperties = addProps.properties || {}
16+
+ let fieldRequired: string | undefined = addProps.required
17+
+
18+
+ if (nestedProp) {
19+
+ // Use the nested property definition if it exists
20+
+ // Handle type - it can be string or string[] in OpenAPI v2
21+
+ if (nestedProp.type) {
22+
+ if (Array.isArray(nestedProp.type)) {
23+
+ fieldType = nestedProp.type[0] || addProps.type
24+
+ } else if (typeof nestedProp.type === 'string') {
25+
+ fieldType = nestedProp.type
26+
+ } else {
27+
+ fieldType = addProps.type
28+
+ }
29+
+ } else {
30+
+ fieldType = addProps.type
31+
+ }
32+
+
33+
+ // Handle items - it can be ItemsObject or ReferenceObject
34+
+ if (nestedProp.items) {
35+
+ // Check if it's a valid ItemsObject with type property
36+
+ if ('type' in nestedProp.items && typeof nestedProp.items.type === 'string') {
37+
+ fieldItems = { type: nestedProp.items.type }
38+
+ } else {
39+
+ fieldItems = addProps.items
40+
+ }
41+
+ } else {
42+
+ fieldItems = addProps.items
43+
+ }
44+
+
45+
+ fieldNestedProperties = nestedProp.properties || {}
46+
+ // Handle required field - it can be string[] in OpenAPI schema
47+
+ if (Array.isArray(nestedProp.required)) {
48+
+ fieldRequired = nestedProp.required.join(',')
49+
+ } else if (typeof nestedProp.required === 'string') {
50+
+ fieldRequired = nestedProp.required
51+
+ } else {
52+
+ fieldRequired = addProps.required
53+
+ }
54+
+ }
55+
+
56+
inputProps?.addField({
57+
path: Array.isArray(name) ? [...name, String(collapseTitle)] : [name, String(collapseTitle)],
58+
name: additionalPropValue,
59+
- type: addProps.type,
60+
- items: addProps.items,
61+
- nestedProperties: addProps.properties || {},
62+
- required: addProps.required,
63+
+ type: fieldType,
64+
+ items: fieldItems,
65+
+ nestedProperties: fieldNestedProperties,
66+
+ required: fieldRequired,
67+
})
68+
setAddditionalPropValue(undefined)
69+
}
70+
diff --git a/src/components/molecules/BlackholeForm/molecules/FormStringInput/FormStringInput.tsx b/src/components/molecules/BlackholeForm/molecules/FormStringInput/FormStringInput.tsx
71+
index 487d480..3ca46c1 100644
72+
--- a/src/components/molecules/BlackholeForm/molecules/FormStringInput/FormStringInput.tsx
73+
+++ b/src/components/molecules/BlackholeForm/molecules/FormStringInput/FormStringInput.tsx
74+
@@ -42,7 +42,11 @@ export const FormStringInput: FC<TFormStringInputProps> = ({
75+
const formValue = Form.useWatch(formFieldName)
76+
77+
// Derive multiline based on current local value
78+
- const isMultiline = useMemo(() => isMultilineString(formValue), [formValue])
79+
+ const isMultiline = useMemo(() => {
80+
+ // Normalize value for multiline check
81+
+ const value = typeof formValue === 'string' ? formValue : (formValue === null || formValue === undefined ? '' : String(formValue))
82+
+ return isMultilineString(value)
83+
+ }, [formValue])
84+
85+
const title = (
86+
<>
87+
@@ -77,6 +81,23 @@ export const FormStringInput: FC<TFormStringInputProps> = ({
88+
rules={[{ required: forceNonRequired === false && required?.includes(getStringByName(name)) }]}
89+
validateTrigger="onBlur"
90+
hasFeedback={designNewLayout ? { icons: feedbackIcons } : true}
91+
+ normalize={(value) => {
92+
+ // Normalize value to string - prevent "[object Object]" display
93+
+ if (value === undefined || value === null) {
94+
+ return ''
95+
+ }
96+
+ if (typeof value === 'string') {
97+
+ return value
98+
+ }
99+
+ if (typeof value === 'number' || typeof value === 'boolean') {
100+
+ return String(value)
101+
+ }
102+
+ // If it's an object or array, it shouldn't be in a string field - return empty string
103+
+ if (typeof value === 'object') {
104+
+ return ''
105+
+ }
106+
+ return String(value)
107+
+ }}
108+
>
109+
<Input.TextArea
110+
placeholder={getStringByName(name)}
111+
diff --git a/src/components/molecules/BlackholeForm/organisms/BlackholeForm/helpers/casts.ts b/src/components/molecules/BlackholeForm/organisms/BlackholeForm/helpers/casts.ts
112+
index 6f9eb39..835224c 100644
113+
--- a/src/components/molecules/BlackholeForm/organisms/BlackholeForm/helpers/casts.ts
114+
+++ b/src/components/molecules/BlackholeForm/organisms/BlackholeForm/helpers/casts.ts
115+
@@ -124,8 +124,26 @@ export const materializeAdditionalFromValues = (
116+
*
117+
* This is used when a new field appears in the data but doesn't yet exist in the schema.
118+
*/
119+
- const makeChildFromAP = (ap: any): OpenAPIV2.SchemaObject => {
120+
- const t = ap?.type ?? 'object'
121+
+ const makeChildFromAP = (ap: any, value?: unknown): OpenAPIV2.SchemaObject => {
122+
+ // Determine type based on actual value if not explicitly defined in additionalProperties
123+
+ let t = ap?.type
124+
+ if (!t && value !== undefined && value !== null) {
125+
+ if (Array.isArray(value)) {
126+
+ t = 'array'
127+
+ } else if (typeof value === 'object') {
128+
+ t = 'object'
129+
+ } else if (typeof value === 'string') {
130+
+ t = 'string'
131+
+ } else if (typeof value === 'number') {
132+
+ t = 'number'
133+
+ } else if (typeof value === 'boolean') {
134+
+ t = 'boolean'
135+
+ } else {
136+
+ t = 'object'
137+
+ }
138+
+ }
139+
+ t = t ?? 'object'
140+
+
141+
const child: OpenAPIV2.SchemaObject = { type: t } as any
142+
143+
// Copy common schema details (if present)
144+
@@ -134,6 +152,20 @@ export const materializeAdditionalFromValues = (
145+
if (ap?.required)
146+
(child as any).required = _.cloneDeep(ap.required)
147+
148+
+ // If value is an array and items type is not defined, infer it from the first item
149+
+ if (t === 'array' && Array.isArray(value) && value.length > 0 && !ap?.items) {
150+
+ const firstItem = value[0]
151+
+ if (typeof firstItem === 'string') {
152+
+ ;(child as any).items = { type: 'string' }
153+
+ } else if (typeof firstItem === 'number') {
154+
+ ;(child as any).items = { type: 'number' }
155+
+ } else if (typeof firstItem === 'boolean') {
156+
+ ;(child as any).items = { type: 'boolean' }
157+
+ } else if (typeof firstItem === 'object') {
158+
+ ;(child as any).items = { type: 'object' }
159+
+ }
160+
+ }
161+
+
162+
// Mark as originating from `additionalProperties`
163+
;(child as any).isAdditionalProperties = true
164+
return child
165+
@@ -177,7 +209,16 @@ export const materializeAdditionalFromValues = (
166+
167+
// If the key doesn't exist in schema, create it from `additionalProperties`
168+
if (!schemaNode.properties![k]) {
169+
- schemaNode.properties![k] = makeChildFromAP(ap)
170+
+ // Check if there's a nested property definition in additionalProperties
171+
+ const nestedProp = ap?.properties?.[k]
172+
+ if (nestedProp) {
173+
+ // Use the nested property definition from additionalProperties
174+
+ schemaNode.properties![k] = _.cloneDeep(nestedProp) as any
175+
+ ;(schemaNode.properties![k] as any).isAdditionalProperties = true
176+
+ } else {
177+
+ // Create from additionalProperties with value-based type inference
178+
+ schemaNode.properties![k] = makeChildFromAP(ap, vo[k])
179+
+ }
180+
// If it's an existing additional property, merge any nested structure
181+
} else if ((schemaNode.properties![k] as any).isAdditionalProperties && ap?.properties) {
182+
;(schemaNode.properties![k] as any).properties ??= _.cloneDeep(ap.properties)
183+
diff --git a/src/components/molecules/BlackholeForm/organisms/BlackholeForm/utils.tsx b/src/components/molecules/BlackholeForm/organisms/BlackholeForm/utils.tsx
184+
index 2d887c7..d69d711 100644
185+
--- a/src/components/molecules/BlackholeForm/organisms/BlackholeForm/utils.tsx
186+
+++ b/src/components/molecules/BlackholeForm/organisms/BlackholeForm/utils.tsx
187+
@@ -394,9 +394,11 @@ export const getArrayFormItemFromSwagger = ({
188+
{(fields, { add, remove }, { errors }) => (
189+
<>
190+
{fields.map(field => {
191+
- const fieldType = (
192+
+ const rawFieldType = (
193+
schema.items as (OpenAPIV2.ItemsObject & { properties?: OpenAPIV2.SchemaObject }) | undefined
194+
)?.type
195+
+ // Handle type as string or string[] (OpenAPI v2 allows both)
196+
+ const fieldType = Array.isArray(rawFieldType) ? rawFieldType[0] : rawFieldType
197+
const description = (schema.items as (OpenAPIV2.ItemsObject & { description?: string }) | undefined)
198+
?.description
199+
const entry = schema.items as
200+
@@ -577,7 +579,29 @@ export const getArrayFormItemFromSwagger = ({
201+
type="text"
202+
size="small"
203+
onClick={() => {
204+
- add()
205+
+ // Determine initial value based on item type
206+
+ const fieldType = (
207+
+ schema.items as (OpenAPIV2.ItemsObject & { properties?: OpenAPIV2.SchemaObject }) | undefined
208+
+ )?.type
209+
+
210+
+ let initialValue: unknown
211+
+ // Handle type as string or string[] (OpenAPI v2 allows both)
212+
+ const typeStr = Array.isArray(fieldType) ? fieldType[0] : fieldType
213+
+ if (typeStr === 'string') {
214+
+ initialValue = ''
215+
+ } else if (typeStr === 'number' || typeStr === 'integer') {
216+
+ initialValue = 0
217+
+ } else if (typeStr === 'boolean') {
218+
+ initialValue = false
219+
+ } else if (typeStr === 'array') {
220+
+ initialValue = []
221+
+ } else if (typeStr === 'object') {
222+
+ initialValue = {}
223+
+ } else {
224+
+ initialValue = ''
225+
+ }
226+
+
227+
+ add(initialValue)
228+
}}
229+
>
230+
<PlusIcon />

‎packages/system/dashboard/images/openapi-ui/openapi-ui/patches/namespaces.diff‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
diff --git a/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx b/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx
2-
index b6fb99f..965bac0 100644
2+
index ac56e5f..c6e2350 100644
33
--- a/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx
44
+++ b/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx
5-
@@ -1,11 +1,16 @@
5+
@@ -1,6 +1,6 @@
66
import React, { FC, useState } from 'react'
77
import { Button, Alert, Spin, Typography } from 'antd'
8-
-import { filterSelectOptions, Spacer, useBuiltinResources } from '@prorobotech/openapi-k8s-toolkit'
8+
-import { filterSelectOptions, Spacer, useBuiltinResources, useApiResources } from '@prorobotech/openapi-k8s-toolkit'
99
+import { filterSelectOptions, Spacer, useApiResources } from '@prorobotech/openapi-k8s-toolkit'
1010
import { useNavigate } from 'react-router-dom'
1111
import { useSelector, useDispatch } from 'react-redux'
1212
import { RootState } from 'store/store'
13-
import { setCluster } from 'store/cluster/cluster/cluster'
13+
@@ -11,6 +11,11 @@ import {
14+
CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME,
15+
} from 'constants/customizationApiGroupAndVersion'
1416
import { Styled } from './styled'
1517
+import {
1618
+ BASE_PROJECTS_API_GROUP,
@@ -20,9 +22,9 @@ index b6fb99f..965bac0 100644
2022

2123
export const ListInsideClusterAndNs: FC = () => {
2224
const clusterList = useSelector((state: RootState) => state.clusterList.clusterList)
23-
@@ -17,9 +22,11 @@ export const ListInsideClusterAndNs: FC = () => {
24-
const [selectedCluster, setSelectedCluster] = useState<string>()
25-
const [selectedNamespace, setSelectedNamespace] = useState<string>()
25+
@@ -33,9 +38,11 @@ export const ListInsideClusterAndNs: FC = () => {
26+
typeof CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME === 'string' &&
27+
CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME.length > 0
2628

2729
- const namespacesData = useBuiltinResources({
2830
+ const namespacesData = useApiResources({
@@ -32,7 +34,7 @@ index b6fb99f..965bac0 100644
3234
+ apiVersion: BASE_PROJECTS_VERSION,
3335
+ typeName: BASE_PROJECTS_RESOURCE_NAME,
3436
limit: null,
35-
isEnabled: selectedCluster !== undefined,
37+
isEnabled: selectedCluster !== undefined && !isCustomNamespaceResource,
3638
})
3739
diff --git a/src/hooks/useNavSelectorInside.ts b/src/hooks/useNavSelectorInside.ts
3840
index 5736e2b..1ec0f71 100644

0 commit comments

Comments
 (0)