Skip to content

Commit

Permalink
Merge branch 'activepieces:main' into apitraffic/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonfill authored Sep 16, 2024
2 parents 11c0e05 + 89dc8da commit d47fe9f
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 93 deletions.
27 changes: 21 additions & 6 deletions packages/react-ui/src/app/components/dashboard-container.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { t } from 'i18next';
import { AlertCircle, Link2, Logs, Workflow, Wrench } from 'lucide-react';
import { Navigate } from 'react-router-dom';

import { useEmbedding } from '@/components/embed-provider';
import { issueHooks } from '@/features/issues/hooks/issue-hooks';
import { flagsHooks } from '@/hooks/flags-hooks';
import { ApEdition, ApFlagId } from '@activepieces/shared';
import { platformHooks } from '@/hooks/platform-hooks';
import { isNil } from '@activepieces/shared';

import { authenticationSession } from '../../lib/authentication-session';

import { AllowOnlyLoggedInUserOnlyGuard } from './allow-logged-in-user-only-guard';
import { Sidebar, SidebarLink } from './sidebar';
Expand All @@ -14,11 +17,16 @@ type DashboardContainerProps = {
};

export function DashboardContainer({ children }: DashboardContainerProps) {
const { data: edition } = flagsHooks.useFlag<ApEdition>(ApFlagId.EDITION);
const { data: showIssuesNotification } =
issueHooks.useIssuesNotification(edition);
const { platform } = platformHooks.useCurrentPlatform();
const { data: showIssuesNotification } = issueHooks.useIssuesNotification(
platform.flowIssuesEnabled,
);

const { embedState } = useEmbedding();
const currentProjectId = authenticationSession.getProjectId();
if (isNil(currentProjectId) || currentProjectId === '') {
return <Navigate to="/sign-in" replace />;
}
const links: SidebarLink[] = [
{
to: '/flows',
Expand Down Expand Up @@ -51,7 +59,14 @@ export function DashboardContainer({ children }: DashboardContainerProps) {
icon: Wrench,
showInEmbed: false,
},
].filter((link) => !embedState.isEmbedded || link.showInEmbed);
]
.filter((link) => !embedState.isEmbedded || link.showInEmbed)
.map((link) => {
return {
...link,
to: `/projects/${currentProjectId}${link.to}`,
};
});

return (
<AllowOnlyLoggedInUserOnlyGuard>
Expand Down
25 changes: 20 additions & 5 deletions packages/react-ui/src/app/components/project-settings-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import {
SunMoon,
Users,
} from 'lucide-react';
import { Navigate } from 'react-router-dom';

import SidebarLayout from '@/app/components/sidebar-layout';
import SidebarLayout, { SidebarItem } from '@/app/components/sidebar-layout';
import { platformHooks } from '@/hooks/platform-hooks';
import { isNil } from '@activepieces/shared';

import { authenticationSession } from '../../lib/authentication-session';

const iconSize = 20;

Expand Down Expand Up @@ -49,15 +53,26 @@ const sidebarNavItems = [
interface SettingsLayoutProps {
children: React.ReactNode;
}

export default function ProjectSettingsLayout({
children,
}: SettingsLayoutProps) {
const { platform } = platformHooks.useCurrentPlatform();
const currentProjectId = authenticationSession.getProjectId();
if (isNil(currentProjectId)) {
return <Navigate to="/sign-in" replace />;
}

const filterAlerts = (item: SidebarItem) =>
platform.alertsEnabled || item.title !== t('Alerts');
const addProjectIdToHref = (item: SidebarItem) => ({
...item,
href: `/projects/${currentProjectId}${item.href}`,
});

// TODO enable alerts for communityh when it is ready
const filteredNavItems = platform.alertsEnabled
? sidebarNavItems
: sidebarNavItems.filter((item) => item.title !== t('Alerts'));
const filteredNavItems = sidebarNavItems
.filter(filterAlerts)
.map(addProjectIdToHref);

return (
<SidebarLayout title={t('Settings')} items={filteredNavItems}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui/src/app/components/sidebar-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface SidebarLayoutProps {
children: React.ReactNode;
}

type SidebarItem = {
export type SidebarItem = {
title: string;
href: string;
icon: JSX.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,33 @@ import {
ActivepiecesVendorRouteChanged,
} from 'ee-embed-sdk';

import { FlowsPage } from '../app/routes/flows';
import { AllowOnlyLoggedInUserOnlyGuard } from '../components/allow-logged-in-user-only-guard';
import { DashboardContainer } from '../components/dashboard-container';
import { PlatformAdminContainer } from '../components/platform-admin-container';
import NotFoundPage from '../routes/404-page';
import { ChangePasswordPage } from '../routes/change-password';
import AppConnectionsPage from '../routes/connections';
import { FlowsPage } from '../routes/flows';
import { FlowBuilderPage } from '../routes/flows/id';
import { ResetPasswordPage } from '../routes/forget-password';
import { FormPage } from '../routes/forms';
import IssuesPage from '../routes/issues';
import PlansPage from '../routes/plans';
import AuditLogsPage from '../routes/platform/audit-logs';
import ProjectsPage from '../routes/platform/projects';
import TemplatesPage from '../routes/platform/templates';
import UsersPage from '../routes/platform/users';
import { FlowRunPage } from '../routes/runs/id';
import AlertsPage from '../routes/settings/alerts';
import AppearancePage from '../routes/settings/appearance';
import GeneralPage from '../routes/settings/general';
import { GitSyncPage } from '../routes/settings/git-sync';
import TeamPage from '../routes/settings/team';
import { SignInPage } from '../routes/sign-in';
import { SignUpPage } from '../routes/sign-up';
import { ShareTemplatePage } from '../routes/templates/share-template';

import { AllowOnlyLoggedInUserOnlyGuard } from './components/allow-logged-in-user-only-guard';
import { DashboardContainer } from './components/dashboard-container';
import { PlatformAdminContainer } from './components/platform-admin-container';
import NotFoundPage from './routes/404-page';
import { ChangePasswordPage } from './routes/change-password';
import AppConnectionsPage from './routes/connections';
import { FlowBuilderPage } from './routes/flows/id';
import { ResetPasswordPage } from './routes/forget-password';
import { FormPage } from './routes/forms';
import IssuesPage from './routes/issues';
import PlansPage from './routes/plans';
import AuditLogsPage from './routes/platform/audit-logs';
import ProjectsPage from './routes/platform/projects';
import TemplatesPage from './routes/platform/templates';
import UsersPage from './routes/platform/users';
import { FlowRunPage } from './routes/runs/id';
import AlertsPage from './routes/settings/alerts';
import AppearancePage from './routes/settings/appearance';
import GeneralPage from './routes/settings/general';
import { GitSyncPage } from './routes/settings/git-sync';
import TeamPage from './routes/settings/team';
import { SignInPage } from './routes/sign-in';
import { SignUpPage } from './routes/sign-up';
import { ShareTemplatePage } from './routes/templates/share-template';
import { ProjectRouterWrapper } from './project-route-wrapper';

const SettingsRerouter = () => {
const { hash } = useLocation();
Expand All @@ -66,6 +67,7 @@ const SettingsRerouter = () => {
<Navigate to="/settings/general" replace />
);
};

const routes = [
{
path: '/embed',
Expand All @@ -76,7 +78,7 @@ const routes = [
path: '/switch-to-beta',
element: <SwitchToBetaPage />,
},
{
...ProjectRouterWrapper({
path: '/flows',
element: (
<DashboardContainer>
Expand All @@ -85,8 +87,8 @@ const routes = [
</PageTitle>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/flows/:flowId',
element: (
<AllowOnlyLoggedInUserOnlyGuard>
Expand All @@ -95,7 +97,7 @@ const routes = [
</PageTitle>
</AllowOnlyLoggedInUserOnlyGuard>
),
},
}),
{
path: '/forms/:flowId',
element: (
Expand All @@ -104,7 +106,7 @@ const routes = [
</PageTitle>
),
},
{
...ProjectRouterWrapper({
path: '/runs/:runId',
element: (
<AllowOnlyLoggedInUserOnlyGuard>
Expand All @@ -113,7 +115,7 @@ const routes = [
</PageTitle>
</AllowOnlyLoggedInUserOnlyGuard>
),
},
}),
{
path: '/templates/:templateId',
element: (
Expand All @@ -124,7 +126,7 @@ const routes = [
</AllowOnlyLoggedInUserOnlyGuard>
),
},
{
...ProjectRouterWrapper({
path: '/runs',
element: (
<DashboardContainer>
Expand All @@ -133,8 +135,8 @@ const routes = [
</PageTitle>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/issues',
element: (
<DashboardContainer>
Expand All @@ -143,8 +145,8 @@ const routes = [
</PageTitle>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/connections',
element: (
<DashboardContainer>
Expand All @@ -153,8 +155,8 @@ const routes = [
</PageTitle>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/plans',
element: (
<DashboardContainer>
Expand All @@ -163,15 +165,15 @@ const routes = [
</PageTitle>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/settings',
element: (
<DashboardContainer>
<SettingsRerouter></SettingsRerouter>
</DashboardContainer>
),
},
}),
{
path: '/forget-password',
element: (
Expand Down Expand Up @@ -212,7 +214,7 @@ const routes = [
</PageTitle>
),
},
{
...ProjectRouterWrapper({
path: '/settings/alerts',
element: (
<DashboardContainer>
Expand All @@ -223,8 +225,8 @@ const routes = [
</ProjectSettingsLayout>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/settings/appearance',
element: (
<DashboardContainer>
Expand All @@ -235,8 +237,8 @@ const routes = [
</ProjectSettingsLayout>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/settings/general',
element: (
<DashboardContainer>
Expand All @@ -247,8 +249,8 @@ const routes = [
</ProjectSettingsLayout>
</DashboardContainer>
),
},
{
}),
...ProjectRouterWrapper({
path: '/settings/pieces',
element: (
<DashboardContainer>
Expand All @@ -259,9 +261,8 @@ const routes = [
</ProjectSettingsLayout>
</DashboardContainer>
),
},

{
}),
...ProjectRouterWrapper({
path: '/settings/team',
element: (
<DashboardContainer>
Expand All @@ -272,12 +273,13 @@ const routes = [
</ProjectSettingsLayout>
</DashboardContainer>
),
},
}),
{
path: '/team',
element: <Navigate to="/settings/team" replace></Navigate>,
},
{

...ProjectRouterWrapper({
path: '/settings/git-sync',
element: (
<DashboardContainer>
Expand All @@ -288,7 +290,7 @@ const routes = [
</ProjectSettingsLayout>
</DashboardContainer>
),
},
}),

{
path: '/invitation',
Expand Down
Loading

0 comments on commit d47fe9f

Please sign in to comment.