-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(permissions) show a warning modal for users with lower permissio…
…ns that can't read events Signed-off-by: David Edler <[email protected]>
- Loading branch information
Showing
7 changed files
with
152 additions
and
59 deletions.
There are no files selected for viewing
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 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 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 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 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,70 @@ | ||
import { Button, Icon, Modal, usePortal } from "@canonical/react-components"; | ||
import { useCurrentProject } from "context/useCurrentProject"; | ||
import { useProjectEntitlements } from "util/entitlements/projects"; | ||
import { useEffect } from "react"; | ||
import { useSettings } from "context/useSettings"; | ||
|
||
const ProjectPermissionWarning = () => { | ||
const { isLoading: isSettingsLoading } = useSettings(); | ||
const { project, isLoading: isProjectLoading } = useCurrentProject(); | ||
const { canViewEvents } = useProjectEntitlements(); | ||
const { openPortal, closePortal, isOpen, Portal } = usePortal({ | ||
programmaticallyOpen: true, | ||
}); | ||
|
||
const hasWarning = | ||
!isProjectLoading && !isSettingsLoading && !canViewEvents(project); | ||
|
||
useEffect(() => { | ||
if (hasWarning) { | ||
openPortal(); | ||
} | ||
}, [hasWarning]); | ||
|
||
if (!hasWarning) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div> | ||
<Button | ||
onClick={() => { | ||
openPortal(); | ||
}} | ||
appearance="base" | ||
className="u-no-margin--bottom" | ||
> | ||
<Icon name="warning" className="is-light" /> | ||
</Button> | ||
{isOpen && ( | ||
<Portal> | ||
<Modal title="Missing viewer permission" close={closePortal}> | ||
<p> | ||
You do not have the <code>viewer</code> permission for the | ||
selected project. | ||
</p> | ||
<p> | ||
Changes made in the UI will not be visible without manual reload | ||
of the page. | ||
</p> | ||
<p> | ||
Your UI experience is limited because of that. Contact your | ||
administrator to add the necessary permissions for your user. | ||
</p> | ||
<footer className="p-modal__footer" id="modal-footer"> | ||
<Button | ||
appearance="positive" | ||
className="u-no-margin--bottom" | ||
onClick={closePortal} | ||
> | ||
Accept | ||
</Button> | ||
</footer> | ||
</Modal> | ||
</Portal> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProjectPermissionWarning; |
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 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