Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): officially release @docusaurus/plugin-debug #3392

Merged
merged 26 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cacdd45
Add json styling to config debug
Drewbi Aug 16, 2020
26302d7
Style debug content page
Drewbi Aug 16, 2020
4144cb4
Add style and collapse depth to json viewer
Drewbi Aug 16, 2020
dd99e42
Add style to debug layout
Drewbi Aug 16, 2020
e95703d
Add style to metadata debug
Drewbi Aug 16, 2020
681089b
Add style support to registry debugger
Drewbi Aug 16, 2020
9865f92
Remove default content if other instances are present
Drewbi Aug 17, 2020
5d16872
Change colors for more contrast
Drewbi Aug 17, 2020
68ed1bc
Add debug routes styles
Drewbi Aug 17, 2020
d1bfe1c
Add active link style
Drewbi Aug 17, 2020
fae01ff
Fix container css issues
Drewbi Aug 17, 2020
025db33
Style registry debug page
Drewbi Aug 17, 2020
7f90587
Remove unused style modules
Drewbi Aug 17, 2020
8f93b43
Add white space to style files
Drewbi Aug 17, 2020
ba9af39
Add font scaling
Drewbi Aug 17, 2020
d30e092
Fix prettier errors
Drewbi Aug 17, 2020
0add1cc
Add child routes to route debug
Drewbi Aug 17, 2020
2b660aa
Readd default content plugin json
Drewbi Aug 17, 2020
9c43c9f
Add empty home page to debug
Drewbi Aug 17, 2020
905c99f
Prettier
Drewbi Aug 17, 2020
78359c3
Revert "Add empty home page to debug"
Drewbi Aug 18, 2020
d7b7e15
Merge branch 'master' of github.com:MLH-Fellowship/docusaurus into dr…
Drewbi Aug 25, 2020
a7b6cf1
Set colors to dark theme
Drewbi Aug 31, 2020
c424c31
Merge branch 'master' into slorber/plugin-debug
slorber Sep 2, 2020
3cf4220
Add plugin debug doc + minor fixes + expose global data
slorber Sep 2, 2020
4aafb18
more debug plugin doc
slorber Sep 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/docusaurus-plugin-debug/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function pluginContentPages({

addRoute({
path: normalizeUrl([baseUrl, '__docusaurus/debug/metadata']),
component: '@theme/DebugMetadata',
component: '@theme/DebugSiteMetadata',
exact: true,
});

Expand All @@ -74,6 +74,12 @@ export default function pluginContentPages({
allContent: aliasedSource(allContentPath),
},
});

addRoute({
path: normalizeUrl([baseUrl, '__docusaurus/debug/globalData']),
component: '@theme/DebugGlobalData',
exact: true,
});
},

configureWebpack() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import React from 'react';

import DebugLayout from '../DebugLayout';
import DebugJsonView from '../DebugJsonView';

import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

function DebugMetadata() {
const {siteConfig} = useDocusaurusContext();
return (
<DebugLayout>
<h2>Site config</h2>
<div>{JSON.stringify(siteConfig, null, 2)}</div>
<DebugJsonView src={siteConfig} collapseDepth="3" />
</DebugLayout>
);
}
Expand Down

This file was deleted.

54 changes: 20 additions & 34 deletions packages/docusaurus-plugin-debug/src/theme/DebugContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,38 @@
* LICENSE file in the root directory of this source tree.
*/

import React, {useState} from 'react';
import React from 'react';

import DebugLayout from '../DebugLayout';
import DebugJsonView from '../DebugJsonView';

const PluginInstanceContent = ({pluginId, pluginInstanceContent}) => (
<section style={{marginBottom: 30}}>
<h4>{`>> ${pluginId}`}</h4>
<div
style={{
marginTop: 10,
padding: 10,
border: 'thin cyan solid',
borderRadius: 5,
backgroundColor: 'lightgrey',
}}>
<DebugJsonView src={pluginInstanceContent} />
</div>
<code>{pluginId}</code>
<DebugJsonView src={pluginInstanceContent} collapseDepth="2" />
</section>
);

const PluginContent = ({pluginName, pluginContent}) => {
const [visible, setVisible] = useState(true);
return (
<section style={{marginBottom: 60}}>
<h3 onClick={() => setVisible((v) => !v)} style={{cursor: 'pointer'}}>
{pluginName}
</h3>
{visible && (
<div>
{Object.entries(pluginContent)
// filter plugin instances with no content
.filter(
([_pluginId, pluginInstanceContent]) => !!pluginInstanceContent,
)
.map(([pluginId, pluginInstanceContent]) => {
return (
<PluginInstanceContent
key={pluginId}
pluginId={pluginId}
pluginInstanceContent={pluginInstanceContent}
/>
);
})}
</div>
)}
<h3>{pluginName}</h3>
<div>
{Object.entries(pluginContent)
// filter plugin instances with no content
.filter(
([_pluginId, pluginInstanceContent]) => !!pluginInstanceContent,
)
.map(([pluginId, pluginInstanceContent]) => {
return (
<PluginInstanceContent
key={pluginId}
pluginId={pluginId}
pluginInstanceContent={pluginInstanceContent}
/>
);
})}
</div>
</section>
);
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';

import DebugLayout from '../DebugLayout';
import DebugJsonView from '../DebugJsonView';
import useGlobalData from '@docusaurus/useGlobalData';

function DebugMetadata() {
const globalData = useGlobalData();
return (
<DebugLayout>
<h2>Global data</h2>
<DebugJsonView src={globalData} collapseDepth="3" />
</DebugLayout>
);
}

export default DebugMetadata;
17 changes: 14 additions & 3 deletions packages/docusaurus-plugin-debug/src/theme/DebugJsonView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,28 @@ const BrowserOnlyReactJson = (props) => {
);
};

