Line

You are reading the unreleased docs (next). See latest (v0.9)

ui/client/features/pages-editor/hooks/useSnippetEditor

Cockpit client (features), next. Source: ui/client/features/pages-editor/hooks/useSnippetEditor.tsx.

Functions#

useSnippetEditor()#

useSnippetEditor(feature, file, nodeId, contentHash, onSaved): object

Defined in: ui/client/features/pages-editor/hooks/useSnippetEditor.tsx:16

Isolated snippet edit + save-back-to-source for one node, extended by with JSX syntax highlighting and a diff preview shown before a save is actually committed. Called directly from the SnippetEditor component — a component may import a hook (only controllers/workflows/ services/domain imports are banned in component files), so the real fetch/save I/O, highlighting, and diffing all stay behind this hook and the layers it calls into rather than living in the component itself.

Parameters#

feature

string

file

string

nodeId

string

contentHash

string

onSaved

(tree) => void

Returns#

busy

busy: boolean

cancelSave

cancelSave: () => void

Returns

void

confirmSave

confirmSave: () => Promise<void>

The actual save-back-to-source call, only ever reached after the diff preview has been shown and explicitly confirmed. The hash sent is the one this snippet's own getNodeSnippet load resolved to; before that resolves, it's the tree's own hash (contentHash, the same file, from the same load that opened this node) — never an empty string, which the server now refuses outright.

Returns

Promise<void>

diffHunks

diffHunks: DiffHunk[]

hasChanges

hasChanges: boolean

highlightedHtml

highlightedHtml: string

requestSave

requestSave: () => void

Opens the diff preview — nothing is saved yet.

Returns

void

setSnippet

setSnippet: Dispatch<SetStateAction<string>>

showDiff

showDiff: boolean

snippet

snippet: string

status

status: StatusMessage | null