Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jakcinmarina committed Oct 11, 2023
1 parent 185d601 commit 6d29fe1
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 34 deletions.
21 changes: 18 additions & 3 deletions frontend/src/components/explorer/explorer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { useEffect, useState } from "react";
import ReactFlow, { useEdgesState, useNodesState } from "reactflow";
import ReactFlow, {
Controls,
useEdgesState,
useNodesInitialized,
useNodesState,
useReactFlow,
} from "reactflow";
import "reactflow/dist/style.css";
import { CustomEdge } from "./components/customEdge";
import { ChildNode, ParentNode } from "./components/customNode";
Expand Down Expand Up @@ -29,6 +35,8 @@ const nodeTypes = {

const Explorer = ({ resourceList, closeResourceList }) => {
const navigate = useNavigate();
const reactFlowInstance = useReactFlow();
const nodesInitialized = useNodesInitialized();
const { id: resourceId } = useParams();
const { type: resourceType } = useParams();
const [nodes, setNodes] = useNodesState([]);
Expand All @@ -51,6 +59,12 @@ const Explorer = ({ resourceList, closeResourceList }) => {
}
}, [resourceId, resourceType]);

useEffect(() => {
if (nodesInitialized) {
reactFlowInstance.fitView();
}
}, [nodesInitialized]);

