@equinor/fusion-react-ag-grid-person-cell
Version:
React component for displaying person details in AgGrid cell and PersonCard on cell hover
48 lines (47 loc) • 2.41 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { PersonAvatar, PersonCell } from '@equinor/fusion-react-person';
import { usePersonCellData } from './usePersonCellData';
import { PersonPopover } from './PersonPopover';
import styled from 'styled-components';
const Styled = {
ArrayContainer: styled.div `
display: flex;
align-items: center;
gap: 4px;
height: 100%;
`,
SingleContainer: styled.div `
display: flex;
align-items: center;
height: 100%;
`,
};
export const PersonCellRender = (params) => {
const { heading, subHeading, azureId, upn, dataSource, showAvatar, value, size } = params;
// Helper function to apply selector to data (handles both single items and arrays)
const applySelector = (selector, data) => {
if (!selector)
return undefined;
// If the data itself is an array, map the selector over each item
if (Array.isArray(data)) {
const results = data.map((item) => selector(item)).filter((result) => result !== undefined);
return results.length > 0 ? results : undefined;
}
// If data is not an array, apply selector directly
return selector(data);
};
// Apply selectors with automatic array handling
const azureResult = applySelector(azureId, value);
const upnResult = applySelector(upn, value);
const dataSourceResult = applySelector(dataSource, value);
const personData = usePersonCellData(azureResult, upnResult, dataSourceResult);
if (azureResult === undefined && upnResult === undefined && dataSourceResult === undefined) {
return null;
}
if (personData.isArray) {
return (_jsx(Styled.ArrayContainer, { children: personData.items?.map((item, index) => (_jsx(PersonPopover, { ...item, children: _jsx(PersonAvatar, { showLetter: !showAvatar, size: size ?? 'small', trigger: "none", ...item }) }, `person-${index}-${item.azureId || item.upn || 'unknown'}`))) }));
}
return (_jsx(Styled.SingleContainer, { children: _jsx(PersonPopover, { azureId: personData.single?.azureId, upn: personData.single?.upn, dataSource: personData.single?.dataSource, children: _jsx(PersonCell, { size: size ?? 'small', heading: heading, subHeading: subHeading, showAvatar: showAvatar, ...personData.single }) }) }));
};
PersonCellRender.displayName = 'PersonCellRender';
export default PersonCellRender;