Skip to content

Commit

Permalink
Merge documentation and current value rendering into one componenet (#…
Browse files Browse the repository at this point in the history
…722)

* Condense config documentation and status to show in one block.

* Swap things around to make the current value prominent.

Before:

![image](https://github.com/user-attachments/assets/e554b0f7-408a-4ea6-9ffa-8df53119feac)


After:

![image](https://github.com/user-attachments/assets/26bcc16b-f85b-4639-9b8f-43f820158c7e)
  • Loading branch information
Gnuxie authored Feb 3, 2025
1 parent 69cf36b commit 2482402
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/commands/ProtectionsShowCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ DraupnirInterfaceAdaptor.describeRenderer(DraupnirProtectionsShowCommand, {
</span>
<p>{protectionInfo.description.description}</p>
<h3>Protection settings</h3>
{StandardPersistentConfigRenderer.renderConfigDocumentation(
protectionInfo.description.protectionSettings
)}
{StandardPersistentConfigRenderer.renderConfigStatus({
description: protectionInfo.description.protectionSettings,
error: undefined,
Expand Down
27 changes: 19 additions & 8 deletions src/safemode/PersistentConfigRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import {
ConfigDescription,
ConfigParseError,
ConfigPropertyDescription,
ConfigPropertyError,
ConfigPropertyUseError,
} from "matrix-protection-suite";
Expand Down Expand Up @@ -126,22 +127,30 @@ function renderConfigPropertyError(
}

function renderConfigProperty(
propertyKey: string,
configProperty: ConfigPropertyDescription,
data: Record<string, unknown>,
errors: ConfigPropertyError[]
): DocumentNode {
const propertyValue = data[propertyKey];
const error = findError(propertyKey, errors);
const propertyValue = data[configProperty.name];
const error = findError(configProperty.name, errors);
if (Array.isArray(propertyValue)) {
return (
<li>
<details>
<summary>
{renderConfigPropertyError(error)} <code>{propertyKey}</code>:
{renderConfigPropertyError(error)}{" "}
<code>{configProperty.name}</code>:
</summary>
{configProperty.description ?? "No description provided."} default
value: {renderConfigPropertyValue(configProperty.default)}.
<ul>
{propertyValue.map((value, index) =>
renderConfigPropertyItem(propertyKey, index, value, errors)
renderConfigPropertyItem(
configProperty.name,
index,
value,
errors
)
)}
</ul>
</details>
Expand All @@ -150,8 +159,10 @@ function renderConfigProperty(
}
return (
<li>
{renderConfigPropertyError(error)}
<code>{propertyKey}</code>: {renderConfigPropertyValue(propertyValue)}
{renderConfigPropertyError(error)} <code>{configProperty.name}</code>:{" "}
{configProperty.description ?? "No description provided."} default value:{" "}
{renderConfigPropertyValue(configProperty.default)}.
<p>{renderConfigPropertyValue(propertyValue)}</p>
</li>
);
}
Expand Down Expand Up @@ -219,7 +230,7 @@ export const StandardPersistentConfigRenderer = Object.freeze({
.properties()
.map((property) =>
renderConfigProperty(
property.name,
property,
config.data as Record<string, unknown>,
config.error?.errors ?? []
)
Expand Down

0 comments on commit 2482402

Please sign in to comment.