in public/apps/configuration/panels/role-view/tenants-panel.tsx [58:149]
export function TenantsPanel(props: RoleViewTenantsPanelProps) {
const [tenantPermissionDetail, setTenantPermissionDetail] = React.useState<
RoleTenantPermissionDetail[]
>([]);
const [currentUsername, setCurrentUsername] = React.useState('');
const [toasts, addToast, removeToast] = useToastState();
const [errorFlag, setErrorFlag] = React.useState(props.errorFlag);
React.useEffect(() => {
const fetchData = async () => {
try {
const rawTenantData = await fetchTenants(props.coreStart.http);
const processedTenantData = transformTenantData(rawTenantData, false);
setTenantPermissionDetail(
transformRoleTenantPermissionData(props.tenantPermissions, processedTenantData)
);
const currentUser = await getCurrentUser(props.coreStart.http);
setCurrentUsername(currentUser);
} catch (e) {
console.log(e);
setErrorFlag(true);
}
};
fetchData();
}, [props]);
const viewDashboard = async (tenantName: string) => {
try {
await selectTenant(props.coreStart.http, {
tenant: tenantName,
username: currentUsername,
});
window.location.href = getNavLinkById(props.coreStart, PageId.dashboardId);
} catch (e) {
console.log(e);
addToast(createUnknownErrorToast('viewDashboard', `view dashboard for ${tenantName} tenant`));
}
};
const viewVisualization = async (tenantName: string) => {
try {
await selectTenant(props.coreStart.http, {
tenant: tenantName,
username: currentUsername,
});
window.location.href = getNavLinkById(props.coreStart, PageId.visualizationId);
} catch (e) {
console.log(e);
addToast(
createUnknownErrorToast('viewVisualization', `view visualization for ${tenantName} tenant`)
);
}
};
const columns: Array<EuiBasicTableColumn<RoleTenantPermissionDetail>> = [
{
field: 'tenant_patterns',
name: 'Name',
render: truncatedListView(tableItemsUIProps),
truncateText: true,
sortable: true,
},
{
field: 'description',
name: 'Description',
truncateText: true,
},
{
field: 'permissionType',
name: 'Read/write permission',
},
{
field: 'tenantValue',
name: 'Dashboard',
render: (tenant: string) => {
if (tenant === RoleViewTenantInvalidText) {
return (
<>
<EuiText size="s">{RoleViewTenantInvalidText}</EuiText>
</>
);
}
return (
<>
<EuiLink data-test-subj="view-dashboard" onClick={() => viewDashboard(tenant)}>
View dashboard
</EuiLink>
</>
);
},
},