function DebugJsonView({src}) {
function DebugJsonView({src, collapseDepth}) {
return (
<BrowserOnlyReactJson
src={src}
style={{
marginTop: '10px',
padding: '10px',
borderRadius: '4px',
backgroundColor: '#292a2b',
}}
name={RootName}
theme="paraiso"
shouldCollapse={(field) => {
// By default, we collapse the json for performance reasons
// See https://github.com/mac-s-g/react-json-view/issues/235
// only the "root" is not collapsed
return field.name !== RootName;
// Non-root elements that are larger than 50 fields are collapsed
return field.name !== RootName && Object.keys(field.src).length > 50;
}}
collapsed={collapseDepth}
groupArraysAfterLength="5"
enableClipboard={false}
displayDataTypes={false}
/>
);
}
Expand Down

This file was deleted.

18 changes: 11 additions & 7 deletions packages/docusaurus-plugin-debug/src/theme/DebugLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,35 @@

import React from 'react';
import Link from '@docusaurus/Link';
// import styles from './styles.module.css';
import styles from './styles.module.css';

const DebugNavLink = ({to, children}) => (
<Link
style={{margin: 10}}
className="button button--primary"
className={styles.navlink}
isNavLink
activeClassName="button--active"
to={to}
exact>
exact
activeStyle={{
backgroundColor: '#363739',
}}>
{children}
</Link>
);

function DebugLayout({children}) {
return (
<div>
<nav style={{width: '100%', padding: 10, border: 'solid'}}>
<nav className={styles.nav}>
<DebugNavLink to="/__docusaurus/debug">Config</DebugNavLink>
<DebugNavLink to="/__docusaurus/debug/metadata">Metadata</DebugNavLink>
<DebugNavLink to="/__docusaurus/debug/registry">Registry</DebugNavLink>
<DebugNavLink to="/__docusaurus/debug/routes">Routes</DebugNavLink>
<DebugNavLink to="/__docusaurus/debug/content">Content</DebugNavLink>
<DebugNavLink to="/__docusaurus/debug/globalData">
Global data
</DebugNavLink>
</nav>
<main style={{padding: 20}}>{children}</main>
<main className={styles.container}>{children}</main>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,72 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.container {
padding: 20px;
padding-top: 80px;
overflow-x: hidden;
background-color: #18191a;
color: white;
min-height: 100vh;
}

.nav {
position: fixed;
display: flex;
justify-content: space-evenly;
align-items: center;
height: 3.75rem;
background-color: #242526;
width: 100%;
z-index: 1;
}

.navlink {
color: white;
font-weight: 500;
font-size: clamp(12px, 4vw, 16px);
text-align: center;
border-radius: 4px;
padding: 6px 6px;
}

.navlink:hover {
text-decoration: none;
background-color: #292a2b;
}

code {
color: white;
background-color: #444950;
}

.active {
background-color: #363739;
}

@media screen and (min-width: 800px) {
.nav {
flex-direction: column;
justify-content: flex-start;
align-items: center;
height: 100vh;
width: 200px;
float: left;
background-color: #18191a;
border-right: 1px solid #606770;
padding-top: 20px;
}

.navlink {
width: 80%;
margin-top: 20px;
text-align: left;
}

.container {
padding-top: 40px;
float: right;
width: calc(100% - 200px);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ import React from 'react';

import DebugLayout from '../DebugLayout';
import registry from '@generated/registry';
import styles from './styles.module.css';

function DebugRegistry() {
return (
<DebugLayout>
{' '}
<h2>Registry</h2>
<ul>
<ul className={styles.list}>
{Object.values(registry).map(([, aliasedPath, resolved]) => (
<li key={aliasedPath}>
<div>Aliased Path: {aliasedPath}</div>
<div>Resolved Path: {resolved}</div>
<li key={aliasedPath} className={styles.listItem}>
<div style={{marginBottom: '10px'}}>
Aliased Path: <code>{aliasedPath}</code>
</div>
<div>
Resolved Path: <code>{resolved}</code>
</div>
</li>
))}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

.list {
padding: 0;
}

.listItem {
list-style: none;
background-color: #242526;
padding: 10px;
border-radius: 4px;
margin-bottom: 20px;
}
22 changes: 17 additions & 5 deletions packages/docusaurus-plugin-debug/src/theme/DebugRoutes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,29 @@
import React from 'react';

import DebugLayout from '../DebugLayout';
import DebugJsonView from '../DebugJsonView';
import routes from '@generated/routes';
import styles from './styles.module.css';

function DebugRoutes() {
return (
<DebugLayout>
<h2>Routes</h2>
<ul>
{routes.map(({path, exact}) => (
<li key={path}>
<div>Route: {path}</div>
<div>Is exact: {String(Boolean(exact))}</div>
<ul className={styles.list}>
{routes.map(({path, exact, routes: childRoutes}) => (
<li key={path} className={styles.listItem}>
<div className={styles.route}>
<code className={styles.routeName}>{path}</code>
</div>
<div>
Is exact: <code>{String(Boolean(exact))}</code>
</div>
{childRoutes && (
<div>
Child Routes:
<DebugJsonView src={childRoutes} />
</div>
)}
</li>
))}
</ul>
Expand Down
Loading