-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1141 from upalatucci/editor-highlight
Bug 2167608: highlight parts
- Loading branch information
Showing
17 changed files
with
201 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/utils/components/SidebarEditor/useEditorHighlighter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import { YAMLEditorRef } from '@openshift-console/dynamic-plugin-sdk'; | ||
|
||
import { createSelection, getLinesToHighlight } from './utils'; | ||
|
||
export const useEditorHighlighter = ( | ||
editableYAML: string, | ||
pathsToHighlight: string[], | ||
showEditor: boolean, | ||
) => { | ||
const [editor, setEditor] = useState<YAMLEditorRef['editor']>(); | ||
const isHighlighed = useRef(false); | ||
|
||
useEffect(() => { | ||
isHighlighed.current = false; | ||
}, [pathsToHighlight, showEditor]); | ||
|
||
useEffect(() => { | ||
const highlightPaths = async () => { | ||
if (editor && editableYAML && pathsToHighlight && !isHighlighed.current) { | ||
isHighlighed.current = true; | ||
const ranges = getLinesToHighlight(editableYAML, pathsToHighlight); | ||
|
||
await editor.getAction('editor.foldAll').run(); | ||
|
||
const selections = ranges.map((range) => createSelection(range)); | ||
|
||
editor.setSelections(selections); | ||
await editor.getAction('editor.unfoldRecursively').run(); | ||
setTimeout(() => editor.revealLineInCenter(ranges.at(-1).start), 500); | ||
} | ||
}; | ||
|
||
highlightPaths(); | ||
}, [editableYAML, editor, pathsToHighlight]); | ||
|
||
return (ref: YAMLEditorRef) => setEditor(ref?.editor); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
export const NO_DATA_DASH = '-'; | ||
|
||
export const MILLISECONDS_TO_SECONDS_MULTIPLIER = 1000; | ||
|
||
export const PATHS_TO_HIGHLIGHT = { | ||
DETAILS_TAB: [ | ||
'spec.template.metadata.annotations', | ||
'spec.template.metadata.labels', | ||
'spec.template.spec.domain.cpu', | ||
'spec.template.spec.domain.resources.requests', | ||
'metadata.labels', | ||
'metadata.annotations', | ||
], | ||
ENV_TAB: ['spec.template.spec.domain.devices.disks', 'spec.template.spec.volumes'], | ||
DISKS_TAB: ['spec.template.spec.domain.devices.disks', 'spec.template.spec.volumes'], | ||
NETWORK_TAB: ['spec.template.spec.networks', 'spec.template.spec.domain.devices.interfaces'], | ||
SCHEDULING_TAB: [ | ||
'spec.template.spec.affinity', | ||
'spec.template.spec.tolerations', | ||
'spec.template.spec.nodeSelector', | ||
'spec.template.metadata.annotations', | ||
], | ||
SCRIPTS_TAB: ['spec.template.spec.volumes', 'spec.template.spec.accessCredentials'], | ||
DEFAULT: ['spec.template.spec.domain.devices.disks', 'spec.template.spec.volumes'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.