const openEntitlementsDetails = (entitlement) => {
setResourceDetailsOpen({
entitlementOpened: true,
Expand All @@ -60,7 +74,6 @@ const Explorer = ({ resourceList, closeResourceList }) => {

const openResourceDetails = async (resourceType: string, nodeId: string) => {
const resourceDetails = await fetchResourceDetails(resourceType, nodeId);
console.log("resource details", resourceDetails)
setResourceDetailsOpen({
resourceOpened: true,
resource: resourceDetails,
Expand Down Expand Up @@ -136,7 +149,9 @@ const Explorer = ({ resourceList, closeResourceList }) => {
}
fitView
attributionPosition="bottom-left"
/>
>
<Controls position="bottom-right" showInteractive={false} />
</ReactFlow>
</TreeWrapper>
)}
{resourceDetails.resource && (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/icons/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const ExplorerLogo = ({ color }) => {
);
};

export const Link = ({ color }) => {
export const LinkIcon = ({ color }) => {
return (
<SvgIcon color={color}>
<svg
Expand Down
20 changes: 7 additions & 13 deletions frontend/src/components/navigation/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@ import { Tooltip, useTheme } from "@mui/material";
import pluralize from "pluralize";
import { Logo, StyledDrawer, CloseButton } from "./styles";

interface ResourceTypesData {
resource_types: {
resource_type: {
id: string;
display_name: string;
traits?: number[];
};
}[];
}

export const Navigation = ({ openResourceList }) => {
const theme = useTheme();
const [data, setData] = useState<ResourceTypesData>();
const [data, setData] = useState([]);
useEffect(() => {
const fetchData = async () => {
const res = await (await fetch("/api/resourceTypes")).json();
setData(res.data);
const resourceTypes = res.data.resource_types
const sorted = resourceTypes.sort((a, b) =>
a.resource_type.display_name.localeCompare(b.resource_type.display_name)
);
setData(sorted);
};
fetchData();
}, []);
Expand All @@ -33,7 +27,7 @@ export const Navigation = ({ openResourceList }) => {
</Logo>
<List>
{data &&
data.resource_types.map((type) => (
data.map((type) => (
<Tooltip
key={type.resource_type.display_name}
title={pluralize(type.resource_type.display_name)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ListItem } from "..";
import { Label, Value } from "../styles";

const purposeMap = {
0: "PURPOSE_VALUE_UNSPECIFIED",
1: "PURPOSE_VALUE_ASSIGNMENT",
2: "PURPOSE_VALUE_PERMISSION",
0: "Unspecified",
1: "Assignment",
2: "Permission",
};

export const EntitlementDetails = ({
Expand Down
37 changes: 27 additions & 10 deletions frontend/src/components/resourceDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment } from "react";
import { Close, Link } from "../icons/icons";
import { Close, LinkIcon } from "../icons/icons";
import { useTheme } from "@mui/material/styles";
import { Button, Typography } from "@mui/material";
import {
Expand All @@ -11,6 +11,7 @@ import {
Value,
CloseButton,
ModalHeader,
StyledLink,
} from "./styles";
import { normalizeString } from "../../common/helpers";
import { EntitlementDetails } from "./components/entitlements";
Expand All @@ -29,14 +30,27 @@ export const ListItem = ({ label, value }) => {
);
};

export const ResourceDetailsModal = ({ resource, resourceDetails, closeDetails }) => {
export const ResourceDetailsModal = ({
resource,
resourceDetails,
closeDetails,
}) => {
const theme = useTheme();
const copyToClipboard = () => {
navigator.clipboard.writeText(`http://localhost:3000/${resource.resource_type.id}/${resource.resource.id.resource}`)
}

const handleClose = (event, reason) => {
if (reason && reason === "backdropClick") {
closeDetails();
}
};

return (
<ResourceDetailsDrawer theme={theme} variant="permanent" anchor="right">
<ResourceDetailsDrawer
theme={theme}
variant="temporary"
open={resourceDetails.resourceOpened || resourceDetails.entitlementOpened}
anchor="right"
ModalProps={{ onClose: handleClose }}
>
<ModalHeader>
<StyledDiv>
<Typography variant="h5">
Expand All @@ -50,19 +64,22 @@ export const ResourceDetailsModal = ({ resource, resourceDetails, closeDetails }
<Button
variant="text"
color="secondary"
startIcon={<Link color="secondary" />}
startIcon={<LinkIcon color="secondary" />}
disableElevation
onClick={copyToClipboard}
>
Copy Link
<StyledLink
to={`http://localhost:3000/${resource.resource_type.id}/${resource.resource.id.resource}`}
>
focus
</StyledLink>
</Button>
)}
</ModalHeader>
<Details>
{resourceDetails.entitlementOpened && (
<EntitlementDetails entitlement={resource} />
)}
{ resourceDetails.resourceOpened && (
{resourceDetails.resourceOpened && (
<ResourceDetails resource={resource.resource} />
)}
</Details>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/resourceDetails/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { styled } from "@mui/material/styles";
import MuiDrawer from "@mui/material/Drawer";
import { IconButton, Typography } from "@mui/material";
import { Link } from "react-router-dom";

export const ResourceDetailsDrawer = styled(MuiDrawer)(({ theme }) => ({
"& .MuiDrawer-paper": {
Expand Down Expand Up @@ -55,3 +56,8 @@ export const CloseButton = styled(IconButton)(() => ({
border: "1px solid #D0D5DD",
borderRadius: "8px"
}));

export const StyledLink = styled(Link)(() => ({
textDecoration: 'none',
color: 'inherit'
}));
1 change: 1 addition & 0 deletions frontend/src/context/resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const ResourcesContextProvider = ({ children }) => {
}

map[type].push(resource);
map[type].sort((a, b) => a.resource.display_name.localeCompare(b.resource.display_name))
});

setResources({
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/pages/homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Footer from "../components/footer/footer";
import "../components/explorer/index.css";
import { Navigation } from "../components/navigation/navigation";
import Explorer from "../components/explorer/explorer";
import { ReactFlowProvider } from "reactflow";

type ResourcesListState = {
opened: boolean;
Expand Down Expand Up @@ -30,10 +31,12 @@ const Homepage = () => {
return (
<>
<Navigation openResourceList={openResourceList} />
<Explorer
resourceList={resourceList}
closeResourceList={closeResourceList}
/>
<ReactFlowProvider>
<Explorer
resourceList={resourceList}
closeResourceList={closeResourceList}
/>
</ReactFlowProvider>
<Footer />
</>
);
Expand Down

0 comments on commit 6d29fe1

Please sign in to comment.