App directory refactoring
This commit is contained in:
parent
a53a26f4c0
commit
b312a8c862
153 changed files with 1532 additions and 1447 deletions
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, PropsWithChildren } from "react";
|
||||
import { Box } from "@mui/material";
|
||||
import { useAppContext } from "./AppProvider";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import Image from "next/legacy/image";
|
||||
import { Grid, Box, GridSize } from "@mui/material";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import Image from "next/legacy/image";
|
||||
import { signOut } from "next-auth/react";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import {
|
||||
FC,
|
||||
createContext,
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import Link from "next/link";
|
||||
import { Button as MUIButton } from "@mui/material";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Container, Grid, Box, Button } from "@mui/material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { Dialog, Box, Grid, Checkbox, IconButton } from "@mui/material";
|
||||
import { Close as CloseIcon } from "@mui/icons-material";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { Button } from "@mui/material";
|
||||
|
|
@ -1,30 +1,23 @@
|
|||
import { useEffect } from "react";
|
||||
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||
"use client";
|
||||
|
||||
import { useEffect, FC } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { getSession } from "next-auth/react";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import { Grid, Button } from "@mui/material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { Layout } from "components/Layout";
|
||||
import { getUserVisualizations } from "lib/opensearch";
|
||||
import { Welcome } from "components/Welcome";
|
||||
import { WelcomeDialog } from "components/WelcomeDialog";
|
||||
import { VisualizationCard } from "components/VisualizationCard";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { getEmbedded } from "lib/utils";
|
||||
import { Welcome } from "@/app/_components/Welcome";
|
||||
import { WelcomeDialog } from "@/app/_components/WelcomeDialog";
|
||||
import { VisualizationCard } from "@/app/_components/VisualizationCard";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
|
||||
type MyVisualizationsProps = {
|
||||
type HomeProps = {
|
||||
visualizations: any;
|
||||
embedded: boolean;
|
||||
};
|
||||
|
||||
const MyVisualizations: NextPage<MyVisualizationsProps> = ({
|
||||
visualizations,
|
||||
embedded,
|
||||
}) => {
|
||||
export const Home: FC<HomeProps> = ({ visualizations, embedded }) => {
|
||||
const router = useRouter();
|
||||
const cookieName = "homeIntroComplete";
|
||||
const [cookies, setCookie] = useCookies([cookieName]);
|
||||
|
|
@ -43,10 +36,7 @@ const MyVisualizations: NextPage<MyVisualizationsProps> = ({
|
|||
}, [homeIntroComplete, router, setCookie]);
|
||||
|
||||
return (
|
||||
<Layout embedded={embedded}>
|
||||
<Head>
|
||||
<title>Digital Threat Dashboard – Leafcutter</title>
|
||||
</Head>
|
||||
<>
|
||||
<Welcome />
|
||||
<Grid
|
||||
container
|
||||
|
|
@ -105,19 +95,6 @@ const MyVisualizations: NextPage<MyVisualizationsProps> = ({
|
|||
))}
|
||||
</Grid>
|
||||
<WelcomeDialog />
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default MyVisualizations;
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (
|
||||
context: GetServerSidePropsContext
|
||||
) => {
|
||||
const session = (await getSession(context)) ?? null;
|
||||
const visualizations = await getUserVisualizations(
|
||||
session?.user?.email ?? "none",
|
||||
20
|
||||
);
|
||||
return { props: { visualizations, embedded: getEmbedded(context) } };
|
||||
};
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, PropsWithChildren } from "react";
|
||||
import getConfig from "next/config";
|
||||
import { Grid, Container } from "@mui/material";
|
||||
|
|
@ -13,7 +15,7 @@ type LayoutProps = PropsWithChildren<{
|
|||
embedded?: boolean;
|
||||
}>;
|
||||
|
||||
export const Layout: FC<LayoutProps> = ({
|
||||
export const InternalLayout: FC<LayoutProps> = ({
|
||||
embedded = false,
|
||||
children,
|
||||
}: any) => {
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { useRouter } from "next/router";
|
||||
import { IconButton, Menu, MenuItem, Box } from "@mui/material";
|
||||
import { KeyboardArrowDown as KeyboardArrowDownIcon } from "@mui/icons-material";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useEffect, useState } from "react";
|
||||
import { useAppContext } from "./AppProvider";
|
||||
import { RawDataViewer } from "./RawDataViewer";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { Card, Grid } from "@mui/material";
|
||||
import {
|
||||
47
apps/leafcutter/app/_components/MultiProvider.tsx
Normal file
47
apps/leafcutter/app/_components/MultiProvider.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* eslint-disable react/jsx-props-no-spreading */
|
||||
import { FC, PropsWithChildren } from "react";
|
||||
import { SessionProvider } from "next-auth/react";
|
||||
import { CssBaseline } from "@mui/material";
|
||||
import { CookiesProvider } from "react-cookie";
|
||||
import { I18n } from "react-polyglot";
|
||||
import { AdapterDateFns } from "@mui/x-date-pickers-pro/AdapterDateFns";
|
||||
("use client");
|
||||
|
||||
import { LocalizationProvider } from "@mui/x-date-pickers-pro";
|
||||
import { AppProvider } from "@/app/_components/AppProvider";
|
||||
import { NextAppDirEmotionCacheProvider } from "tss-react/next/appDir";
|
||||
import en from "locales/en.json";
|
||||
import fr from "locales/fr.json";
|
||||
import "@fontsource/poppins/400.css";
|
||||
import "@fontsource/poppins/700.css";
|
||||
import "@fontsource/roboto/400.css";
|
||||
import "@fontsource/roboto/700.css";
|
||||
import "@fontsource/playfair-display/900.css";
|
||||
import "styles/global.css";
|
||||
import { LicenseInfo } from "@mui/x-data-grid-pro";
|
||||
|
||||
LicenseInfo.setLicenseKey(process.env.MUI_LICENSE_KEY ?? "");
|
||||
|
||||
const messages: any = { en, fr };
|
||||
|
||||
export const MultiProvider: FC<PropsWithChildren> = ({ children }: any) => {
|
||||
// const { locale = "en" } = useRouter();
|
||||
const locale = "en";
|
||||
|
||||
return (
|
||||
<NextAppDirEmotionCacheProvider options={{ key: "css" }}>
|
||||
<SessionProvider>
|
||||
<CookiesProvider>
|
||||
<CssBaseline />
|
||||
<AppProvider>
|
||||
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
||||
<I18n locale={locale} messages={messages[locale]}>
|
||||
{children}
|
||||
</I18n>
|
||||
</LocalizationProvider>
|
||||
</AppProvider>
|
||||
</CookiesProvider>
|
||||
</SessionProvider>
|
||||
</NextAppDirEmotionCacheProvider>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import Iframe from "react-iframe";
|
||||
import { Box } from "@mui/material";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
/* eslint-disable react/require-default-props */
|
||||
import { FC, PropsWithChildren } from "react";
|
||||
import { Box } from "@mui/material";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import {
|
||||
Box,
|
||||
|
|
@ -15,14 +17,14 @@ import {
|
|||
Group as GroupIcon,
|
||||
} from "@mui/icons-material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import taxonomy from "config/taxonomy.json";
|
||||
import taxonomy from "app/_config/taxonomy.json";
|
||||
import { QueryBuilderSection } from "./QueryBuilderSection";
|
||||
import { QueryListSelector } from "./QueryListSelector";
|
||||
import { QueryDateRangeSelector } from "./QueryDateRangeSelector";
|
||||
import { useAppContext } from "./AppProvider";
|
||||
import { Tooltip } from "./Tooltip";
|
||||
|
||||
interface QueryBuilderProps { }
|
||||
interface QueryBuilderProps {}
|
||||
|
||||
export const QueryBuilder: FC<QueryBuilderProps> = () => {
|
||||
const t = useTranslate();
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, PropsWithChildren, useState } from "react";
|
||||
import {
|
||||
Box,
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState, useEffect } from "react";
|
||||
import { Box, Grid, TextField, Select, MenuItem } from "@mui/material";
|
||||
import { DatePicker } from "@mui/x-date-pickers-pro";
|
||||
|
|
@ -90,7 +92,7 @@ export const QueryDateRangeSelector: FC<QueryDateRangeSelectorProps> = () => {
|
|||
endDate: { values: [date] },
|
||||
});
|
||||
}}
|
||||
// @ts-ignore
|
||||
// @ts-ignore
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState, useEffect } from "react";
|
||||
import { Box, Grid, Tooltip } from "@mui/material";
|
||||
import { DataGridPro, GridColDef } from "@mui/x-data-grid-pro";
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState, useEffect } from "react";
|
||||
import { Box, Grid } from "@mui/material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import taxonomy from "config/taxonomy.json";
|
||||
import taxonomy from "app/_config/taxonomy.json";
|
||||
import { colors } from "styles/theme";
|
||||
import { useAppContext } from "./AppProvider";
|
||||
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import {
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Box, Grid } from "@mui/material";
|
||||
import { DataGridPro } from "@mui/x-data-grid-pro";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import DashboardMenuIcon from "images/dashboard-menu.png";
|
||||
import AboutMenuIcon from "images/about-menu.png";
|
||||
|
|
@ -18,8 +20,8 @@ import {
|
|||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { Tooltip } from "components/Tooltip";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
import { Tooltip } from "@/app/_components/Tooltip";
|
||||
// import { ArrowCircleRight as ArrowCircleRightIcon } from "@mui/icons-material";
|
||||
|
||||
const MenuItem = ({
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
/* eslint-disable react/require-default-props */
|
||||
import { FC } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import Link from "next/link";
|
||||
import Image from "next/legacy/image";
|
||||
import { AppBar, Grid, Box } from "@mui/material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import LeafcutterLogo from "images/leafcutter-logo.png";
|
||||
import { AccountButton } from "components/AccountButton";
|
||||
import { HelpButton } from "components/HelpButton";
|
||||
import { Tooltip } from "components/Tooltip";
|
||||
import { AccountButton } from "@/app/_components/AccountButton";
|
||||
import { HelpButton } from "@/app/_components/HelpButton";
|
||||
import { Tooltip } from "@/app/_components/Tooltip";
|
||||
import { useAppContext } from "./AppProvider";
|
||||
// import { LanguageSelect } from "./LanguageSelect";
|
||||
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState, useEffect } from "react";
|
||||
import {
|
||||
Box,
|
||||
|
|
@ -23,11 +25,11 @@ import {
|
|||
RemoveCircle as RemoveCircleIcon,
|
||||
} from "@mui/icons-material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { QueryBuilder } from "components/QueryBuilder";
|
||||
import { QueryText } from "components/QueryText";
|
||||
import { LiveDataViewer } from "components/LiveDataViewer";
|
||||
import { Tooltip } from "components/Tooltip";
|
||||
import visualizationMap from "config/visualizationMap.json";
|
||||
import { QueryBuilder } from "@/app/_components/QueryBuilder";
|
||||
import { QueryText } from "@/app/_components/QueryText";
|
||||
import { LiveDataViewer } from "@/app/_components/LiveDataViewer";
|
||||
import { Tooltip } from "@/app/_components/Tooltip";
|
||||
import visualizationMap from "app/_config/visualizationMap.json";
|
||||
import { VisualizationSelectCard } from "./VisualizationSelectCard";
|
||||
import { MetricSelectCard } from "./MetricSelectCard";
|
||||
import { useAppContext } from "./AppProvider";
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { Grid, Card, Box } from "@mui/material";
|
||||
import Iframe from "react-iframe";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { VisualizationDetailDialog } from "components/VisualizationDetailDialog";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
import { VisualizationDetailDialog } from "@/app/_components/VisualizationDetailDialog";
|
||||
|
||||
interface VisualizationCardProps {
|
||||
id: string;
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
// import Link from "next/link";
|
||||
import { Box } from "@mui/material";
|
||||
import Iframe from "react-iframe";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
|
||||
interface VisualizationDetailProps {
|
||||
id: string;
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
// import Link from "next/link";
|
||||
import {
|
||||
|
|
@ -9,7 +11,7 @@ import {
|
|||
TextField,
|
||||
} from "@mui/material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
import { VisualizationDetail } from "./VisualizationDetail";
|
||||
|
||||
interface VisualizationDetailDialogProps {
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import Image from "next/legacy/image";
|
||||
import { Card, Grid } from "@mui/material";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { Box, Grid } from "@mui/material";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { Box, Grid, Dialog, Button } from "@mui/material";
|
||||
import { useRouter } from "next/router";
|
||||
// import { useSession } from "next-auth/react";
|
||||
|
|
@ -4,18 +4,17 @@ import Head from "next/head";
|
|||
import Image from "next/legacy/image";
|
||||
import Link from "next/link";
|
||||
import { Grid, Container, Box, Button } from "@mui/material";
|
||||
import { Layout } from "components/Layout";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { PageHeader } from "components/PageHeader";
|
||||
import { AboutFeature } from "components/AboutFeature";
|
||||
import { AboutBox } from "components/AboutBox";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
import { PageHeader } from "@/app/_components/PageHeader";
|
||||
import { AboutFeature } from "@/app/_components/AboutFeature";
|
||||
import { AboutBox } from "@/app/_components/AboutBox";
|
||||
import AbstractDiagram from "images/abstract-diagram.png";
|
||||
import AboutHeader from "images/about-header.png";
|
||||
import Globe from "images/globe.png";
|
||||
import Controls from "images/controls.png";
|
||||
import CommunityBackground from "images/community-background.png";
|
||||
import Bicycle from "images/bicycle.png";
|
||||
import { getEmbedded } from "lib/utils";
|
||||
import { getEmbedded } from "@/app/_lib/utils";
|
||||
|
||||
type AboutProps = {
|
||||
embedded: boolean;
|
||||
|
|
@ -29,10 +28,7 @@ const About: NextPage<AboutProps> = ({ embedded }) => {
|
|||
} = useAppContext();
|
||||
|
||||
return (
|
||||
<Layout embedded={embedded}>
|
||||
<Head>
|
||||
<title>Digital Threat Dashboard – Leafcutter</title>
|
||||
</Head>
|
||||
<>
|
||||
<PageHeader
|
||||
backgroundColor={leafcutterElectricBlue}
|
||||
sx={{
|
||||
|
|
@ -166,7 +162,7 @@ const About: NextPage<AboutProps> = ({ embedded }) => {
|
|||
</Link>
|
||||
</Container>
|
||||
</Box>
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ import NextAuth from "next-auth";
|
|||
import Google from "next-auth/providers/google";
|
||||
import Apple from "next-auth/providers/apple";
|
||||
|
||||
export default NextAuth({
|
||||
const handler = NextAuth({
|
||||
providers: [
|
||||
Google({
|
||||
clientId: process.env.GOOGLE_CLIENT_ID ?? "",
|
||||
|
|
@ -15,3 +15,5 @@ export default NextAuth({
|
|||
],
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
});
|
||||
|
||||
export { handler as GET, handler as POST };
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { getUserMetadata, saveUserMetadata } from "lib/opensearch";
|
||||
import { getUserMetadata, saveUserMetadata } from "@/app/_lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
export const POST = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
req,
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
|
|
@ -27,7 +27,6 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||
return res.json(updatedSavedSearches);
|
||||
};
|
||||
|
||||
export default handler;
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { getUserMetadata, saveUserMetadata } from "lib/opensearch";
|
||||
import { getUserMetadata, saveUserMetadata } from "@/app/_lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { getUserMetadata } from "lib/opensearch";
|
||||
import { getUserMetadata } from "@/app/_lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
20
apps/leafcutter/app/api/trends/recent.ts
Normal file
20
apps/leafcutter/app/api/trends/recent.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { NextResponse } from "next/server";
|
||||
// import { getToken } from "next-auth/jwt";
|
||||
import { getTrends } from "@/app/_lib/opensearch";
|
||||
|
||||
export const GET = async () => {
|
||||
/*
|
||||
const session = await getToken({
|
||||
req,
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
});
|
||||
|
||||
if (!session) {
|
||||
return res.redirect("/login");
|
||||
}
|
||||
*/
|
||||
const results = await getTrends(5);
|
||||
|
||||
NextResponse.json(results);
|
||||
};
|
||||
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { Client } from "@opensearch-project/opensearch";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import taxonomy from "config/taxonomy.json";
|
||||
import unRegions from "config/unRegions.json";
|
||||
import taxonomy from "app/_config/taxonomy.json";
|
||||
import unRegions from "app/_config/unRegions.json";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const { headers: { authorization }, body: { tickets } } = req;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { createUserVisualization } from "lib/opensearch";
|
||||
import { createUserVisualization } from "@/app/_lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { deleteUserVisualization } from "lib/opensearch";
|
||||
import { deleteUserVisualization } from "@/app/_lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { performQuery } from "lib/opensearch";
|
||||
import { performQuery } from "@/app/_lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
|
|
@ -16,7 +16,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||
const rawQuery = await JSON.parse(decodeURI(searchQuery as string));
|
||||
const results = await performQuery(rawQuery, 1000);
|
||||
|
||||
return res.json(results)
|
||||
return res.json(results);
|
||||
};
|
||||
|
||||
export default handler;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { updateUserVisualization } from "lib/opensearch";
|
||||
import { updateUserVisualization } from "@/app/_lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
import { FC, useEffect } from "react";
|
||||
import { GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||
import Head from "next/head";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { useRouter } from "next/router";
|
||||
import { Box, Grid } from "@mui/material";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { getTemplates } from "lib/opensearch";
|
||||
import { Layout } from "components/Layout";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { PageHeader } from "components/PageHeader";
|
||||
import { VisualizationBuilder } from "components/VisualizationBuilder";
|
||||
import { getEmbedded } from "lib/utils";
|
||||
import { getTemplates } from "@/app/_lib/opensearch";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
import { PageHeader } from "@/app/_components/PageHeader";
|
||||
import { VisualizationBuilder } from "@/app/_components/VisualizationBuilder";
|
||||
import { getEmbedded } from "@/app/_lib/utils";
|
||||
|
||||
type CreateProps = {
|
||||
templates: any;
|
||||
|
|
@ -36,11 +34,7 @@ const Create: FC<CreateProps> = ({ templates, embedded }) => {
|
|||
}, [searchIntroComplete, router, setCookie]);
|
||||
|
||||
return (
|
||||
<Layout embedded={embedded}>
|
||||
<Head>
|
||||
<title>Digital Threat Dashboard – Leafcutter</title>
|
||||
</Head>
|
||||
|
||||
<>
|
||||
<PageHeader backgroundColor={cdrLinkOrange}>
|
||||
<Grid container direction="row" spacing={2} alignItems="center">
|
||||
{/* <Grid item xs={2} sx={{ textAlign: "center" }}>
|
||||
|
|
@ -67,7 +61,7 @@ const Create: FC<CreateProps> = ({ templates, embedded }) => {
|
|||
</PageHeader>
|
||||
|
||||
<VisualizationBuilder templates={templates} />
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
import Head from "next/head";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||
import { Box, Grid } from "@mui/material";
|
||||
import { Layout } from "components/Layout";
|
||||
import { PageHeader } from "components/PageHeader";
|
||||
import { Question } from "components/Question";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { PageHeader } from "@/app/_components/PageHeader";
|
||||
import { Question } from "@/app/_components/Question";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
import FaqHeader from "images/faq-header.svg";
|
||||
import { getEmbedded } from "lib/utils";
|
||||
import { getEmbedded } from "@/app/_lib/utils";
|
||||
|
||||
type FAQProps = {
|
||||
embedded: boolean;
|
||||
|
|
@ -70,10 +68,7 @@ const FAQ: NextPage<FAQProps> = ({ embedded }) => {
|
|||
];
|
||||
|
||||
return (
|
||||
<Layout embedded={embedded}>
|
||||
<Head>
|
||||
<title>Digital Threat Dashboard – Leafcutter</title>
|
||||
</Head>
|
||||
<>
|
||||
<PageHeader
|
||||
backgroundColor={lavender}
|
||||
sx={{
|
||||
|
|
@ -105,7 +100,7 @@ const FAQ: NextPage<FAQProps> = ({ embedded }) => {
|
|||
{questions.map((q: any, index: number) => (
|
||||
<Question key={index} question={q.question} answer={q.answer} />
|
||||
))}
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
36
apps/leafcutter/app/layout.tsx
Normal file
36
apps/leafcutter/app/layout.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { ReactNode } from "react";
|
||||
import { Metadata } from "next";
|
||||
import "./_styles/global.css";
|
||||
import "@fontsource/poppins/400.css";
|
||||
import "@fontsource/poppins/700.css";
|
||||
import "@fontsource/roboto/400.css";
|
||||
import "@fontsource/roboto/700.css";
|
||||
import "@fontsource/playfair-display/900.css";
|
||||
import "styles/global.css";
|
||||
// import getConfig from "next/config";
|
||||
// import { LicenseInfo } from "@mui/x-data-grid-pro";
|
||||
import { MultiProvider } from "app/_components/MultiProvider";
|
||||
import { InternalLayout } from "app/_components/InternalLayout";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Leafcutter",
|
||||
};
|
||||
|
||||
type LayoutProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export default function Layout({ children }: LayoutProps) {
|
||||
// const { publicRuntimeConfig } = getConfig();
|
||||
// LicenseInfo.setLicenseKey(publicRuntimeConfig.muiLicenseKey);
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>
|
||||
<MultiProvider>
|
||||
<InternalLayout>{children}</InternalLayout>
|
||||
</MultiProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
|
@ -5,10 +5,10 @@ import Image from "next/legacy/image";
|
|||
import { Box, Grid, Container, IconButton } from "@mui/material";
|
||||
import { Apple as AppleIcon, Google as GoogleIcon } from "@mui/icons-material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { LanguageSelect } from "components/LanguageSelect";
|
||||
import { LanguageSelect } from "@/app/_components/LanguageSelect";
|
||||
import LeafcutterLogoLarge from "images/leafcutter-logo-large.png";
|
||||
import { signIn, getSession } from "next-auth/react";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
|
||||
type LoginProps = {
|
||||
session: any;
|
||||
16
apps/leafcutter/app/page.tsx
Normal file
16
apps/leafcutter/app/page.tsx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { getSession } from "next-auth/react";
|
||||
import { getUserVisualizations } from "@/app/_lib/opensearch";
|
||||
import { getEmbedded } from "@/app/_lib/utils";
|
||||
import { Home } from "@/app/_components/Home";
|
||||
|
||||
export default async function Page() {
|
||||
const context = undefined;
|
||||
const session = (await getSession(context)) ?? null;
|
||||
const visualizations = await getUserVisualizations(
|
||||
session?.user?.email ?? "none",
|
||||
20
|
||||
);
|
||||
const embedded = false; // getEmbedded(context);
|
||||
|
||||
return <Home visualizations={visualizations} embedded={embedded} />;
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { FC } from "react";
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
// import { Client } from "@opensearch-project/opensearch";
|
||||
import { RawDataViewer } from "components/RawDataViewer";
|
||||
import { VisualizationDetail } from "components/VisualizationDetail";
|
||||
import { RawDataViewer } from "@/app/_components/RawDataViewer";
|
||||
import { VisualizationDetail } from "@/app/_components/VisualizationDetail";
|
||||
// import { createVisualization } from "lib/opensearch";
|
||||
|
||||
interface PreviewProps {
|
||||
|
|
@ -3,7 +3,7 @@ import { NextPage } from "next";
|
|||
import { useRouter } from "next/router";
|
||||
import { Grid, CircularProgress } from "@mui/material";
|
||||
import Iframe from "react-iframe";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
|
||||
const Setup: NextPage = () => {
|
||||
const {
|
||||
|
|
@ -2,12 +2,11 @@ import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next";
|
|||
import Head from "next/head";
|
||||
import { Grid, Box } from "@mui/material";
|
||||
import { useTranslate } from "react-polyglot";
|
||||
import { Layout } from "components/Layout";
|
||||
import { getTrends } from "lib/opensearch";
|
||||
import { PageHeader } from "components/PageHeader";
|
||||
import { VisualizationCard } from "components/VisualizationCard";
|
||||
import { useAppContext } from "components/AppProvider";
|
||||
import { getEmbedded } from "lib/utils";
|
||||
import { getTrends } from "@/app/_lib/opensearch";
|
||||
import { PageHeader } from "@/app/_components/PageHeader";
|
||||
import { VisualizationCard } from "@/app/_components/VisualizationCard";
|
||||
import { useAppContext } from "@/app/_components/AppProvider";
|
||||
import { getEmbedded } from "@/app/_lib/utils";
|
||||
|
||||
type TrendsProps = {
|
||||
visualizations: any;
|
||||
|
|
@ -22,10 +21,7 @@ const Trends: NextPage<TrendsProps> = ({ visualizations, embedded }) => {
|
|||
} = useAppContext();
|
||||
|
||||
return (
|
||||
<Layout embedded={embedded}>
|
||||
<Head>
|
||||
<title>Digital Threat Dashboard – Leafcutter</title>
|
||||
</Head>
|
||||
<>
|
||||
<PageHeader backgroundColor={cdrLinkOrange}>
|
||||
<Grid
|
||||
container
|
||||
|
|
@ -73,7 +69,7 @@ const Trends: NextPage<TrendsProps> = ({ visualizations, embedded }) => {
|
|||
/>
|
||||
))}
|
||||
</Grid>
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
/* eslint-disable no-underscore-dangle */
|
||||
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||
import { Client } from "@opensearch-project/opensearch";
|
||||
import Head from "next/head";
|
||||
import { Layout } from "components/Layout";
|
||||
import { VisualizationDetail } from "components/VisualizationDetail";
|
||||
import { getEmbedded } from "lib/utils";
|
||||
import { VisualizationDetail } from "@/app/_components/VisualizationDetail";
|
||||
import { getEmbedded } from "@/app/_lib/utils";
|
||||
|
||||
type VisualizationProps = {
|
||||
visualization: any;
|
||||
|
|
@ -14,14 +12,7 @@ type VisualizationProps = {
|
|||
const Visualization: NextPage<VisualizationProps> = ({
|
||||
visualization,
|
||||
embedded,
|
||||
}) => (
|
||||
<Layout embedded={embedded}>
|
||||
<Head>
|
||||
<title>Digital Threat Dashboard – Leafcutter</title>
|
||||
</Head>
|
||||
<VisualizationDetail {...visualization} />
|
||||
</Layout>
|
||||
);
|
||||
}) => <VisualizationDetail {...visualization} />;
|
||||
|
||||
export default Visualization;
|
||||
|
||||
|
|
@ -23,13 +23,13 @@
|
|||
"@mui/icons-material": "^5",
|
||||
"@mui/lab": "^5.0.0-alpha.134",
|
||||
"@mui/material": "^5",
|
||||
"@mui/x-data-grid-pro": "^6.8.0",
|
||||
"@mui/x-date-pickers-pro": "^6.8.0",
|
||||
"@mui/x-data-grid-pro": "^6.9.0",
|
||||
"@mui/x-date-pickers-pro": "^6.9.0",
|
||||
"@opensearch-project/opensearch": "^2.0.0",
|
||||
"date-fns": "^2.30.0",
|
||||
"http-proxy-middleware": "^2.0.6",
|
||||
"material-ui-popup-state": "^5.0.9",
|
||||
"next": "13.4.6",
|
||||
"next": "13.4.7",
|
||||
"next-auth": "^4.22.1",
|
||||
"next-http-proxy-middleware": "^1.2.5",
|
||||
"nodemailer": "^6.9.3",
|
||||
|
|
@ -41,18 +41,19 @@
|
|||
"react-markdown": "^8.0.7",
|
||||
"react-polyglot": "^0.7.2",
|
||||
"sharp": "^0.32.1",
|
||||
"swr": "^2.1.5",
|
||||
"swr": "^2.2.0",
|
||||
"tss-react": "^4.8.6",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.22.5",
|
||||
"@types/react": "18.2.13",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/react": "18.2.14",
|
||||
"@types/uuid": "^9.0.2",
|
||||
"babel-loader": "^9.1.2",
|
||||
"eslint": "^8.43.0",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
"eslint-config-next": "^13.4.6",
|
||||
"eslint-config-next": "^13.4.7",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
/* eslint-disable react/jsx-props-no-spreading */
|
||||
import { AppProps } from "next/app";
|
||||
import { SessionProvider } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
import Head from "next/head";
|
||||
import { CssBaseline } from "@mui/material";
|
||||
import { CacheProvider, EmotionCache } from "@emotion/react";
|
||||
import { CookiesProvider } from "react-cookie";
|
||||
import { I18n } from "react-polyglot";
|
||||
import { AdapterDateFns } from "@mui/x-date-pickers-pro/AdapterDateFns";
|
||||
import { LocalizationProvider } from "@mui/x-date-pickers-pro";
|
||||
import { AppProvider } from "components/AppProvider";
|
||||
import createEmotionCache from "lib/createEmotionCache";
|
||||
import Favicon from "images/favicon.ico";
|
||||
import en from "locales/en.json";
|
||||
import fr from "locales/fr.json";
|
||||
import "@fontsource/poppins/400.css";
|
||||
import "@fontsource/poppins/700.css";
|
||||
import "@fontsource/roboto/400.css";
|
||||
import "@fontsource/roboto/700.css";
|
||||
import "@fontsource/playfair-display/900.css";
|
||||
import "styles/global.css";
|
||||
import { LicenseInfo } from "@mui/x-data-grid-pro";
|
||||
|
||||
LicenseInfo.setLicenseKey(process.env.MUI_LICENSE_KEY ?? "");
|
||||
|
||||
const clientSideEmotionCache: any = createEmotionCache();
|
||||
|
||||
const messages: any = { en, fr };
|
||||
|
||||
interface LeafcutterWebProps extends AppProps {
|
||||
// eslint-disable-next-line react/require-default-props
|
||||
emotionCache?: EmotionCache;
|
||||
}
|
||||
|
||||
const LeafcutterWeb = (props: LeafcutterWebProps) => {
|
||||
const { locale = "en" } = useRouter();
|
||||
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="icon" type="image/png" href={Favicon.src} />
|
||||
</Head>
|
||||
<SessionProvider session={(pageProps as any).session}>
|
||||
<CacheProvider value={emotionCache}>
|
||||
<CookiesProvider>
|
||||
<CssBaseline />
|
||||
<AppProvider>
|
||||
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
||||
<I18n locale={locale} messages={messages[locale]}>
|
||||
<Component {...pageProps} />
|
||||
</I18n>
|
||||
</LocalizationProvider>
|
||||
</AppProvider>
|
||||
</CookiesProvider>
|
||||
</CacheProvider>
|
||||
</SessionProvider>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default LeafcutterWeb;
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// eslint-disable-next-line no-use-before-define
|
||||
import * as React from "react";
|
||||
import Document, { Html, Head, Main, NextScript } from "next/document";
|
||||
import createEmotionServer from "@emotion/server/create-instance";
|
||||
import createEmotionCache from "lib/createEmotionCache";
|
||||
|
||||
export default class LeafcutterDocument extends Document {
|
||||
render() {
|
||||
return (
|
||||
<Html lang="en">
|
||||
<Head />
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
LeafcutterDocument.getInitialProps = async (ctx): Promise<any> => {
|
||||
const originalRenderPage = ctx.renderPage;
|
||||
const cache = createEmotionCache();
|
||||
const { extractCriticalToChunks } = createEmotionServer(cache as any);
|
||||
|
||||
ctx.renderPage = () =>
|
||||
originalRenderPage({
|
||||
enhanceApp: (App: any) => (props: any) =>
|
||||
<App emotionCache={cache} {...props} />,
|
||||
});
|
||||
|
||||
const initialProps = await Document.getInitialProps(ctx);
|
||||
const emotionStyles = extractCriticalToChunks(initialProps.html);
|
||||
const emotionStyleTags = emotionStyles.styles.map((style) => (
|
||||
<style
|
||||
data-emotion={`${style.key} ${style.ids.join(" ")}`}
|
||||
key={style.key}
|
||||
// eslint-disable-next-line react/no-danger
|
||||
dangerouslySetInnerHTML={{ __html: style.css }}
|
||||
/>
|
||||
));
|
||||
|
||||
return {
|
||||
...initialProps,
|
||||
styles: [
|
||||
...React.Children.toArray(initialProps.styles),
|
||||
...emotionStyleTags,
|
||||
],
|
||||
};
|
||||
};
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { getTrends } from "lib/opensearch";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getToken({
|
||||
req,
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
});
|
||||
|
||||
if (!session) {
|
||||
return res.redirect("/login");
|
||||
}
|
||||
|
||||
const results = await getTrends(5);
|
||||
return res.json(results)
|
||||
};
|
||||
|
||||
export default handler;
|
||||
Loading…
Add table
Add a link
Reference in a new issue