import React, { useContext } from 'react'; import { Box, Grid2, Stack, Typography } from '@mui/material'; import AvatarFrame from '../assets/AvatarFrame'; import AvatarFrameMain from '../assets/AvatarFrameMain'; import { getComponentProps } from '../common/getComponentProps'; import { inputProps } from '../interface/inputfieldProps'; import { DataContext } from '../context/Context'; import { JsonFormsDispatch, useJsonForms, withJsonFormsControlProps } from '@jsonforms/react'; import { getFieldName } from '../permissions/getFieldName'; import ComponentWrapper from '../common/ComponentWrapper'; import defaultImage from '../assets/DefaultImage.png'; import { toLocaleStringForAmount } from '../common/formatUtils'; const LeaderBoard = React.memo( ({ data, uischema, path, schema, rootSchema, renderers }: inputProps) => { const uischemaData = uischema.config.main; const { pageName, permissions, theme, locale,serviceProvider} = useContext(DataContext); const fieldName = getFieldName(path); const nameKey = uischemaData.nameKey ?? 'name'; const imageKey = uischemaData.imageKey ?? 'image'; const scoreKey = uischemaData.scoreKey ?? 'score'; const ctx = useJsonForms(); const dynamicStyle = React.useMemo(() => { return serviceProvider( ctx, { onClick: uischema.config?.main?.styleFunction || 'getStyle', }, { event: { _reactName: 'onClick' }, path, }, ); }, [data, path]); const componentStyle = { ...uischema.config?.style, ...dynamicStyle }; const getScoreValue = (value: string | number) => { if (value === null || value === undefined) return ''; return uischemaData.isScoreAmount ? toLocaleStringForAmount(value, locale) : value; }; const tableUiSchema = { type: 'Control', scope: path, options: { widget: 'Table', }, config: { main: { enableTopToolbar: false, enableBottomToolbar: false, disableSorting: true, disableColumnResizing: true, disablePagination: true, initialDensity: 'comfortable', isLeaderBoard: true, }, style: { height: '100%', border: 'none', borderRadius: '8px', tableBodystyle: { '& tr:nth-of-type(1)': { backgroundColor: '#E3B505 !important', '& td': { color: 'white', }, }, '& tr:nth-of-type(2)': { backgroundColor: `${theme.myTheme.palette.primary.main} !important`, '& td': { color: 'white', }, }, '& tr:nth-of-type(3)': { backgroundColor: `${theme.myTheme.palette.primary.main} !important`, '& td': { color: 'white', }, }, '& tr:not(:nth-child(-n+3))': { '& td': { borderRight: '1px solid #c6c6c6', }, }, '& tr:nth-of-type(1): hover': { backgroundColor: '#E3B505 !important', }, '& tr:nth-of-type(2): hover': { backgroundColor: `${theme.myTheme.palette.primary.main} !important`, '& td': { color: 'white', }, }, '& tr:hover': { '& td:after': { backgroundColor: 'transparent', }, }, '& tr': { '& td': { fontWeight: 'bold', paddingTop: '0px', paddingBottom: '0px', '& div': { fontSize: '12px !important', }, }, }, }, tableHeadstyle: { background: theme.myTheme.palette.grey[700], color: 'white', boxShadow: 'none', fontWeight: 'bold', }, tablePaperstyle: { height: '100%', border: 'none', borderRadius: '8px', }, tableContainerstyle: { height: '100%', '&': { scrollbarGutter: 'stable', overflow: 'overlay', }, '&::-webkit-scrollbar': { width: '7px', height: '7px', }, '&::-webkit-scrollbar-track': { background: 'transparent', }, '&::-webkit-scrollbar-thumb': { background: '#b1b1b1', }, '&::-webkit-scrollbar-thumb:hover': { background: '#808080', }, }, }, }, elements: uischema.elements ?? [], }; return ( {getScoreValue(data?.[1]?.[scoreKey])} {getScoreValue(data?.[0]?.[scoreKey])} {getScoreValue(data?.[2]?.[scoreKey])} ); }, ); export default withJsonFormsControlProps(LeaderBoard);