Skip to content

Commit

Permalink
Sync changes with netbird cloud (#407)
Browse files Browse the repository at this point in the history
* Update axa oidc library and package.json

* Update ACL port state to show correct value

* Filter user groups by unique groups only

* Add peer multiselect, optimize dropdown performance for peer selection, remove 'all' group from some dropdowns, various ui / ux optimizations

* Add peer multiselect, optimize dropdown performance for peer selection, remove 'all' group from some dropdowns, various ui / ux optimizations
  • Loading branch information
heisbrot authored Aug 13, 2024
1 parent 650496f commit d34ae9b
Show file tree
Hide file tree
Showing 51 changed files with 2,236 additions and 748 deletions.
526 changes: 435 additions & 91 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"cypress:open": "cypress open"
},
"dependencies": {
"@axa-fr/react-oidc": "^5.14.0",
"@axa-fr/react-oidc": "^7.22.18",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-collapsible": "^1.0.3",
Expand All @@ -22,8 +22,9 @@
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-scroll-area": "^1.1.0",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
Expand All @@ -37,6 +38,7 @@
"@types/node": "20.10.6",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/react-window": "^1.8.8",
"autoprefixer": "^10",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
Expand Down Expand Up @@ -67,6 +69,7 @@
"react-jwt": "^1.2.0",
"react-loading-skeleton": "^3.3.1",
"react-responsive": "^9.0.2",
"react-virtuoso": "^4.9.0",
"swr": "^2.2.4",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
Expand Down
1 change: 1 addition & 0 deletions src/app/(dashboard)/peer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ function PeerOverview() {
disabled={isUser}
onChange={setSelectedGroups}
values={selectedGroups}
hideAllGroup={true}
peer={peer}
/>
</FullTooltip>
Expand Down
31 changes: 16 additions & 15 deletions src/app/(dashboard)/peers/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import Breadcrumbs from "@components/Breadcrumbs";
import InlineLink from "@components/InlineLink";
import Paragraph from "@components/Paragraph";
import SkeletonTable from "@components/skeletons/SkeletonTable";
import useFetchApi from "@utils/api";
import { usePortalElement } from "@hooks/usePortalElement";
import { ExternalLinkIcon } from "lucide-react";
import React, { lazy, Suspense, useEffect } from "react";
import React, { lazy, Suspense } from "react";
import PeerIcon from "@/assets/icons/PeerIcon";
import { useGroups } from "@/contexts/GroupsProvider";
import PeersProvider, { usePeers } from "@/contexts/PeersProvider";
import { useLoggedInUser, useUsers } from "@/contexts/UsersProvider";
import { Peer } from "@/interfaces/Peer";
import PageContainer from "@/layouts/PageContainer";
import { SetupModalContent } from "@/modules/setup-netbird-modal/SetupModal";

Expand All @@ -21,24 +20,22 @@ export default function Peers() {

return (
<PageContainer>
{permission?.dashboard_view === "blocked" ? (
{permission.dashboard_view === "blocked" ? (
<PeersBlockedView />
) : (
<PeersView />
<PeersProvider>
<PeersView />
</PeersProvider>
)}
</PageContainer>
);
}

function PeersView() {
const { data: peers, isLoading } = useFetchApi<Peer[]>("/peers");
const { peers, isLoading } = usePeers();
const { users } = useUsers();
const { refresh } = useGroups();

useEffect(() => {
refresh();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const { ref: headingRef, portalTarget } =
usePortalElement<HTMLHeadingElement>();

const peersWithUser = peers?.map((peer) => {
if (!users) return peer;
Expand All @@ -58,7 +55,7 @@ function PeersView() {
icon={<PeerIcon size={13} />}
/>
</Breadcrumbs>
<h1>{peers && peers.length > 1 ? `${peers.length} Peers` : "Peers"}</h1>
<h1 ref={headingRef}>Peers</h1>
<Paragraph>
A list of all machines and devices connected to your private network.
Use this view to manage peers.
Expand All @@ -76,7 +73,11 @@ function PeersView() {
</Paragraph>
</div>
<Suspense fallback={<SkeletonTable />}>
<PeersTable isLoading={isLoading} peers={peersWithUser} />
<PeersTable
isLoading={isLoading}
peers={peersWithUser}
headingTarget={portalTarget}
/>
</Suspense>
</>
);
Expand Down
26 changes: 16 additions & 10 deletions src/app/(dashboard)/team/user/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function UserOverview({ user }: Props) {
)}
</div>

<div className={"flex gap-10 w-full mt-8 max-w-6xl"}>
<div className={"flex gap-10 w-full mt-8 max-w-6xl items-start"}>
<UserInformationCard user={user} />
<div className={"flex flex-col gap-8 w-1/2 "}>
{!user.is_service_user && (
Expand All @@ -200,6 +200,7 @@ function UserOverview({ user }: Props) {
disabled={isUser}
onChange={setSelectedGroups}
values={selectedGroups}
hideAllGroup={true}
/>
</div>
)}
Expand All @@ -214,6 +215,8 @@ function UserOverview({ user }: Props) {
<UserRoleSelector
value={role}
onChange={setRole}
hideOwner={user.is_service_user}
currentUser={user}
disabled={
isLoggedInUser ||
!isOwnerOrAdmin ||
Expand Down Expand Up @@ -301,15 +304,18 @@ function UserInformationCard({ user }: { user: User }) {

{!isServiceUser && (
<>
<Card.ListItem
label={
<>
<Ban size={16} />
Block User
</>
}
value={<UserBlockCell user={user} isUserPage={true} />}
/>
{!user.is_current && user.role != Role.Owner && (
<Card.ListItem
label={
<>
<Ban size={16} />
Block User
</>
}
value={<UserBlockCell user={user} isUserPage={true} />}
/>
)}

<Card.ListItem
label={
<>
Expand Down
5 changes: 5 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ p {

.stepper-bg-variant .step-circle {
@apply !border-[#1d2024];
}

.webkit-scroll{
-webkit-overflow-scrolling: touch;
-webkit-transform: translate3d(0, 0, 0);
}
Binary file added src/assets/os-icons/FreeBSD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/auth/OIDCProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use client";

import { OidcProvider } from "@axa-fr/react-oidc";
import {
AuthorityConfiguration,
OidcConfiguration,
} from "@axa-fr/react-oidc/dist/vanilla/oidc";
OidcProvider,
} from "@axa-fr/react-oidc";
import FullScreenLoading from "@components/ui/FullScreenLoading";
import { useLocalStorage } from "@hooks/useLocalStorage";
import { useRedirect } from "@hooks/useRedirect";
Expand All @@ -30,7 +30,7 @@ const auth0AuthorityConfig: AuthorityConfiguration = {
revocation_endpoint: new URL("oauth/revoke", config.authority).href,
end_session_endpoint: new URL("v2/logout", config.authority).href,
userinfo_endpoint: new URL("userinfo", config.authority).href,
//issuer: new URL("", config.authority).href,
issuer: new URL("", config.authority).href,
};

const onEvent = (configurationName: any, eventName: any, data: any) => {
Expand Down
10 changes: 9 additions & 1 deletion src/auth/SecureProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ export const SecureProvider = ({ children }: Props) => {
const currentPath = usePathname();

useEffect(() => {
let timeout: NodeJS.Timeout | undefined = undefined;
if (!isAuthenticated) {
login(currentPath);
timeout = setTimeout(async () => {
if (!isAuthenticated) {
await login(currentPath);
}
}, 1500);
}
return () => {
clearTimeout(timeout);
};
}, [currentPath, isAuthenticated, login]);

return (
Expand Down
11 changes: 11 additions & 0 deletions src/components/DropdownInfoText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from "react";

type Props = {
children: React.ReactNode;
};

export const DropdownInfoText = ({ children }: Props) => {
return (
<div className={"text-center pt-2 mb-6 text-nb-gray-400"}>{children}</div>
);
};
48 changes: 48 additions & 0 deletions src/components/DropdownInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { IconArrowBack } from "@tabler/icons-react";
import { cn } from "@utils/helpers";
import { SearchIcon } from "lucide-react";
import * as React from "react";
import { forwardRef } from "react";

type Props = {
value: string;
onChange: (value: string) => void;
placeholder?: string;
};

export const DropdownInput = forwardRef<HTMLInputElement, Props>(
({ value, onChange, placeholder = "Search..." }, ref) => {
return (
<div className={"relative w-full"}>
<input
ref={ref}
className={cn(
"min-h-[42px] w-full relative",
"border-b-0 border-t-0 border-r-0 border-l-0 border-neutral-200 dark:border-nb-gray-700 items-center",
"bg-transparent text-sm outline-none focus-visible:outline-none ring-0 focus-visible:ring-0",
"dark:placeholder:text-nb-gray-400 font-light placeholder:text-neutral-500 pl-10",
)}
value={value}
onChange={(e) => onChange(e.target.value)}
placeholder={placeholder}
/>
<div className={"absolute left-0 top-0 h-full flex items-center pl-4"}>
<div className={"flex items-center"}>
<SearchIcon size={14} />
</div>
</div>
<div className={"absolute right-0 top-0 h-full flex items-center pr-4"}>
<div
className={
"flex items-center bg-nb-gray-800 py-1 px-1.5 rounded-[4px] border border-nb-gray-500"
}
>
<IconArrowBack size={10} />
</div>
</div>
</div>
);
},
);

DropdownInput.displayName = "DropdownInput";
17 changes: 13 additions & 4 deletions src/components/NetworkRouteSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommandItem } from "@components/Command";
import FullTooltip from "@components/FullTooltip";
import { Popover, PopoverContent, PopoverTrigger } from "@components/Popover";
import TextWithTooltip from "@components/ui/TextWithTooltip";
import { IconArrowBack } from "@tabler/icons-react";
import useFetchApi from "@utils/api";
import { cn } from "@utils/helpers";
Expand Down Expand Up @@ -108,12 +109,12 @@ export function NetworkRouteSelector({
{value ? (
<div
className={
"flex items-center justify-between text-sm text-white w-full pr-4 pl-1"
"flex items-center justify-between text-sm text-white w-full pr-4 pl-1 gap-2"
}
>
<div className={"flex items-center gap-2.5 text-sm"}>
<NetworkRoutesIcon size={16} />
{value.network_id}
<TextWithTooltip text={value.network_id} maxChars={15} />
</div>

<div
Expand Down Expand Up @@ -224,10 +225,14 @@ export function NetworkRouteSelector({
togglePeer(option);
setOpen(false);
}}
className={"gap-2"}
>
<div className={"flex items-center gap-2.5 text-sm"}>
<NetworkRoutesIcon size={14} />
{option.network_id}
<TextWithTooltip
text={option.network_id}
maxChars={15}
/>
</div>

<div
Expand Down Expand Up @@ -259,7 +264,11 @@ function DomainList({ domains }: { domains?: string[] }) {
<FullTooltip
content={<div className={"text-xs max-w-sm"}>{domains.join(", ")}</div>}
>
<div className={"text-xs text-nb-gray-300"}>
<div
className={
"text-xs text-nb-gray-300 block min-w-0 truncate max-w-[180px]"
}
>
{firstDomain} {domains.length > 1 && "+" + (domains.length - 1)}
</div>
</FullTooltip>
Expand Down
Loading

0 comments on commit d34ae9b

Please sign in to comment.