2022-01-23 19:48:04 +00:00
|
|
|
import { CellProps, Column } from 'react-table';
|
|
|
|
import { MenuItem, MenuLink } from '@reach/menu-button';
|
|
|
|
import { useRouter, useSref } from '@uirouter/react';
|
|
|
|
|
|
|
|
import { Environment } from '@/portainer/environments/types';
|
2022-04-19 18:43:36 +00:00
|
|
|
import { snapshotEndpoint } from '@/portainer/environments/environment.service';
|
2022-01-23 19:48:04 +00:00
|
|
|
import * as notifications from '@/portainer/services/notifications';
|
|
|
|
import { getRoute } from '@/portainer/environments/utils';
|
|
|
|
|
2022-06-17 16:18:42 +00:00
|
|
|
import { ActionsMenu } from '@@/datatables/ActionsMenu';
|
|
|
|
|
2022-01-23 19:48:04 +00:00
|
|
|
export const actions: Column<Environment> = {
|
|
|
|
Header: 'Actions',
|
|
|
|
accessor: () => 'actions',
|
|
|
|
id: 'actions',
|
|
|
|
disableFilters: true,
|
|
|
|
canHide: true,
|
|
|
|
disableResizing: true,
|
|
|
|
width: '5px',
|
|
|
|
sortType: 'string',
|
|
|
|
Filter: () => null,
|
|
|
|
Cell: ActionsCell,
|
|
|
|
};
|
|
|
|
|
|
|
|
export function ActionsCell({
|
|
|
|
row: { original: environment },
|
|
|
|
}: CellProps<Environment>) {
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const environmentRoute = getRoute(environment);
|
|
|
|
const browseLinkProps = useSref(environmentRoute, {
|
|
|
|
id: environment.Id,
|
|
|
|
endpointId: environment.Id,
|
|
|
|
});
|
|
|
|
|
|
|
|
const showRefreshSnapshot = false; // remove and show MenuItem when feature is available
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ActionsMenu>
|
|
|
|
<MenuLink href={browseLinkProps.href} onClick={browseLinkProps.onClick}>
|
|
|
|
Browse
|
|
|
|
</MenuLink>
|
|
|
|
{showRefreshSnapshot && (
|
|
|
|
<MenuItem hidden onSelect={() => handleRefreshSnapshotClick()}>
|
|
|
|
Refresh Snapshot
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
</ActionsMenu>
|
|
|
|
);
|
|
|
|
|
|
|
|
async function handleRefreshSnapshotClick() {
|
|
|
|
try {
|
|
|
|
await snapshotEndpoint(environment.Id);
|
|
|
|
notifications.success('Success', 'Environment updated');
|
|
|
|
} catch (err) {
|
|
|
|
notifications.error(
|
|
|
|
'Failure',
|
|
|
|
err as Error,
|
|
|
|
'An error occurred during environment snapshot'
|
|
|
|
);
|
|
|
|
} finally {
|
|
|
|
await router.stateService.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|