Skip to content

Commit

Permalink
feat: added Edit this page CTA to non-component pages
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Sep 28, 2023
1 parent 322c80d commit ad358f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
15 changes: 12 additions & 3 deletions www/src/components/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ function Layout({
title
}
}
allSitePage {
nodes {
component
}
}
}
`);

const currentURL = typeof window !== 'undefined' ? window.location.pathname.split('/')[2] : '';
const filteredData = data.allSitePage.nodes.filter(item => !item.component.includes('components'));
const elementWithLayout = filteredData.find(item => item.component.includes(currentURL))?.component;
const componentName = elementWithLayout?.split('src')[1];
const foundationLinkBase = `https://github.com/openedx/paragon/blob/master/www/src${componentName}`;

return (
<div className="d-flex flex-column">
<Header
Expand All @@ -93,9 +104,7 @@ function Layout({
<Container size="md">
<hr />
<Stack direction="horizontal" gap={2}>
{isMdx && (
<PageEditBtn className="mb-5" githubEditPath={githubEditPath ?? ''} />
)}
<PageEditBtn className="mb-5" githubEditPath={githubEditPath || foundationLinkBase} />
<LeaveFeedback className="mb-5" />
</Stack>
</Container>
Expand Down
14 changes: 11 additions & 3 deletions www/src/pages/insights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ const {
lastModified: analysisLastUpdated,
} = dependentProjectsAnalysis;

interface TabsDataType {
export interface TabsDataType {
components: string[],
hooks: string[],
utils: string[],
icons: string[],
}

export default function InsightsPage({ pageContext: { tab } }: { pageContext: { tab: string } }) {
export interface InsightsPageTypes {
pageContext: {
tab: string,
githubEditPath: string
}
}

export default function InsightsPage({ pageContext: { tab, githubEditPath } }: InsightsPageTypes) {
const { settings } = useContext(SettingsContext);
const { paragonTypes = {}, isParagonIcon = () => false } = useContext(InsightsContext) as IInsightsContext;
const {
Expand All @@ -61,7 +68,7 @@ export default function InsightsPage({ pageContext: { tab } }: { pageContext: {
}
};
return (
<Layout isAutoToc tab={tab}>
<Layout isAutoToc tab={tab} githubEditPath={githubEditPath}>
{/* eslint-disable-next-line react/jsx-pascal-case */}
<SEO title="Usage Insights" />
<Container size={settings.containerWidth} className="py-5">
Expand Down Expand Up @@ -113,5 +120,6 @@ export default function InsightsPage({ pageContext: { tab } }: { pageContext: {
InsightsPage.propTypes = {
pageContext: PropTypes.shape({
tab: PropTypes.oneOf(Object.values(INSIGHTS_TABS)),
githubEditPath: PropTypes.string,
}).isRequired,
};
2 changes: 1 addition & 1 deletion www/utils/createPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function createPages(graphql, actions, reporter) {
createPage({
path: pagePath,
component: require.resolve('../src/pages/insights.tsx'),
context: { tab },
context: { tab, githubEditPath: 'https://github.com/openedx/paragon/blob/master/www/src/pages/insights.tsx' },
});
});

Expand Down

0 comments on commit ad358f6

Please sign in to comment.