AccessControlFolderPermissions.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React, { useEffect } from 'react';
  2. import { connect, ConnectedProps } from 'react-redux';
  3. import { Permissions } from 'app/core/components/AccessControl';
  4. import Page from 'app/core/components/Page/Page';
  5. import { contextSrv } from 'app/core/core';
  6. import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
  7. import { getNavModel } from 'app/core/selectors/navModel';
  8. import { AccessControlAction, StoreState } from 'app/types';
  9. import { getFolderByUid } from './state/actions';
  10. import { getLoadingNav } from './state/navModel';
  11. interface RouteProps extends GrafanaRouteComponentProps<{ uid: string }> {}
  12. function mapStateToProps(state: StoreState, props: RouteProps) {
  13. const uid = props.match.params.uid;
  14. return {
  15. uid: uid,
  16. navModel: getNavModel(state.navIndex, `folder-permissions-${uid}`, getLoadingNav(1)),
  17. };
  18. }
  19. const mapDispatchToProps = {
  20. getFolderByUid,
  21. };
  22. const connector = connect(mapStateToProps, mapDispatchToProps);
  23. export type Props = ConnectedProps<typeof connector>;
  24. export const AccessControlFolderPermissions = ({ uid, getFolderByUid, navModel }: Props) => {
  25. useEffect(() => {
  26. getFolderByUid(uid);
  27. }, [getFolderByUid, uid]);
  28. const canSetPermissions = contextSrv.hasPermission(AccessControlAction.FoldersPermissionsWrite);
  29. return (
  30. <Page navModel={navModel}>
  31. <Page.Contents>
  32. <Permissions resource="folders" resourceId={uid} canSetPermissions={canSetPermissions} />
  33. </Page.Contents>
  34. </Page>
  35. );
  36. };
  37. export default connector(AccessControlFolderPermissions);