mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Update UI include MDM IdP device mapping (#15509)
This commit is contained in:
parent
0e468b4981
commit
685353be61
3 changed files with 89 additions and 23 deletions
|
|
@ -84,6 +84,38 @@ export interface IDeviceUser {
|
|||
source: string;
|
||||
}
|
||||
|
||||
const DEVICE_USER_SOURCE_TO_DISPLAY: { [key: string]: string } = {
|
||||
google_chrome_profiles: "Google Chrome",
|
||||
mdm_idp_accounts: "identity provider",
|
||||
} as const;
|
||||
|
||||
const getDeviceUserSourceForDisplay = (s: string): string => {
|
||||
return DEVICE_USER_SOURCE_TO_DISPLAY[s] || s;
|
||||
};
|
||||
|
||||
const getDeviceUserForDisplay = (d: IDeviceUser): IDeviceUser => {
|
||||
return { ...d, source: getDeviceUserSourceForDisplay(d.source) };
|
||||
};
|
||||
|
||||
/*
|
||||
* mapDeviceUsersForDisplay is a helper function that takes an array of device users and returns a
|
||||
* new array of device users with the source field mapped to a more user-friendly value. It also
|
||||
* ensures that the identity provider account is always the first device user in the array.
|
||||
*/
|
||||
export const mapDeviceUsersForDisplay = (
|
||||
deviceMapping: IDeviceUser[]
|
||||
): IDeviceUser[] => {
|
||||
const newDeviceMapping: IDeviceUser[] = [];
|
||||
deviceMapping.forEach((d) => {
|
||||
if (d.source === "mdm_idp_accounts") {
|
||||
newDeviceMapping.unshift(getDeviceUserForDisplay(d));
|
||||
} else {
|
||||
newDeviceMapping.push(getDeviceUserForDisplay(d));
|
||||
}
|
||||
});
|
||||
return newDeviceMapping;
|
||||
};
|
||||
|
||||
export interface IDeviceMappingResponse {
|
||||
device_mapping: IDeviceUser[];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,16 @@
|
|||
color: $core-fleet-black;
|
||||
font-weight: $bold;
|
||||
}
|
||||
&__data {
|
||||
.device-mapping {
|
||||
&__source {
|
||||
color: $ui-fleet-black-75;
|
||||
}
|
||||
&__more {
|
||||
color: $ui-fleet-black-50;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.list {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,32 @@ import { HumanTimeDiffWithFleetLaunchCutoff } from "components/HumanTimeDiffWith
|
|||
import TooltipWrapper from "components/TooltipWrapper";
|
||||
import CustomLink from "components/CustomLink";
|
||||
|
||||
import { IHostMdmData, IMunkiData, IDeviceUser } from "interfaces/host";
|
||||
import {
|
||||
IHostMdmData,
|
||||
IMunkiData,
|
||||
IDeviceUser,
|
||||
mapDeviceUsersForDisplay,
|
||||
} from "interfaces/host";
|
||||
import {
|
||||
DEFAULT_EMPTY_CELL_VALUE,
|
||||
MDM_STATUS_TOOLTIP,
|
||||
} from "utilities/constants";
|
||||
|
||||
const getDeviceUserTipContent = (deviceMapping: IDeviceUser[]) => {
|
||||
if (deviceMapping.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const format = (d: IDeviceUser) =>
|
||||
d.source ? `${d.email} (${d.source})` : d.email;
|
||||
|
||||
return deviceMapping.slice(1).map((d) => (
|
||||
<span key={format(d)}>
|
||||
{format(d)}
|
||||
<br />
|
||||
</span>
|
||||
));
|
||||
};
|
||||
|
||||
interface IAboutProps {
|
||||
aboutData: { [key: string]: any };
|
||||
deviceMapping?: IDeviceUser[];
|
||||
|
|
@ -122,34 +142,38 @@ const About = ({
|
|||
return null;
|
||||
}
|
||||
|
||||
const numUsers = deviceMapping.length;
|
||||
const tooltipText = deviceMapping.map((d) => (
|
||||
<span key={Math.random().toString().slice(2)}>
|
||||
{d.email}
|
||||
<br />
|
||||
</span>
|
||||
));
|
||||
let displayPrimaryUser: React.ReactNode = DEFAULT_EMPTY_CELL_VALUE;
|
||||
|
||||
const newDeviceMapping = mapDeviceUsersForDisplay(deviceMapping);
|
||||
if (newDeviceMapping[0]) {
|
||||
const { email, source } = newDeviceMapping[0];
|
||||
if (!source) {
|
||||
displayPrimaryUser = email;
|
||||
} else {
|
||||
displayPrimaryUser = (
|
||||
<>
|
||||
{email}{" "}
|
||||
<span className="device-mapping__source">{`(${source})`}</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="info-grid__block">
|
||||
<span className="info-grid__header">Used by</span>
|
||||
<span className="info-grid__data">
|
||||
{numUsers > 1 ? (
|
||||
<>
|
||||
<span data-tip data-for="device_mapping" className="tooltip">
|
||||
{`${numUsers} users`}
|
||||
</span>
|
||||
<ReactTooltip
|
||||
effect="solid"
|
||||
backgroundColor="#3e4771"
|
||||
id="device_mapping"
|
||||
data-html
|
||||
>
|
||||
<span className={`tooltip__tooltip-text`}>{tooltipText}</span>
|
||||
</ReactTooltip>
|
||||
</>
|
||||
{newDeviceMapping.length > 1 ? (
|
||||
<TooltipWrapper
|
||||
tipContent={getDeviceUserTipContent(newDeviceMapping)}
|
||||
>
|
||||
{displayPrimaryUser}
|
||||
<span className="device-mapping__more">{` +${
|
||||
newDeviceMapping.length - 1
|
||||
} more`}</span>
|
||||
</TooltipWrapper>
|
||||
) : (
|
||||
deviceMapping[0].email || DEFAULT_EMPTY_CELL_VALUE
|
||||
displayPrimaryUser
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue