Skip to content

Commit

Permalink
feat: added logic for Edit page button
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Sep 11, 2023
1 parent 604acb7 commit cd7e49d
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Breadcrumb/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Breadcrumbs'
title: 'Breadcrumb'
type: 'component'
components:
- Breadcrumb
Expand Down
2 changes: 1 addition & 1 deletion src/Button/button-group.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Button Group'
title: 'ButtonGroup'
type: 'component'
components:
- ButtonGroup
Expand Down
4 changes: 4 additions & 0 deletions src/DataTable/dataviews.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
title: 'Data views'
type: 'component'
components:
- DataTable
- DataTableTable
- TableControlBar
- TableFooter
- Table
- TableCell
- TableHeaderCell
Expand Down
2 changes: 1 addition & 1 deletion src/DataTable/tablefilters.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Table Filters'
title: 'TableFilters'
type: 'component'
components:
- TextFilter
Expand Down
2 changes: 1 addition & 1 deletion src/Form/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Forms'
title: 'Form'
type: 'component'
components:
- Form
Expand Down
2 changes: 1 addition & 1 deletion src/Form/input-group.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Input Group'
title: 'InputGroup'
type: 'component'
categories:
- Forms
Expand Down
2 changes: 1 addition & 1 deletion src/Overlay/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Overlays'
title: 'Overlay'
type: 'component'
components:
- Overlay
Expand Down
2 changes: 1 addition & 1 deletion src/PageBanner/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Page Banner'
title: 'PageBanner'
type: 'component'
components:
- PageBanner
Expand Down
2 changes: 1 addition & 1 deletion src/ProgressBar/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Progress Bar'
title: 'ProgressBar'
type: 'component'
components:
- ProgressBar
Expand Down
22 changes: 0 additions & 22 deletions www/src/components/PageEditBtn.tsx

This file was deleted.

35 changes: 35 additions & 0 deletions www/src/components/PageEditBtn/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const BASE_PATH = 'https://github.com/openedx/paragon/edit/master/src';

const componentsNamesMap = {
'AlertModal': 'Modal/alert-modal.mdx',

Check failure on line 4 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'AlertModal' found
'ButtonGroup': 'Button/button-group.mdx',

Check failure on line 5 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'ButtonGroup' found
'Data views': 'DataTable/dataviews.mdx',
'Form.Autosuggest': 'Form/form-autosuggest.mdx',
'Form.Checkbox': 'Form/form-checkbox.mdx',
'Form.Control': 'Form/form-control.mdx',
'Form.Control.Feedback': 'Form/form-control-feedback.mdx',
'Form.Group': 'Form/form-group.mdx',
'Form.Label': 'Form/form-label.mdx',
'Form.Radio': 'Form/form-radio.mdx',
'Form.Switch': 'Form/form-switch.mdx',
'FullscreenModal': 'Modal/fullscreen-modal.mdx',

Check failure on line 15 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'FullscreenModal' found
'InputGroup': 'Form/input-group.mdx',

Check failure on line 16 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'InputGroup' found
'MarketingModal': 'Modal/marketing-modal.mdx',

Check failure on line 17 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'MarketingModal' found
'ModalDialog': 'Modal/modal-dialog.mdx',

Check failure on line 18 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'ModalDialog' found
'ModalLayer': 'Modal/modal-layer.mdx',

Check failure on line 19 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'ModalLayer' found
'ModalPopup': 'Modal/modal-popup.mdx',

Check failure on line 20 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'ModalPopup' found
'OverflowScroll': 'OverflowScroll/OverflowScroll.mdx',

Check failure on line 21 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'OverflowScroll' found
'SelectMenu': 'Menu/select-menu.md',

Check failure on line 22 in www/src/components/PageEditBtn/constants.js

View workflow job for this annotation

GitHub Actions / tests

Unnecessarily quoted property 'SelectMenu' found
'StandardModal': 'Modal/standard-modal.mdx',
'TableControlBar': 'DataTable/tablecontrolbar.mdx',
'TableFilters': 'DataTable/tablefilters.mdx',
'TableFooter': 'DataTable/tablefooter.mdx',
'useArrowKeyNavigation': 'hooks/useArrowKeyNavigation.mdx',
'useIndexOfLastVisibleChild': 'hooks/useIndexOfLastVisibleChild.mdx',
'useIsVisible': 'hooks/useIsVisible.mdx',
'useOverflowScroll': 'OverflowScroll/useOverflowScroll.mdx',
'useToggle': 'hooks/useToggle.mdx',
'useWindowSize': 'hooks/useWindowSize.mdx',
};

export { BASE_PATH, componentsNamesMap };
35 changes: 35 additions & 0 deletions www/src/components/PageEditBtn/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Hyperlink } from '~paragon-react';
import { BASE_PATH, componentsNamesMap } from './constants';

function PageEditBtn({ componentTitle, ...props }) {
const pageEditUrl = componentsNamesMap[componentTitle]
? `${BASE_PATH}/${componentsNamesMap[componentTitle]}`
: `${BASE_PATH}/${componentTitle}/README.md`;

const handlePageEditBtnClick = () => {
global.analytics.track('openedx.paragon.docs.page_edit.clicked');
};

return (
<Button
size="sm"
as={Hyperlink}
destination={pageEditUrl}
variant="tertiary"
onClick={handlePageEditBtnClick}
target="_blank"
rel="noopener noreferrer"
{...props}
>
Edit this page
</Button>
);
}

PageEditBtn.propTypes = {
componentTitle: PropTypes.string.isRequired,
};

export default PageEditBtn;
3 changes: 2 additions & 1 deletion www/src/templates/component-page-template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function PageTemplate({
const usageInsightsUrl = 'usage-insights';

const sortedComponentNames = mdx.frontmatter?.components || [];
const componentTitle = mdx.frontmatter.title;
const filteredComponentsUsageInsights = componentsUsageInsights.map(componentName => componentName.replace(/\./g, ''));
const isUsageInsights = (sortedComponentNames as []).some(value => filteredComponentsUsageInsights.includes(value));

Expand Down Expand Up @@ -142,7 +143,7 @@ export default function PageTemplate({
<div className="d-flex justify-content-between align-items-start">
<h1 className="mb-4">{mdx.frontmatter.title}</h1>
<Stack direction="horizontal" gap={3}>
<PageEditBtn />
<PageEditBtn componentTitle={componentTitle} />
<LeaveFeedback />
</Stack>
</div>
Expand Down

0 comments on commit cd7e49d

Please sign in to comment.