Skip to content

Commit 221858d

Browse files
authored
Merge pull request #197 from PRO-Robotech/feature/dev
form fixes | wildcards
2 parents d6cad1c + cc8996a commit 221858d

File tree

17 files changed

+628
-143
lines changed

17 files changed

+628
-143
lines changed

package-lock.json

Lines changed: 2 additions & 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@prorobotech/openapi-k8s-toolkit",
3-
"version": "0.0.1-alpha.138",
3+
"version": "0.0.1-alpha.139",
44
"description": "ProRobotech OpenAPI k8s tools",
55
"main": "dist/openapi-k8s-toolkit.cjs.js",
66
"module": "dist/openapi-k8s-toolkit.es.js",

src/components/molecules/BlackholeForm/atoms/HiddenContainer/HiddenContainer.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import React, { FC, PropsWithChildren } from 'react'
2-
import { includesArray } from 'utils/nestedStringsArrayInclude'
32
import { TFormName } from 'localTypes/form'
4-
import { PossibleHiddenContainer } from '../../atoms'
53
import { useHiddenPathsLayout } from '../../organisms/BlackholeForm/context'
4+
import { PossibleHiddenContainer } from '../../atoms'
5+
import { includesPath, toArray } from './utils'
6+
7+
export const HiddenContainer: FC<PropsWithChildren<{ name?: TFormName; secondName?: TFormName }>> = ({
8+
name,
9+
secondName,
10+
children,
11+
}) => {
12+
const hiddenPaths = useHiddenPathsLayout() // type: string[][]
613

7-
type THiddenContainerProps = PropsWithChildren<{
8-
name?: TFormName
9-
secondName?: TFormName
10-
}>
14+
const nameArr = toArray(name)
15+
const secondArr = toArray(secondName)
1116

12-
export const HiddenContainer: FC<THiddenContainerProps> = ({ name, secondName, children }) => {
13-
const hiddenPaths = useHiddenPathsLayout()
17+
const isHidden = !!hiddenPaths && !!nameArr && includesPath(hiddenPaths, nameArr)
1418

15-
const isHidden = name ? includesArray(hiddenPaths, Array.isArray(name) ? name : [name]) : false
16-
const isHiddenSecond = secondName
17-
? includesArray(hiddenPaths, Array.isArray(secondName) ? secondName : [secondName])
18-
: false
19+
const isHiddenSecond = !!hiddenPaths && !!secondArr && includesPath(hiddenPaths, secondArr)
1920

2021
return (
2122
<PossibleHiddenContainer $isHidden={!hiddenPaths || isHidden || isHiddenSecond}>{children}</PossibleHiddenContainer>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { TFormName } from 'localTypes/form'
2+
3+
// robust comparator: haystack is string[][], needle may have numbers
4+
export const includesPath = (haystack: string[][], needle: (string | number)[]) =>
5+
haystack.some(h => h.length === needle.length && h.every((seg, i) => seg === String(needle[i])))
6+
7+
export const toArray = (p?: TFormName): (string | number)[] | undefined =>
8+
// eslint-disable-next-line no-nested-ternary
9+
p === undefined ? undefined : Array.isArray(p) ? p : [p]

src/components/molecules/BlackholeForm/molecules/FormInlineYamlEditor/FormInlineYamlEditor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/* eslint-disable no-empty */
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33
import React, { FC, useEffect, useMemo, useRef, useState } from 'react'
4-
import { Form } from 'antd'
4+
import { Form, theme as antdtheme } from 'antd'
55
import Editor from '@monaco-editor/react'
66
import type * as monaco from 'monaco-editor'
77
import { TFormName, TPersistedControls } from 'localTypes/form'
88
import * as yaml from 'yaml'
99
import { useOnValuesChangeCallback } from '../../organisms/BlackholeForm/context'
10+
import { Styled } from './styled'
1011

1112
export const FormInlineYamlEditor: FC<{
1213
path: TFormName
1314
persistedControls: TPersistedControls
1415
externalValue?: unknown
1516
}> = ({ path, persistedControls, externalValue }) => {
17+
const { token } = antdtheme.useToken()
1618
const form = Form.useFormInstance()
1719
const onValuesChange = useOnValuesChangeCallback()
1820

@@ -73,7 +75,7 @@ export const FormInlineYamlEditor: FC<{
7375
}, [yamlText, modelUri])
7476

7577
return (
76-
<div style={{ height: 140 }}>
78+
<Styled.Container $colorBorder={token.colorBorder}>
7779
<Editor
7880
language="yaml"
7981
path={modelUri}
@@ -181,6 +183,6 @@ export const FormInlineYamlEditor: FC<{
181183
wordWrap: 'on',
182184
}}
183185
/>
184-
</div>
186+
</Styled.Container>
185187
)
186188
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import styled from 'styled-components'
2+
3+
type TContainerProps = {
4+
$colorBorder: string
5+
}
6+
7+
const Container = styled.div<TContainerProps>`
8+
height: 140px;
9+
border: 1px solid ${({ $colorBorder }) => $colorBorder};
10+
border-radius: 8px;
11+
padding: 2px;
12+
13+
.monaco-editor,
14+
.overflow-guard {
15+
border-radius: 8px;
16+
}
17+
`
18+
19+
export const Styled = {
20+
Container,
21+
}

src/components/molecules/BlackholeForm/molecules/YamlEditor/YamlEditor.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
/* eslint-disable no-nested-ternary */
33
import React, { FC, useEffect, useRef, useState } from 'react'
4+
import { theme as antdtheme } from 'antd'
45
import Editor from '@monaco-editor/react'
56
import type * as monaco from 'monaco-editor'
67
import * as yaml from 'yaml'
@@ -10,9 +11,11 @@ type TYamlEditProps = {
1011
theme: 'light' | 'dark'
1112
currentValues: Record<any, unknown>
1213
onChange: (values: Record<string, unknown>) => void
14+
editorUri: string
1315
}
1416

15-
export const YamlEditor: FC<TYamlEditProps> = ({ theme, currentValues, onChange }) => {
17+
export const YamlEditor: FC<TYamlEditProps> = ({ theme, currentValues, onChange, editorUri }) => {
18+
const { token } = antdtheme.useToken()
1619
const [yamlData, setYamlData] = useState<string>('')
1720

1821
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null)
@@ -37,7 +40,7 @@ export const YamlEditor: FC<TYamlEditProps> = ({ theme, currentValues, onChange
3740
const monaco = monacoRef.current
3841
if (editor && monaco) {
3942
if (isFocusedRef.current) return
40-
const uri = monaco.Uri.parse('inmemory://openapi-ui/form.yaml')
43+
const uri = monaco.Uri.parse(editorUri)
4144
let model = editor.getModel() || monaco.editor.getModel(uri)
4245

4346
if (!model) {
@@ -55,13 +58,13 @@ export const YamlEditor: FC<TYamlEditProps> = ({ theme, currentValues, onChange
5558
}
5659
}
5760
}
58-
}, [yamlData])
61+
}, [yamlData, editorUri])
5962

6063
return (
61-
<Styled.BorderRadiusContainer>
64+
<Styled.BorderRadiusContainer $colorBorder={token.colorBorder}>
6265
<Editor
6366
language="yaml"
64-
path="inmemory://openapi-ui/form.yaml"
67+
path={editorUri}
6568
keepCurrentModel
6669
width="100%"
6770
height="100%"

src/components/molecules/BlackholeForm/molecules/YamlEditor/styled.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import styled from 'styled-components'
22

3-
const BorderRadiusContainer = styled.div`
3+
type TBorderRadiusContainerProps = {
4+
$colorBorder: string
5+
}
6+
7+
const BorderRadiusContainer = styled.div<TBorderRadiusContainerProps>`
48
height: 100%;
9+
border: 1px solid ${({ $colorBorder }) => $colorBorder};
10+
border-radius: 8px;
11+
padding: 2px;
512
613
.monaco-editor,
714
.overflow-guard {

src/components/molecules/BlackholeForm/molecules/YamlEditorSingleton/YamlEditorSingleton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const YamlEditorSingleton: FC<TYamlEditorSingletonProps> = ({
110110
return (
111111
<>
112112
{contextHolder}
113-
<Styled.BorderRadiusContainer $designNewLayoutHeight={designNewLayoutHeight}>
113+
<Styled.BorderRadiusContainer $designNewLayoutHeight={designNewLayoutHeight} $colorBorder={token.colorBorder}>
114114
<Editor
115115
defaultLanguage="yaml"
116116
width="100%"

src/components/molecules/BlackholeForm/molecules/YamlEditorSingleton/styled.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import styled from 'styled-components'
22

33
type TBorderRadiusContainerProps = {
44
$designNewLayoutHeight?: number
5+
$colorBorder: string
56
}
67

78
const BorderRadiusContainer = styled.div<TBorderRadiusContainerProps>`
89
height: ${({ $designNewLayoutHeight }) => ($designNewLayoutHeight ? `${$designNewLayoutHeight}px` : '75vh')};
10+
border: 1px solid ${({ $colorBorder }) => $colorBorder};
11+
border-radius: 8px;
12+
padding: 2px;
13+
box-sizing: border-box;
914
1015
.monaco-editor,
1116
.overflow-guard {

0 commit comments

Comments
 (0)