mirror of
https://github.com/harness/drone.git
synced 2025-05-21 19:39:59 +08:00
Schema integration
This commit is contained in:
parent
c90233ff49
commit
0436628aea
@ -38,7 +38,8 @@ export default function MonacoSourceCodeEditor({
|
|||||||
height,
|
height,
|
||||||
autoHeight,
|
autoHeight,
|
||||||
wordWrap = true,
|
wordWrap = true,
|
||||||
onChange = noop
|
onChange = noop,
|
||||||
|
schema
|
||||||
}: SourceCodeEditorProps) {
|
}: SourceCodeEditorProps) {
|
||||||
const [editor, setEditor] = useState<monacoEditor.editor.IStandaloneCodeEditor>()
|
const [editor, setEditor] = useState<monacoEditor.editor.IStandaloneCodeEditor>()
|
||||||
const scrollbar = autoHeight ? 'hidden' : 'auto'
|
const scrollbar = autoHeight ? 'hidden' : 'auto'
|
||||||
@ -51,6 +52,23 @@ export default function MonacoSourceCodeEditor({
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (window.monaco && language === 'yaml' && schema) {
|
||||||
|
monaco.languages.yaml?.yamlDefaults?.setDiagnosticsOptions?.({
|
||||||
|
validate: true,
|
||||||
|
enableSchemaRequest: false,
|
||||||
|
hover: true,
|
||||||
|
completion: true,
|
||||||
|
schemas: [
|
||||||
|
{
|
||||||
|
fileMatch: ['*'],
|
||||||
|
schema
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [language, schema])
|
||||||
|
|
||||||
useEventListener('resize', () => {
|
useEventListener('resize', () => {
|
||||||
editor?.layout({ width: 0, height: 0 })
|
editor?.layout({ width: 0, height: 0 })
|
||||||
window.requestAnimationFrame(() => editor?.layout())
|
window.requestAnimationFrame(() => editor?.layout())
|
||||||
|
@ -8,10 +8,11 @@ import { Color } from '@harnessio/design-system'
|
|||||||
import type { OpenapiCommitFilesRequest, RepoCommitFilesResponse } from 'services/code'
|
import type { OpenapiCommitFilesRequest, RepoCommitFilesResponse } from 'services/code'
|
||||||
import { useStrings } from 'framework/strings'
|
import { useStrings } from 'framework/strings'
|
||||||
import { useGetSpaceParam } from 'hooks/useGetSpaceParam'
|
import { useGetSpaceParam } from 'hooks/useGetSpaceParam'
|
||||||
import { SourceCodeEditor } from 'components/SourceCodeEditor/SourceCodeEditor'
|
import MonacoSourceCodeEditor from 'components/SourceCodeEditor/MonacoSourceCodeEditor'
|
||||||
import { useAppContext } from 'AppContext'
|
import { useAppContext } from 'AppContext'
|
||||||
import type { CODEProps } from 'RouteDefinitions'
|
import type { CODEProps } from 'RouteDefinitions'
|
||||||
import { getErrorMessage } from 'utils/Utils'
|
import { getErrorMessage } from 'utils/Utils'
|
||||||
|
import pipelineSchema from './schema/pipeline-schema.json'
|
||||||
|
|
||||||
import css from './NewPipeline.module.scss'
|
import css from './NewPipeline.module.scss'
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ const NewPipeline = (): JSX.Element => {
|
|||||||
|
|
||||||
const { mutate, loading } = useMutate<RepoCommitFilesResponse>({
|
const { mutate, loading } = useMutate<RepoCommitFilesResponse>({
|
||||||
verb: 'POST',
|
verb: 'POST',
|
||||||
path: `/api/v1/repos/test-space/vb-repo/+/commits`
|
path: `/api/v1/repos/${space}/vb-repo/+/commits`
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleSaveAndRun = (): void => {
|
const handleSaveAndRun = (): void => {
|
||||||
@ -90,8 +91,9 @@ const NewPipeline = (): JSX.Element => {
|
|||||||
/>
|
/>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<Container className={css.editorContainer}>
|
<Container className={css.editorContainer}>
|
||||||
<SourceCodeEditor
|
<MonacoSourceCodeEditor
|
||||||
language={'yaml'}
|
language={'yaml'}
|
||||||
|
schema={pipelineSchema}
|
||||||
source={
|
source={
|
||||||
'stages:\n- type: ci\n spec:\n steps:\n - type: script\n spec:\n run: echo hello world'
|
'stages:\n- type: ci\n spec:\n steps:\n - type: script\n spec:\n run: echo hello world'
|
||||||
}
|
}
|
||||||
|
2372
web/src/pages/NewPipeline/schema/pipeline-schema.json
Normal file
2372
web/src/pages/NewPipeline/schema/pipeline-schema.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -88,6 +88,7 @@ export interface SourceCodeEditorProps {
|
|||||||
autoHeight?: boolean
|
autoHeight?: boolean
|
||||||
wordWrap?: boolean
|
wordWrap?: boolean
|
||||||
onChange?: (value: string) => void
|
onChange?: (value: string) => void
|
||||||
|
schema?: Record<string, any>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monaco editor has a bug where when its value is set, the value
|
// Monaco editor has a bug where when its value is set, the value
|
||||||
|
Loading…
Reference in New Issue
Block a user