Skip to content

Commit 7061612

Browse files
authored
Support monospace font hint for admin UI settings fields (PP-4734) (#3539)
## Description Adds a `use_monospace_font` boolean hint to `FormMetadata` for integration settings fields. When set to `True`, the flag is included in the serialized form entry sent to the Admin UI, signaling that the field's input should be rendered in a monospace font. The flag defaults to `False` and is omitted from the output when false to keep the payload minimal. ## Motivation and Context Some settings fields (structured data, filter code snippets) are easier to read and edit in a monospace font. The Admin UI needs a backend-supplied hint to know when to apply that treatment. This is the backend half of the work, with the frontend side tracked on ThePalaceProject/circulation-admin#307. It is safe to merge them independently. [Jira PP-4734] ## How Has This Been Tested? - Manual testing in local dev environment with frontend dev-server. - New tests for this functionality. - All tests pass locally. - [CI tests](https://github.com/ThePalaceProject/circulation/actions/runs/28827880245) pass. ## Checklist - N/A - I have updated the documentation accordingly. - [x] All new and existing tests passed.
1 parent fd81933 commit 7061612

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/palace/manager/integration/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ class FormMetadata(LoggerMixin):
118118
# If set to True, the Admin UI will be directed to hide this field.
119119
hidden: bool = False
120120

121+
# If set to True, hints the Admin UI that it should render the field's input in a
122+
# monospace font. Useful for fields whose values are easier to read in monospace
123+
# (e.g. structured data, code).
124+
use_monospace_font: bool = False
125+
121126
# If set to True, this field is eligible to be included in the patron auth filter
122127
# expression context. Fields that contain credentials (e.g., private keys, client
123128
# secrets) or large blobs (e.g., XML metadata) should leave this False.
@@ -179,6 +184,8 @@ def to_dict(
179184
]
180185
if self.format is not None:
181186
form_entry["format"] = self.format
187+
if self.use_monospace_font:
188+
form_entry["use_monospace_font"] = True
182189

183190
return self.weight, form_entry
184191

tests/manager/integration/test_settings.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,31 @@ def test_required(self, caplog: pytest.LogCaptureFixture) -> None:
549549
"a default value or factory and yet its required property is set to False"
550550
) in caplog.text
551551

552+
@pytest.mark.parametrize(
553+
"field_type, monospace, in_output",
554+
[
555+
pytest.param(FormFieldType.TEXTAREA, True, True, id="textarea-true"),
556+
pytest.param(FormFieldType.JSON, True, True, id="json-true"),
557+
pytest.param(FormFieldType.TEXT, True, True, id="text-true"),
558+
pytest.param(FormFieldType.TEXT, False, False, id="text-false"),
559+
pytest.param(FormFieldType.TEXT, None, False, id="text-default"),
560+
],
561+
)
562+
def test_monospace(
563+
self,
564+
field_type: FormFieldType,
565+
monospace: bool | None,
566+
in_output: bool,
567+
) -> None:
568+
kwargs: dict[str, Any] = {"label": "Test", "type": field_type}
569+
if monospace is not None:
570+
kwargs["use_monospace_font"] = monospace
571+
_, entry = FormMetadata(**kwargs).to_dict(MagicMock(), "test", False)
572+
if in_output:
573+
assert entry["use_monospace_font"] is True
574+
else:
575+
assert "use_monospace_font" not in entry
576+
552577
def test_get_form_field_label_by_alias(
553578
self, base_settings_fixture: BaseSettingsFixture
554579
) -> None:

0 commit comments

Comments
 (0)