From 33dc790137a4de3232bf65c14d01a05f33c2d73b Mon Sep 17 00:00:00 2001 From: checktheroads Date: Wed, 25 Mar 2020 11:23:45 -0700 Subject: [PATCH] fix logo file & width parameter handling --- docs/docs/ui.mdx | 16 ++++++++-------- hyperglass/configuration/models/web.py | 17 +++++++++++++---- hyperglass/constants.py | 2 +- hyperglass/ui/components/Title.js | 8 ++++---- install.sh | 2 +- pyproject.toml | 2 +- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/docs/ui.mdx b/docs/docs/ui.mdx index 9bfc637..83e6fcd 100644 --- a/docs/docs/ui.mdx +++ b/docs/docs/ui.mdx @@ -158,17 +158,17 @@ By default, no Opengraph image is set. If you define one with `image`, hyperglas | `query_vrf` | String | `'Routing Table'` | Query VRF form label. | | `subtitle` | String | `'AS{primary_asn}'` | Subtitle text. `{primary_asn}` will be replaced with the primary_asn value. | | `title` | String | `'hyperglass'` | Title text. | -| `title_mode` | String | `'text_only'` | Set the title mode. Must be text_only, logo_only, logo_title, or all | +| `title_mode` | String | `'text_only'` | Set the title mode. Must be text_only, logo_only, logo_subtitle, or all | -:::important Title Mode +:::note Title Mode The `title_mode` parameter behaves in the following manner: -| Mode | Behavior | -| ------------ | ------------------------------------------------------------------ | -| `text_only` | Shows the `title` and `subtitle` only. | -| `logo_only` | Shows the `logo` only. | -| `logo_title` | Shows the `logo` and `title` only. | -| `all` | Shows the `logo`, `title`, and `subtitle`. | +| Mode | Behavior | +| --------------- | ------------------------------------------------------------------ | +| `text_only` | Shows the `title` and `subtitle` only. | +| `logo_only` | Shows the `logo` only. | +| `logo_subtitle` | Shows the `logo` and `subtitle` only. | +| `all` | Shows the `logo`, `title`, and `subtitle`. | ::: diff --git a/hyperglass/configuration/models/web.py b/hyperglass/configuration/models/web.py index c48c4d8..11a8f01 100644 --- a/hyperglass/configuration/models/web.py +++ b/hyperglass/configuration/models/web.py @@ -1,7 +1,7 @@ """Validate branding configuration variables.""" # Standard Library -from typing import Optional +from typing import Optional, Union # Third Party from pydantic import ( @@ -92,8 +92,8 @@ class Logo(HyperglassLevel3): light: StrictStr = "images/hyperglass-light.png" dark: StrictStr = "images/hyperglass-dark.png" - width: StrictInt = 384 - height: Optional[StrictInt] + width: Optional[Union[StrictInt, constr(regex=r"^([1-9][0-9]?|100)\%$")]] = "80%" + height: Optional[Union[StrictInt, constr(regex=r"^([1-9][0-9]?|100)\%$")]] favicons: StrictStr = "ui/images/favicons/" @validator("favicons") @@ -133,7 +133,9 @@ class Terms(HyperglassLevel3): class Text(HyperglassLevel3): """Validation model for params.branding.text.""" - title_mode: constr(regex=("logo_only|text_only|logo_title|all")) = "logo_only" + title_mode: constr( + regex=("logo_only|text_only|logo_title|logo_subtitle|all") + ) = "logo_only" title: StrictStr = "hyperglass" subtitle: StrictStr = "AS{primary_asn}" query_location: StrictStr = "Location" @@ -143,6 +145,13 @@ class Text(HyperglassLevel3): fqdn_tooltip: StrictStr = "Use {protocol}" # Formatted by Javascript cache: StrictStr = "Results will be cached for {timeout} {period}." + @validator("title_mode") + def validate_title_mode(cls, value): + """Set legacy logo_title to logo_subtitle.""" + if value == "logo_title": + value = "logo_subtitle" + return value + class ThemeColors(HyperglassLevel4): """Validation model for theme colors.""" diff --git a/hyperglass/constants.py b/hyperglass/constants.py index 0e638dd..5b98f0c 100644 --- a/hyperglass/constants.py +++ b/hyperglass/constants.py @@ -4,7 +4,7 @@ import sys from datetime import datetime __name__ = "hyperglass" -__version__ = "1.0.0-beta.12" +__version__ = "1.0.0-beta.13" __author__ = "Matt Love" __copyright__ = f"Copyright {datetime.now().year} Matthew Love" __license__ = "BSD 3-Clause Clear License" diff --git a/hyperglass/ui/components/Title.js b/hyperglass/ui/components/Title.js index 3345785..9a19fca 100644 --- a/hyperglass/ui/components/Title.js +++ b/hyperglass/ui/components/Title.js @@ -46,10 +46,10 @@ const Logo = ({ text, logo }) => { const { colorMode } = useColorMode(); const logoColor = { light: logo.dark, dark: logo.light }; const logoPath = logoColor[colorMode]; - return {text.title}; + return {text.title}; }; -const LogoTitle = ({ text, logo, showSubtitle }) => ( +const LogoSubtitle = ({ text, logo, showSubtitle }) => ( <> @@ -67,11 +67,11 @@ const All = ({ text, logo, mediaSize, showSubtitle }) => ( ); -const modeMap = { text_only: TextOnly, logo_only: Logo, logo_title: LogoTitle, all: All }; +const modeMap = { text_only: TextOnly, logo_only: Logo, logo_subtitle: LogoSubtitle, all: All }; const widthMap = { text_only: "100%", logo_only: ["90%", "90%", "25%", "25%"], - logo_title: ["90%", "90%", "25%", "25%"], + logo_subtitle: ["90%", "90%", "25%", "25%"], all: ["90%", "90%", "25%", "25%"] }; diff --git a/install.sh b/install.sh index 127f848..4377557 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ set -e -HYPERGLASS_VERSION="1.0.0b12" +HYPERGLASS_VERSION="1.0.0b13" MIN_PYTHON_MAJOR="3" MIN_PYTHON_MINOR="6" diff --git a/pyproject.toml b/pyproject.toml index 5421a7e..f984239 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api" [tool.poetry] name = "hyperglass" -version = "1.0.0-beta.12" +version = "1.0.0-beta.13" description = "hyperglass is the modern network looking glass that tries to make the internet better." authors = ["Matt Love "] readme = "README.md"