Skip to content

Commit

Permalink
feat: add knowledge
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Ellison committed Jun 19, 2023
1 parent 48dc9aa commit 9d4a60c
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 173 deletions.
154 changes: 42 additions & 112 deletions components/solutions/SolutionView.jsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,38 @@
import React, { useState, useEffect, useRef } from 'react'
import React, { useState } from 'react'

import { ErrorBoundary } from 'react-error-boundary'
import { baseTheme } from '../../constants/baseTheme';

import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import { mdComponents } from "../../constants/mdxProvider";
import Link from '@mui/material/Link';
import { Stack } from '@mui/material'
import { Chip } from '@mui/material'
import { TopBar } from '@/components/dashboard';
import { MiniStatisticsCard } from "@/components/dashboard";
import { MDXProvider } from '@mdx-js/react';
import { Menu, ButtonMenu, NavigationDrawer } from '@/components/airview-ui';
import { ControlTable } from '@/components/compliance/ControlTable';
import { ControlDataDisplay } from '@/components/compliance/ControlData';
import { useMdx } from '@/lib/content/mdx'
import Container from '@mui/material/Container';
import CloseIcon from '@mui/icons-material/Close';
import { Menu, NavigationDrawer } from '@/components/airview-ui';
import { PagedOutput } from '@/components/display/PagedOutput';
import { PresentationOutput } from '@/components/display/PresentationOutput';
import { Dialog, DialogTitle, DialogContent, DialogActions, Button, IconButton, Typography, MenuItem, Box, Alert, Grid } from '@mui/material';
import { Container as MuiContainer } from "@mui/material";
import SlideshowIcon from '@mui/icons-material/Slideshow';
import { IconButton, Typography, MenuItem, Box, Alert, Grid } from '@mui/material';

import {

AsideAndMainContainer,
Aside,
Main,

} from '@/components/airview-ui';

import { Previewer } from 'pagedjs'

import { Tile } from '@/components/dashboard/Tiles'
import path from 'path';

import { siteConfig } from "../../site.config.js";
import { AsideAndMainContainer, Aside, Main } from '@/components/airview-ui';

export function SolutionView({
knowledge,
solutions,
designs,
children,
frontmatter,
file,
content
content,
menuStructure
}) {


console.log('SolutionView:menuStructure: ', menuStructure)
const navDrawerWidth = 300;
const topBarHeight = 64;
const [menuOpen, setMenuOpen] = useState(true);
const [dialogOpen, setDialogOpen] = useState(false);
const [controlUrl, setControlUrl] = useState('');
const [print, setPrint] = useState(false);
const [presentation, setPresentation] = useState(false);

const handleOnNavButtonClick = () => setMenuOpen((prevState) => !prevState);

const { solutionMenu, chapterFiles, knowledgeFiles, designFiles } = fileStructure(solutions)
const { solutionMenu, chapterFiles, knowledgeFiles, designFiles } = menuStructure;

function handlePrint() {
setPrint(!print);
Expand Down Expand Up @@ -120,12 +92,10 @@ export function SolutionView({
{children && children}
</Main>
<Aside sx={{ displayPrint: 'none', display: print ? 'none' : '' }}>
<ChaptersMenu
<ContentMenu
chapters={chapterFiles}
knowledge={knowledgeFiles}
file={file}
open={menuOpen}
top={topBarHeight}
drawerWidth={navDrawerWidth}
/>
{/* <ButtonMenu
menuTitle="Controls"
Expand Down Expand Up @@ -153,36 +123,51 @@ export function SolutionView({
} else if (presentation) {
return (
<PresentationOutput handlePresentation={handlePresentation} refresh={false} content={content}>
{children && children}
{children && children}
</PresentationOutput>
)
}
}


function ChaptersMenu({ chapters, file, open, top, drawerWidth }) {
function ContentMenu({ chapters, file, knowledge }) {
// console.log('ChaptersMenu: ', chapters)
// console.log('ChaptersMenu:File ', file)
let directory = file.split("/")[1]; // Extract directory name
const chaptersMenu = [
{
groupTitle: "",
links: chapters[directory]
}
]
let chaptersMenu = []
if (chapters[directory]) {
chaptersMenu.push(
{
groupTitle: "Chapters",
links: chapters[directory]
}
)
}
if (knowledge[directory]) {
chaptersMenu.push(
{
groupTitle: "Knowledge",
links: knowledge[directory]
}
)
}

return (
<Menu
menuTitle="Chapters"
menuItems={chaptersMenu}
initialCollapsed={false}
loading={false}
fetching={false}
/>
);
if (chaptersMenu) {
return (
<Menu
menuTitle="Content"
menuItems={chaptersMenu}
initialCollapsed={false}
loading={false}
fetching={false}
/>
);
}
}




function SolutionsMenu({ solutions, open, top, drawerWidth }) {
// console.log('SolutionsMenu: ', solutions)

Expand All @@ -197,58 +182,3 @@ function SolutionsMenu({ solutions, open, top, drawerWidth }) {
</NavigationDrawer>
);
}


function fileStructure(solutions, knowledge) {
const solutionMenu = [];
const chapterFiles = {};
const indexFiles = new Set();

// First pass: Find index.md files
for (let x of solutions) {
if (
x.file &&
x.file.split('/').length === 3 &&
x.file.match(/(_index\.md*|index\.md*)$/) &&
x.frontmatter &&
x.frontmatter.title
) {
solutionMenu.push({
label: x.frontmatter.title,
url: x.file,
});
indexFiles.add(x.file.split("/")[1]); // Add directory name to the Set
}
}

// Second pass: Process non-index.md files
for (let x of solutions) {
if (
x.file &&
x.file.split('/').length > 2 && // skip any files in the root of the directory
!x.file.match(/(_index\.md*|index\.md*)$/) &&
x.frontmatter &&
x.frontmatter.title
) {
let directory = x.file.split("/")[1]; // Extract directory name

// Only add file to solutionMenu if there is no corresponding index.md
if (!indexFiles.has(directory)) {
solutionMenu.push({
label: x.frontmatter.title,
url: x.file,
});
}

// Check if the key exists in the chapterFiles object
if (!chapterFiles[directory]) {
chapterFiles[directory] = [];
}
chapterFiles[directory].push({
label: x.frontmatter.title,
url: '/' + x.file,
});
}
}
return { solutionMenu, chapterFiles, knowledgeFiles: null, designFiles: null };
}
3 changes: 2 additions & 1 deletion lib/content/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// helper for content and page contexts

export { useMdx } from './mdx';
export { useMdx } from './mdx';
export { menuStructure } from './menus'
Loading

0 comments on commit 9d4a60c

Please sign in to comment.