Skip to content

Commit

Permalink
Fixed organization render avatar in vulnerability filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheshiriks committed May 7, 2024
1 parent e101105 commit f45f99c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f45f99c

Please sign in to comment.