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 5 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
19 changes: 18 additions & 1 deletion 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 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,15 @@ 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 = (dataType: 'string') => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is recreated on rerender (I think). Is this a good place for a useCallback? (It's unclear to me if IconSvg is going to be re-rendered when this is recreated)

const facet: UniqueFacetIdentifier = {
columnName: 'dataType',
}
addValueToSelectedFacet(facet, dataType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that addValueToSelectedFacet in TableQueryReducerActions handles the case when the caller attempts to add the same facet value more than once (duplicate value is not pushed). So this should be fine!

}

const mergedIconConfigs: IconConfigs = useMemo(() => {
const mergedIconConfigs: IconConfigs = {}
Expand All @@ -47,7 +58,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