import React from 'react';
import { Icon, LegacyForms } from '@grafana/ui';
import { dataSourceAclLevels, DataSourcePermissionLevel } from 'app/types/acl';
import { DataSourcePermission } from '../types';
const { Select } = LegacyForms;
export interface Props {
items: DataSourcePermission[];
onRemoveItem: (item: DataSourcePermission) => void;
}
const adminRole: DataSourcePermission = {
id: -1,
datasourceId: -1,
updated: '',
created: '',
permissionName: 'Admin',
builtInRole: 'Admin',
permission: DataSourcePermissionLevel.Admin,
};
const adminLevel = {
label: 'Admin',
description: '',
value: DataSourcePermissionLevel.Admin,
};
export const DataSourcePermissionsList = ({ items, onRemoveItem }: Props) => {
const users = items.filter((i) => i.userId !== undefined);
const teams = items.filter((i) => i.teamId !== undefined);
const builtIns = [adminRole];
return (
);
};
interface PermissionTableProps {
title: string;
items: DataSourcePermission[];
onRemove: (item: DataSourcePermission) => void;
}
const PermissionTable = ({ title, items, onRemove }: PermissionTableProps) => {
if (items.length === 0) {
return null;
}
return (
{title}
{items.map((item, index) => (
))}
);
};
interface TableRowProps {
item: DataSourcePermission;
onRemove: (item: DataSourcePermission) => void;
}
const TableRow = ({ item, onRemove }: TableRowProps) => {
const renderAvatar = () => {
if (item.teamId) {
return ;
} else if (item.userId) {
return ;
}
return ;
};
const renderDescription = () => {
if (item.userId) {
return {item.userLogin} ;
} else if (item.teamId) {
return {item.team} ;
} else if (item.builtInRole) {
return {item.builtInRole} ;
}
return ;
};
const levels = [...dataSourceAclLevels, adminLevel];
return (
{renderAvatar()} |
{renderDescription()} |
|
Can |
|
{item.builtInRole ? (
) : (
)}
|
);
};