From 6ff508c3181f10e02b09831ba1fc54b2b2fe64b2 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 25 Oct 2023 01:02:59 +0000 Subject: [PATCH 1/5] RenderPluginDoc - support `choices` as an object previously, `choices` was a list of options, now it can also be an object of options: description, where description can be a string or an array of strings No-Issue --- .../render-plugin-doc/render-plugin-doc.tsx | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/src/components/render-plugin-doc/render-plugin-doc.tsx b/src/components/render-plugin-doc/render-plugin-doc.tsx index 9b069c91f2..0c78535319 100644 --- a/src/components/render-plugin-doc/render-plugin-doc.tsx +++ b/src/components/render-plugin-doc/render-plugin-doc.tsx @@ -644,47 +644,75 @@ export class RenderPluginDoc extends React.Component { ); } + private renderLegend(legend) { + if (!legend) { + return null; + } + + if (!Array.isArray(legend)) { + legend = [legend]; + } + + return ( + <> + {' - '} + {legend.map((d) => ( +

{this.applyDocFormatters(d)}

+ ))} + + ); + } + private renderChoices(option) { - let choices, defaul; + let choices, + defaultChoice, + legends = {}; if (option['type'] === 'bool') { choices = ['true', 'false']; + if (option['default'] === true) { - defaul = 'true'; + defaultChoice = 'true'; } else if (option['default'] === false) { - defaul = 'false'; + defaultChoice = 'false'; } } else { choices = option['choices'] || []; - defaul = option['default']; + defaultChoice = option['default']; + } + + if (typeof choices === 'object' && !Array.isArray(choices)) { + legends = choices; + choices = Object.keys(choices); } return ( - + <> {choices && Array.isArray(choices) && choices.length !== 0 ? (
Choices:
    {choices.map((c, i) => (
  • - {c === defaul ? ( + {c === defaultChoice ? ( {c}  ← ) : ( c )} + {this.renderLegend(legends[c])}
  • ))}
) : null} - {defaul && !choices.includes(defaul) ? ( + {defaultChoice && !choices.includes(defaultChoice) ? ( Default: - {defaul} + {defaultChoice} ) : null} -
+ ); } From 3857148822f0c727a7122248419fe9694fa214a0 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 1 Nov 2023 01:48:39 +0000 Subject: [PATCH 2/5] PAUSED: Use `git resume` to continue working. [skip ci] --- src/components/render-plugin-doc/render-plugin-doc.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/render-plugin-doc/render-plugin-doc.tsx b/src/components/render-plugin-doc/render-plugin-doc.tsx index 0c78535319..43667a3f7d 100644 --- a/src/components/render-plugin-doc/render-plugin-doc.tsx +++ b/src/components/render-plugin-doc/render-plugin-doc.tsx @@ -653,6 +653,7 @@ export class RenderPluginDoc extends React.Component { legend = [legend]; } + // TODO look more like in https://docs.ansible.com/ansible/devel/collections/ansible/builtin/config_lookup.html#parameter-on_missing return ( <> {' - '} @@ -686,6 +687,9 @@ export class RenderPluginDoc extends React.Component { choices = Object.keys(choices); } + // DEBUG, http://localhost:8002/ui/repo/published/arista/eos/content/module/eos_acl_interfaces/ + legends = { merged: 'foo', replaced: ['foo', 'bar'] }; + return ( <> {choices && Array.isArray(choices) && choices.length !== 0 ? ( From 88dcb6833ff4bfe30c785f15f896561ea84615ce Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 1 Nov 2023 02:11:56 +0000 Subject: [PATCH 3/5] Choice, Legend - render a monospace choice name, and a potentially multiline description --- .../render-plugin-doc/render-plugin-doc.tsx | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/components/render-plugin-doc/render-plugin-doc.tsx b/src/components/render-plugin-doc/render-plugin-doc.tsx index 43667a3f7d..72d4b27059 100644 --- a/src/components/render-plugin-doc/render-plugin-doc.tsx +++ b/src/components/render-plugin-doc/render-plugin-doc.tsx @@ -1,5 +1,6 @@ +import { Trans, t } from '@lingui/macro'; import { dom, parse } from 'antsibull-docs'; -import React from 'react'; +import React, { ReactNode } from 'react'; import { PluginContentType, PluginDoc, @@ -31,6 +32,18 @@ interface IProps { renderWarning: (text: string) => React.ReactElement; } +function Choice({ children }: { children: ReactNode }) { + return
{children}
; +} + +function Legend({ children }: { children: ReactNode }) { + return ( +
+ {children} +
+ ); +} + export class RenderPluginDoc extends React.Component { subOptionsMaxDepth: number; returnContainMaxDepth: number; @@ -653,13 +666,17 @@ export class RenderPluginDoc extends React.Component { legend = [legend]; } - // TODO look more like in https://docs.ansible.com/ansible/devel/collections/ansible/builtin/config_lookup.html#parameter-on_missing return ( <> - {' - '} - {legend.map((d) => ( -

{this.applyDocFormatters(d)}

- ))} + {': '} + + {legend.map((d, i) => ( + <> + {i ?
: null} + {this.applyDocFormatters(d)} + + ))} +
); } @@ -687,21 +704,22 @@ export class RenderPluginDoc extends React.Component { choices = Object.keys(choices); } - // DEBUG, http://localhost:8002/ui/repo/published/arista/eos/content/module/eos_acl_interfaces/ - legends = { merged: 'foo', replaced: ['foo', 'bar'] }; - return ( <> {choices && Array.isArray(choices) && choices.length !== 0 ? (
- Choices: + + Choices: +
    {choices.map((c, i) => (
  • {c === defaultChoice ? ( - {c}  ← + + {c}  ← + ) : ( - c + {c} )} {this.renderLegend(legends[c])}
  • @@ -712,7 +730,9 @@ export class RenderPluginDoc extends React.Component { {defaultChoice && !choices.includes(defaultChoice) ? ( - Default: + + Default: + {defaultChoice} ) : null} From aa75213c297bbf4a8dbc00e08200094a4f16ec61 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 1 Nov 2023 02:22:13 +0000 Subject: [PATCH 4/5] also fix docs error rendering --- src/containers/collection-detail/collection-docs.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/containers/collection-detail/collection-docs.tsx b/src/containers/collection-detail/collection-docs.tsx index 84d5b76c09..3df8e1d5f2 100644 --- a/src/containers/collection-detail/collection-docs.tsx +++ b/src/containers/collection-detail/collection-docs.tsx @@ -155,7 +155,7 @@ class CollectionDocs extends React.Component { />
    {displayHTML || pluginData ? ( From 11f479a9b8e45266a91c0c4a3c6c78b14f561189 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Fri, 3 Nov 2023 23:40:58 +0000 Subject: [PATCH 5/5] Update src/components/render-plugin-doc/render-plugin-doc.tsx Co-authored-by: Felix Fontein --- src/components/render-plugin-doc/render-plugin-doc.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/render-plugin-doc/render-plugin-doc.tsx b/src/components/render-plugin-doc/render-plugin-doc.tsx index 72d4b27059..8dd45ae434 100644 --- a/src/components/render-plugin-doc/render-plugin-doc.tsx +++ b/src/components/render-plugin-doc/render-plugin-doc.tsx @@ -728,7 +728,7 @@ export class RenderPluginDoc extends React.Component {
    ) : null} - {defaultChoice && !choices.includes(defaultChoice) ? ( + {defaultChoice !== undefined && !choices.includes(defaultChoice) ? ( Default: