Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PORTALS-3385: [CCKP Homepage_V1] Add icons to CCKP cards for data types #1620

Merged
merged 6 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions packages/synapse-react-client/src/components/IconList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useMemo } from 'react'
import { useCallback, useMemo } from 'react'
import IconSvg, { IconSvgProps } from './IconSvg/IconSvg'
import { merge } from 'lodash-es'
import { useQueryContext } from './QueryContext'
import { UniqueFacetIdentifier } from '../utils'

type IconConfigs = {
[index: string]: IconSvgProps // if the icon option has the "label" set, it will show tooltip in IconSvg
Expand Down Expand Up @@ -29,6 +31,18 @@ function IconList(props: IconListProps) {
let noMatch: boolean = false
const css = useTheme ? 'icon-list themed' : 'icon-list'
const componentCss = useBackground ? `${css} bg-circle` : css
const queryContext = useQueryContext()
const { addValueToSelectedFacet } = queryContext

const handleIconClick = useCallback(
(dataType: 'string') => {
const facet: UniqueFacetIdentifier = {
columnName: 'dataType',
}
addValueToSelectedFacet(facet, dataType)
},
[addValueToSelectedFacet],
)

const mergedIconConfigs: IconConfigs = useMemo(() => {
const mergedIconConfigs: IconConfigs = {}
Expand All @@ -47,7 +61,13 @@ function IconList(props: IconListProps) {
noMatch = true
return
} else {
return <IconSvg key={el} {...iconConfig} />
return (
<IconSvg
key={el}
{...iconConfig}
onClick={() => handleIconClick(el)}
/>
)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export type IconName = (typeof IconStrings)[number]
export type IconSvgProps = {
icon: IconName
// If provided, will be shown in tooltip
onClick?: () => void
label?: string
wrap?: boolean
} & SvgIconProps
Expand Down Expand Up @@ -539,7 +540,7 @@ function IconMapping(props: { icon: string } & SvgIconProps) {
}

function IconSvg(props: IconSvgProps) {
const { icon, label = '', wrap = true, ...svgIconProps } = props
const { icon, label = '', onClick, wrap = true, ...svgIconProps } = props

const Wrapper = wrap ? 'span' : Fragment
const wrapperProps = wrap
Expand All @@ -548,6 +549,8 @@ function IconSvg(props: IconSvgProps) {
className: 'styled-svg-wrapper',
id: `icon-${icon}`,
role: 'img',
onClick,
style: onClick ? { cursor: 'pointer' } : {},
}
: {}

Expand Down
Loading