Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: yaml module height drag #630

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"lodash": "^4.17.21",
"moment": "^2.29.4",
"query-string": "^8.1.0",
"re-resizable": "^6.10.0",
"react": "18.2.0",
"react-diff-viewer-continued": "^3.3.1",
"react-dom": "18.2.0",
Expand Down
50 changes: 36 additions & 14 deletions ui/src/components/yaml/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useRef } from 'react'
import React, { useEffect, useRef, useState } from 'react'
import type { LegacyRef } from 'react'
import { Button, message } from 'antd'
import { Resizable } from 're-resizable'
import { useTranslation } from 'react-i18next'
import hljs from 'highlight.js'
import yaml from 'js-yaml'
Expand All @@ -21,6 +22,8 @@ const Yaml = (props: IProps) => {
const { t } = useTranslation()
const yamlRef = useRef<LegacyRef<HTMLDivElement> | undefined>()
const { data } = props
const [moduleHeight, setModuleHeight] = useState<number>(500)

useEffect(() => {
const yamlStatusJson = yaml2json(data)
if (yamlRef.current && yamlStatusJson?.data) {
Expand All @@ -42,19 +45,38 @@ const Yaml = (props: IProps) => {
}

return (
<div className={styles.yaml_content} style={{ height: props?.height }}>
<div className={styles.copy}>
{data && (
<Button type="primary" size="small" onClick={copy} disabled={!data}>
{t('Copy')}
</Button>
)}
</div>
<div
className={styles.yaml_box}
style={{ height: props?.height }}
ref={yamlRef as any}
/>
<div style={{ paddingBottom: 20 }}>
<Resizable
defaultSize={{
height: moduleHeight,
}}
onResizeStop={(e, direction, ref, d) => {
const newModuleHeight = moduleHeight + d.height
setModuleHeight(newModuleHeight)
}}
>
<div className={styles.yaml_content} style={{ height: props?.height }}>
<div className={styles.copy}>
{data && (
<Button
type="primary"
size="small"
onClick={copy}
disabled={!data}
>
{t('Copy')}
</Button>
)}
</div>
<div className={styles.yaml_container}>
<div
className={styles.yaml_box}
style={{ height: props?.height }}
ref={yamlRef as any}
/>
</div>
</div>
</Resizable>
</div>
)
}
Expand Down
35 changes: 18 additions & 17 deletions ui/src/components/yaml/styles.module.less
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
.yaml_content {
position: relative;
height: 100%;
overflow-y: auto;
border-radius: 8px;

.copy {
position: absolute;
top: 20px;
right: 20px;
}

.yaml_box {
width: 100%;
height: 500px;
max-height: 800px;
min-height: 300px;
padding: 1.5rem 2rem;
overflow-y: auto;
font:
1.1em Inconsolata,
monospace;
color: #fff;
word-break: break-all;
white-space: pre-wrap;
.yaml_container {
height: 100%;
background-color: #000;
border-radius: 8px;
box-sizing: border-box;
.yaml_box {
width: 100%;
padding: 1.5rem 2rem;
overflow-y: auto;
font:
1.1em Inconsolata,
monospace;
color: #fff;
word-break: break-all;
white-space: pre-wrap;
background-color: #000;
border-radius: 8px;
box-sizing: border-box;
}
}
}
Loading