forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toward declarative help for Galaxy markdown directives.
- Loading branch information
Showing
5 changed files
with
276 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import RAW_DIRECTIVE_DATA from "./directives.yml"; | ||
|
||
type DirectiveMode = "page" | "report"; | ||
|
||
type DirectiveMetadataValueByMode = { | ||
[key: string]: string; | ||
}; | ||
|
||
interface DirectiveMetadata { | ||
side_panel_name: string | DirectiveMetadataValueByMode; | ||
side_panel_description?: string | DirectiveMetadataValueByMode; | ||
help?: string | DirectiveMetadataValueByMode; | ||
} | ||
|
||
type DirectivesMetadata = { | ||
[key: string]: DirectiveMetadata; | ||
}; | ||
|
||
type SidePanelEntry = { | ||
[key: string]: string; | ||
}; | ||
|
||
const DIRECTIVE_METADATA = RAW_DIRECTIVE_DATA as DirectivesMetadata; | ||
|
||
export function directiveEntry( | ||
directiveId: string, | ||
mode: DirectiveMode, | ||
baseEntry: SidePanelEntry = {} | ||
): SidePanelEntry { | ||
const directiveMetadataData: DirectiveMetadata | undefined = DIRECTIVE_METADATA[directiveId]; | ||
if (directiveMetadataData == undefined) { | ||
throw Error(`Client logic error, cannot find directive metadata for ${directiveId}`); | ||
} | ||
let name = directiveMetadataData.side_panel_name; | ||
if (name && !(typeof name == "string")) { | ||
const modeName = name[mode]; | ||
if (modeName == undefined) { | ||
throw Error(`Client logic error, cannot find directive metadata for ${directiveId}`); | ||
} | ||
name = modeName; | ||
} | ||
let description = directiveMetadataData.side_panel_description; | ||
if (description && !(typeof description == "string")) { | ||
description = description[mode]; | ||
} | ||
let help = directiveMetadataData.help; | ||
if (help && !(typeof help == "string")) { | ||
help = help[mode]; | ||
} | ||
if (help) { | ||
help = help.replace(/%MODE%/g, mode); | ||
} | ||
const entry: SidePanelEntry = { id: directiveId, ...baseEntry }; | ||
if (name) { | ||
entry.name = name; | ||
} | ||
if (description) { | ||
entry.description = description; | ||
} | ||
if (help) { | ||
entry.help = help; | ||
} | ||
return entry; | ||
} |
Oops, something went wrong.