import { css } from '@emotion/css'; import React, { ReactElement } from 'react'; import { useAsync } from 'react-use'; import { UserOrgDTO } from '@grafana/data'; import { Button, CustomScrollbar, Modal } from '@grafana/ui'; import config from 'app/core/config'; import { contextSrv } from 'app/core/services/context_srv'; import { api } from '../../features/profile/api'; interface Props { onDismiss: () => void; } export function OrgSwitcher({ onDismiss }: Props): ReactElement { const { value: orgs = [] } = useAsync(() => { return api.loadOrgs(); }, []); const currentOrgId = contextSrv.user.orgId; const contentClassName = css({ display: 'flex', maxHeight: 'calc(85vh - 42px)', }); const setCurrentOrg = async (org: UserOrgDTO) => { await api.setUserOrg(org); window.location.href = `${config.appSubUrl}${config.appSubUrl.endsWith('/') ? '' : '/'}?orgId=${org.orgId}`; }; return ( {orgs.map((org) => ( ))}
Name Role
{org.name} {org.role} {org.orgId === currentOrgId ? ( ) : ( )}
); }