The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/admin/AdminListOrgsPage.tsx

56 lines
1.7 KiB

import React, { useEffect } from 'react';
import useAsyncFn from 'react-use/lib/useAsyncFn';
import { getBackendSrv } from '@grafana/runtime';
import { LinkButton } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
import { contextSrv } from 'app/core/services/context_srv';
import { AccessControlAction } from 'app/types';
import { AdminOrgsTable } from './AdminOrgsTable';
const deleteOrg = async (orgId: number) => {
return await getBackendSrv().delete('/api/orgs/' + orgId);
};
const getOrgs = async () => {
return await getBackendSrv().get('/api/orgs');
};
const getErrorMessage = (error: any) => {
return error?.data?.message || 'An unexpected error happened.';
};
export default function AdminListOrgsPages() {
const [state, fetchOrgs] = useAsyncFn(async () => await getOrgs(), []);
const canCreateOrg = contextSrv.hasPermission(AccessControlAction.OrgsCreate);
useEffect(() => {
fetchOrgs();
}, [fetchOrgs]);
return (
<Page navId="global-orgs" subTitle="Manage and create orgs across the whole Grafana server.">
<Page.Contents>
<>
<div className="page-action-bar">
<div className="page-action-bar__spacer" />
<LinkButton icon="plus" href="org/new" disabled={!canCreateOrg}>
New org
</LinkButton>
</div>
{state.error && getErrorMessage(state.error)}
{state.loading && 'Fetching organizations'}
{state.value && (
<AdminOrgsTable
orgs={state.value}
onDelete={(orgId) => {
deleteOrg(orgId).then(() => fetchOrgs());
}}
/>
)}
</>
</Page.Contents>
</Page>
);
}