From f45f99c6dec212874cd7105214d8b32f3dda57c8 Mon Sep 17 00:00:00 2001 From: Cheshiriks Date: Tue, 7 May 2024 17:31:13 +0300 Subject: [PATCH] Fixed organization render avatar in vulnerability filters --- .../components/basic/AvatarRenderers.kt | 41 +++++++++++++++++++ .../components/inputform/InputWithDebounce.kt | 3 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/basic/AvatarRenderers.kt b/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/basic/AvatarRenderers.kt index 31463d29a3..072606f1d0 100644 --- a/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/basic/AvatarRenderers.kt +++ b/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/basic/AvatarRenderers.kt @@ -258,6 +258,26 @@ fun ChildrenBuilder.renderTopBarAvatar( } } +/** + * Render organization avatar or placeholder + * + * @param organizationDto organization to render avatar + * @param classes classes applied to [img] html tag + * @param link link to redirect to if clicked + * @param styleBuilder [CSSProperties] builder + */ +fun ChildrenBuilder.renderFilterAvatar( + organizationDto: OrganizationDto, + classes: String = "", + link: String? = null, + styleBuilder: CSSProperties.() -> Unit = {}, +) = renderFilterAvatar( + organizationDto.avatar?.avatarRenderer() ?: AVATAR_ORGANIZATION_PLACEHOLDER, + classes, + link ?: "/${organizationDto.name}", + styleBuilder +) + private fun ChildrenBuilder.renderAvatar( avatarLink: String, classes: String, @@ -283,3 +303,24 @@ private fun ChildrenBuilder.renderAvatar( } } ?: renderImg() } + +private fun ChildrenBuilder.renderFilterAvatar( + avatarLink: String, + classes: String, + link: String?, + styleBuilder: CSSProperties.() -> Unit, +) { + val renderImg: ChildrenBuilder.() -> Unit = { + img { + className = ClassName("avatar avatar-user border color-bg-default rounded-circle $classes") + src = avatarLink + style = jso { styleBuilder() } + } + } + link?.let { + Link { + to = it + renderImg() + } + } ?: renderImg() +} diff --git a/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/inputform/InputWithDebounce.kt b/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/inputform/InputWithDebounce.kt index a04965c106..43b3dd31a4 100644 --- a/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/inputform/InputWithDebounce.kt +++ b/frontend-common/src/main/kotlin/com/saveourtool/frontend/common/components/inputform/InputWithDebounce.kt @@ -6,6 +6,7 @@ import com.saveourtool.common.entities.OrganizationDto import com.saveourtool.common.info.UserInfo import com.saveourtool.common.utils.DEFAULT_DEBOUNCE_PERIOD import com.saveourtool.frontend.common.components.basic.renderAvatar +import com.saveourtool.frontend.common.components.basic.renderFilterAvatar import com.saveourtool.frontend.common.utils.* import js.core.jso @@ -142,7 +143,7 @@ fun renderOrganizationWithAvatar(childrenBuilder: ChildrenBuilder, organizationD style = jso { fontSize = 1.2.rem } - renderAvatar(organizationDto) { + renderFilterAvatar(organizationDto) { width = 2.rem height = 2.rem }