From ad358f635f6a199da0fe3418cd8f16c202ed5cb9 Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Thu, 28 Sep 2023 11:27:24 +0300 Subject: [PATCH] feat: added Edit this page CTA to non-component pages --- www/src/components/PageLayout.tsx | 15 ++++++++++++--- www/src/pages/insights.tsx | 14 +++++++++++--- www/utils/createPages.js | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/www/src/components/PageLayout.tsx b/www/src/components/PageLayout.tsx index 932eaf4fe2..ae8a1fe070 100644 --- a/www/src/components/PageLayout.tsx +++ b/www/src/components/PageLayout.tsx @@ -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 (

- {isMdx && ( - - )} + diff --git a/www/src/pages/insights.tsx b/www/src/pages/insights.tsx index 44128bd1b6..a2d8626c89 100644 --- a/www/src/pages/insights.tsx +++ b/www/src/pages/insights.tsx @@ -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 { @@ -61,7 +68,7 @@ export default function InsightsPage({ pageContext: { tab } }: { pageContext: { } }; return ( - + {/* eslint-disable-next-line react/jsx-pascal-case */} @@ -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, }; diff --git a/www/utils/createPages.js b/www/utils/createPages.js index 394fbea1e0..3e027132fc 100644 --- a/www/utils/createPages.js +++ b/www/utils/createPages.js @@ -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' }, }); });