From 6d8a36e06120bcd8a81b6ca70468b263b3e546c6 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 24 Sep 2021 14:49:18 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B03882=20-=20Fix=20null=20status=20color?= =?UTF-8?q?=20when=20class=20has=20no=20style=20defined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/application/UI/Base/Component/Pill/PillFactory.php | 2 +- .../application/UI/Base/Layout/Object/ObjectDetails.php | 7 ++++++- sources/application/UI/Helper/UIHelper.php | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sources/application/UI/Base/Component/Pill/PillFactory.php b/sources/application/UI/Base/Component/Pill/PillFactory.php index cfbaf5958..e5ee624ae 100644 --- a/sources/application/UI/Base/Component/Pill/PillFactory.php +++ b/sources/application/UI/Base/Component/Pill/PillFactory.php @@ -37,7 +37,7 @@ class PillFactory if ($oStyle !== null) { $oPill->SetCSSColorClass($oStyle->GetStyleClass()); } else { - $oPill->SetSemanticColor(UIHelper::GetColorFromStatusCode($sStateCode)); + $oPill->SetSemanticColor(UIHelper::GetColorNameFromStatusCode($sStateCode)); } return $oPill; diff --git a/sources/application/UI/Base/Layout/Object/ObjectDetails.php b/sources/application/UI/Base/Layout/Object/ObjectDetails.php index 3c14642ac..056029ac5 100644 --- a/sources/application/UI/Base/Layout/Object/ObjectDetails.php +++ b/sources/application/UI/Base/Layout/Object/ObjectDetails.php @@ -63,7 +63,7 @@ class ObjectDetails extends Panel implements iKeyboardShortcut protected $sStatusCode; /** @var string Label of the current value of the attribute carrying the state for $sClassName */ protected $sStatusLabel; - /** @var string */ + /** @var string Color value (eg. #ABCDEF, var(--foo-color), ...) */ protected $sStatusColor; /** @@ -240,6 +240,11 @@ class ObjectDetails extends Panel implements iKeyboardShortcut if ($oStyle !== null) { $this->sStatusColor = $oStyle->GetMainColor(); } + // If no style defined, fallback on a default color + else { + $sColorName = UIHelper::GetColorNameFromStatusCode($this->sStatusCode); + $this->sStatusColor = "var(--ibo-lifecycle-$sColorName-state-primary-color)"; + } } } diff --git a/sources/application/UI/Helper/UIHelper.php b/sources/application/UI/Helper/UIHelper.php index a87686d78..83ac99f52 100644 --- a/sources/application/UI/Helper/UIHelper.php +++ b/sources/application/UI/Helper/UIHelper.php @@ -22,9 +22,9 @@ class UIHelper * @param string $sStateCode Code of the state value * @param bool $bAllowFallbackIfNoMatch If set to true, a fallback semantic color code will be returned in case of no matching mappping. Otherwise it will return null to indicate there was no match. * - * @return string|null A semantic status color code (eg. success, pending, failure, neutral, ...) depending on the value's code. Usefull to try to find a semantic match when a class has no style defined on its state attribute. + * @return string|null A semantic status color name (eg. success, pending, failure, neutral, ...) depending on the value's code. Usefull to try to find a semantic match when a class has no style defined on its state attribute. */ - public static function GetColorFromStatusCode(string $sStateCode, bool $bAllowFallbackIfNoMatch = true): ?string + public static function GetColorNameFromStatusCode(string $sStateCode, bool $bAllowFallbackIfNoMatch = true): ?string { $sStatusColor = null;