ClusterTableActionsCell.tsx 977 B

123456789101112131415161718192021222324252627282930313233
  1. import React, { useMemo } from 'react';
  2. import { Cluster, ResourceType } from 'generated-sources';
  3. import { CellContext } from '@tanstack/react-table';
  4. import { clusterConfigPath } from 'lib/paths';
  5. import { useGetUserInfo } from 'lib/hooks/api/roles';
  6. import { ActionCanButton } from 'components/common/ActionComponent';
  7. type Props = CellContext<Cluster, unknown>;
  8. const ClusterTableActionsCell: React.FC<Props> = ({ row }) => {
  9. const { name } = row.original;
  10. const { data } = useGetUserInfo();
  11. const hasPermissions = useMemo(() => {
  12. if (!data?.rbacEnabled) return true;
  13. return !!data?.userInfo?.permissions.some(
  14. (permission) => permission.resource === ResourceType.APPLICATIONCONFIG
  15. );
  16. }, [data]);
  17. return (
  18. <ActionCanButton
  19. buttonType="secondary"
  20. buttonSize="S"
  21. to={clusterConfigPath(name)}
  22. canDoAction={hasPermissions}
  23. >
  24. Configure
  25. </ActionCanButton>
  26. );
  27. };
  28. export default ClusterTableActionsCell;