11import React from 'react' ;
22import { useTranslation } from 'react-i18next' ;
3- import { omit , omitBy , isEmpty , isObject , has , map , startCase , includes , get , without , forEach , flatten , values , pickBy , isEqual , filter , reject , cloneDeep , keys } from 'lodash' ;
3+ import { omit , omitBy , isEmpty , isObject , has , map , startCase , includes , get , without , forEach , flatten , values , pickBy , isEqual , filter , reject , cloneDeep , keys , find } from 'lodash' ;
44import InfoIcon from '@mui/icons-material/InfoOutlined' ;
5+ import MappedIcon from '@mui/icons-material/Link' ;
56import Button from '@mui/material/Button' ;
67import Badge from '@mui/material/Badge' ;
78import Tooltip from '@mui/material/Tooltip' ;
@@ -18,7 +19,7 @@ import CircularProgress from '@mui/material/CircularProgress';
1819import { URIToParentParams , currentUserHasAccess } from '../../common/utils'
1920import { FACET_ORDER } from './ResultConstants' ;
2021
21- const SearchFilters = ( { filters, resource, onChange, kwargs, bgColor, appliedFilters, fieldOrder, noSubheader, disabledZero, filterDefinitions, nested, onSaveAsDefaultFilters, loading, repoDefaultFilters, propertyFilters, heightToSubtract, open} ) => {
22+ const SearchFilters = ( { filters, resource, onChange, kwargs, bgColor, appliedFilters, fieldOrder, noSubheader, disabledZero, filterDefinitions, nested, onSaveAsDefaultFilters, loading, repoDefaultFilters, propertyFilters, heightToSubtract, open, columns } ) => {
2223 const { t } = useTranslation ( )
2324 const [ applied , setApplied ] = React . useState ( { } ) ;
2425 const [ count , setCount ] = React . useState ( 0 ) ;
@@ -96,14 +97,22 @@ const SearchFilters = ({filters, resource, onChange, kwargs, bgColor, appliedFil
9697 return label
9798 }
9899
99- const formattedListSubheader = field => {
100- if ( field . startsWith ( 'properties__' ) ) {
101- const fields = field . split ( '__' )
102- return startCase ( fields [ 1 ] )
103- } else if ( isFixedConceptField ( field ) ) {
104- return startCase ( field )
100+ const formattedListSubheader = field => field . startsWith ( 'properties__' ) ? startCase ( field . split ( '__' ) [ 1 ] ) : startCase ( field )
101+
102+ const getMappedToColumnName = field => {
103+ let mappedColumnName ;
104+ if ( columns ?. length ) {
105+ let isProperty = field . startsWith ( 'properties__' )
106+ if ( isProperty ) {
107+ let name = field . split ( '__' ) [ 1 ]
108+ mappedColumnName = find ( columns , column => column . label . toLowerCase ( ) === `Property: ${ name } ` . toLowerCase ( ) || column . label . toLowerCase ( ) . includes ( name . toLowerCase ( ) ) ) ?. original
109+ if ( ! mappedColumnName && name === 'concept_class' )
110+ mappedColumnName = find ( columns , column => column . label . toLowerCase ( ) === `Property: Class` . toLowerCase ( ) ) ?. original
111+ } else {
112+ mappedColumnName = find ( columns , column => column . label . toLowerCase ( ) === field . toLowerCase ( ) ) ?. original
113+ }
105114 }
106- return startCase ( field )
115+ return mappedColumnName
107116 }
108117
109118 const handleToggle = ( field , value ) => ( ) => {
@@ -180,6 +189,7 @@ const SearchFilters = ({filters, resource, onChange, kwargs, bgColor, appliedFil
180189 const getFilterList = ( fieldFilters , field ) => {
181190 const shouldShowExpand = fieldFilters . length > 5
182191 const isExpanded = expanded . includes ( field )
192+ const mappedColumnName = getMappedToColumnName ( field )
183193 return (
184194 < ListItem key = { field } sx = { { padding : 0 , flexDirection : 'column' } } >
185195 < List
@@ -193,8 +203,17 @@ const SearchFilters = ({filters, resource, onChange, kwargs, bgColor, appliedFil
193203 >
194204 {
195205 ! noSubheader &&
196- < ListSubheader sx = { { padding : '0 8px 0 0px' , fontWeight : 'bold' , backgroundColor : bgColor , lineHeight : '30px' } } >
197- { formattedListSubheader ( field ) }
206+ < ListSubheader sx = { { padding : '0 8px 0 0px' , fontWeight : 'bold' , backgroundColor : bgColor , lineHeight : '30px' , display : 'flex' , alignItems : 'center' , justifyContent : 'space-between' } } >
207+ < span > { formattedListSubheader ( field ) } </ span >
208+ {
209+ mappedColumnName &&
210+ < Tooltip title = { `Mapped to column ${ mappedColumnName } from input sheet` } >
211+ < span style = { { fontWeight : 'normal' , fontSize : '12px' , display : 'flex' , alignItems : 'center' } } >
212+ < MappedIcon color = 'warning' sx = { { marginRight : '4px' , fontSize : '14px' } } />
213+ { mappedColumnName }
214+ </ span >
215+ </ Tooltip >
216+ }
198217 </ ListSubheader >
199218 }
200219 {
@@ -249,7 +268,6 @@ const SearchFilters = ({filters, resource, onChange, kwargs, bgColor, appliedFil
249268 }
250269
251270
252- const isFixedConceptField = field => isConcept && [ 'conceptClass' , 'datatype' ] . includes ( field )
253271 const canUpdateDefaultFilters = nested && onSaveAsDefaultFilters && currentUserHasAccess ( )
254272 const topBarHeight = canUpdateDefaultFilters ? 60 : 30
255273 let totalFilters = { ...propertyFacets , ...uiFilters }
0 commit comments