forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Angular/Forms migration: Orgs list (grafana#23821)
* Create new components * Fix async issues * Remove comments * Update public/app/features/admin/AdminOrgsTable.tsx * Update public/app/features/admin/AdminListOrgsPage.tsx * Update public/app/features/admin/AdminListOrgsPage.tsx * Remove angular code Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
- Loading branch information
Showing
6 changed files
with
116 additions
and
81 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { FC, useEffect } from 'react'; | ||
import { getNavModel } from 'app/core/selectors/navModel'; | ||
import Page from 'app/core/components/Page/Page'; | ||
import { useSelector } from 'react-redux'; | ||
import { StoreState } from 'app/types/store'; | ||
import { LinkButton } from '@grafana/ui'; | ||
import { getBackendSrv } from '@grafana/runtime'; | ||
import { AdminOrgsTable } from './AdminOrgsTable'; | ||
import useAsyncFn from 'react-use/lib/useAsyncFn'; | ||
|
||
const deleteOrg = async (orgId: number) => { | ||
return await getBackendSrv().delete('/api/orgs/' + orgId); | ||
}; | ||
|
||
const getOrgs = async () => { | ||
return await getBackendSrv().get('/api/orgs'); | ||
}; | ||
|
||
export const AdminListOrgsPages: FC = () => { | ||
const navIndex = useSelector((state: StoreState) => state.navIndex); | ||
const navModel = getNavModel(navIndex, 'global-orgs'); | ||
const [state, fetchOrgs] = useAsyncFn(async () => await getOrgs(), []); | ||
useEffect(() => { | ||
fetchOrgs(); | ||
}, []); | ||
|
||
return ( | ||
<Page navModel={navModel}> | ||
<Page.Contents> | ||
<> | ||
<div className="page-action-bar"> | ||
<div className="page-action-bar__spacer"></div> | ||
<LinkButton icon="plus" href="org/new"> | ||
New org | ||
</LinkButton> | ||
</div> | ||
{state.loading && 'Fetching organizations'} | ||
{state.error} | ||
{state.value && ( | ||
<AdminOrgsTable | ||
orgs={state.value} | ||
onDelete={orgId => { | ||
deleteOrg(orgId); | ||
fetchOrgs(); | ||
}} | ||
/> | ||
)} | ||
</> | ||
</Page.Contents> | ||
</Page> | ||
); | ||
}; | ||
|
||
export default AdminListOrgsPages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { FC, useState } from 'react'; | ||
import { Organization } from 'app/types'; | ||
import { Button, ConfirmModal } from '@grafana/ui'; | ||
|
||
interface Props { | ||
orgs: Organization[]; | ||
onDelete: (orgId: number) => void; | ||
} | ||
|
||
export const AdminOrgsTable: FC<Props> = ({ orgs, onDelete }) => { | ||
const [deleteOrg, setDeleteOrg] = useState<Organization>(); | ||
return ( | ||
<table className="filter-table form-inline filter-table--hover"> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Name</th> | ||
<th style={{ width: '1%' }}></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{orgs.map(org => ( | ||
<tr key={`${org.id}-${org.name}`}> | ||
<td className="link-td"> | ||
<a href={`admin/orgs/edit/${org.id}`}>{org.id}</a> | ||
</td> | ||
<td className="link-td"> | ||
<a href={`admin/orgs/edit/${org.id}`}>{org.name}</a> | ||
</td> | ||
<td className="text-right"> | ||
<Button variant="destructive" size="sm" icon="times" onClick={() => setDeleteOrg(org)} /> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
{deleteOrg && ( | ||
<ConfirmModal | ||
isOpen | ||
icon="trash-alt" | ||
title="Delete" | ||
body={ | ||
<div> | ||
Are you sure you want to delete `${deleteOrg.name}`? | ||
<br /> <small>All dashboards for this organization will be removed!</small> | ||
</div> | ||
} | ||
confirmText="Delete" | ||
onDismiss={() => setDeleteOrg(null)} | ||
onConfirm={() => { | ||
onDelete(deleteOrg.id); | ||
setDeleteOrg(null); | ||
}} | ||
/> | ||
)} | ||
</table> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters