-
Notifications
You must be signed in to change notification settings - Fork 7
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
feature/Issue-97: Implement the Edit on GitHub component #111
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
06e4f38
Issue-97: Create component and initial tests
DevLab2425 9517312
Issue-97: Create styles, story for component
DevLab2425 9ec7247
Issue-97: Initial implementation into page
DevLab2425 608293b
Issue-97: Sticky footer
DevLab2425 b256e57
Issue-97: Extend styles to be responsive
DevLab2425 0b47c1b
Issue-97: Revert work on footer
DevLab2425 aee7bbb
Issue-97: Clean up
DevLab2425 68618fe
Issue-97: Correct prettier errors
DevLab2425 1dea7f0
Issue-97: Include additional stories for variants
DevLab2425 f9bb454
Issue-97: Target edit view
DevLab2425 5036a35
Issue-97: Remove unnecessary label prop
DevLab2425 187b009
Issue-97: Restyle link and wrapper
DevLab2425 f250d47
Issue-97: Clean up story template
DevLab2425 2bf543b
Issue-97: Remove unnecessary comment
DevLab2425 1b672db
Issue-97: Resolve failing tests
DevLab2425 cc23014
Issue-97: Refactor guides implmentation
DevLab2425 ccfcbbf
Issue-97: Update story to remove label example
DevLab2425 ebb27b1
general refactoring to align with site information architecture
thescientist13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import styles from "./edit-on-github.module.css"; | ||
|
||
const REPO_PREFIX = "https://github.com/ProjectEvergreen/www.greenwoodjs.dev/edit/main/src/pages"; | ||
const MAX_ROUTE_DEPTH = 5; | ||
|
||
// one / two segments - /guides/ -> /guides/index.md | ||
// three (max) segments - /guides/getting-started/key-concepts/ -> /guides/getting-started/key-concepts.md | ||
function convertRouteToEditLink(route) { | ||
const segments = route.split("/"); | ||
|
||
// https://stackoverflow.com/a/5497365/417806 | ||
return segments.length === MAX_ROUTE_DEPTH | ||
? `${route.replace(/\/([^/]*)$/, "")}.md` | ||
: `${route}index.md`; | ||
} | ||
|
||
export default class EditOnGitHub extends HTMLElement { | ||
connectedCallback() { | ||
const label = "Edit on GitHub"; | ||
const route = this.getAttribute("route"); | ||
const href = `${REPO_PREFIX}${convertRouteToEditLink(route)}`; | ||
|
||
this.innerHTML = ` | ||
<div class="${styles.container}"> | ||
<a title="${label}" href="${href}" target="_blank"> | ||
${label} | ||
</a> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define("app-edit-on-github", EditOnGitHub); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.container { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.container a, | ||
.container a:active, | ||
.container a:focus, | ||
.container a:visited { | ||
padding: calc(var(--size-1) + var(--size-2)); | ||
border-radius: var(--size-px-2); | ||
background-color: var(--color-prism-bg); | ||
color: var(--color-accent); | ||
text-decoration: none; | ||
box-shadow: 0 0 calc(var(--size-1) + var(--size-2)) var(--size-px-00) var(--color-white); | ||
} | ||
|
||
.container a:hover { | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { expect } from "@esm-bundle/chai"; | ||
import "./edit-on-github.js"; | ||
|
||
// attributes | ||
const ROUTE = "/"; | ||
|
||
describe("Components/Edit on GitHub", () => { | ||
let editWrapper; | ||
let editLink; | ||
|
||
before(async () => { | ||
editWrapper = document.createElement("app-edit-on-github"); | ||
editWrapper.setAttribute("route", ROUTE); | ||
|
||
document.body.appendChild(editWrapper); | ||
|
||
await editWrapper.updateComplete; | ||
|
||
editLink = editWrapper.querySelector("a"); | ||
}); | ||
|
||
it("should not be undefined", () => { | ||
expect(editWrapper).not.equal(undefined); | ||
}); | ||
|
||
describe("Anchor tag to GitHub", () => { | ||
const EXPECTED_BASE = | ||
"https://github.com/ProjectEvergreen/www.greenwoodjs.dev/edit/main/src/pages/"; // including trailing | ||
|
||
it("should render an anchor tag targeting a new window", () => { | ||
expect(editLink).not.equal(undefined); | ||
expect(editLink.getAttribute("target")).equal("_blank"); | ||
}); | ||
|
||
it("should include a title attribute with the label 'Edit on GitHub'", () => { | ||
expect(editLink.getAttribute("title")).equal("Edit on GitHub"); | ||
}); | ||
|
||
it("should render the text 'Edit on GitHub'", () => { | ||
// use trim to allow backtick use in code | ||
expect(editLink.text.trim()).equal("Edit on GitHub"); | ||
}); | ||
|
||
describe("when the route is ONLY a slash", () => { | ||
it("should return 'index.md' for root-level ('/')", () => { | ||
const expected = `${EXPECTED_BASE}index.md`; | ||
|
||
expect(editLink.getAttribute("href")).equal(expected); | ||
}); | ||
}); | ||
|
||
describe("when the route IS NOT a directory", () => { | ||
let staticFilepath; | ||
|
||
before(async () => { | ||
staticFilepath = "/some/static/filename/"; // ie: "/guides/hosting/netlify/" | ||
|
||
editWrapper = document.createElement("app-edit-on-github"); | ||
editWrapper.setAttribute("route", staticFilepath); | ||
|
||
document.body.appendChild(editWrapper); | ||
|
||
await editWrapper.updateComplete; | ||
|
||
editLink = editWrapper.querySelector("a"); | ||
}); | ||
|
||
it("should include a href attribute which includes filepath.md", () => { | ||
const expected = `${EXPECTED_BASE}some/static/filename.md`; | ||
|
||
expect(editLink.getAttribute("href")).equal(expected); | ||
}); | ||
}); | ||
|
||
describe("when the route IS a directory", () => { | ||
let missingTrailingPath; | ||
|
||
before(async () => { | ||
missingTrailingPath = "/some/path/to/hosting/"; // ie: "/guides/hosting/" | ||
|
||
editWrapper = document.createElement("app-edit-on-github"); | ||
editWrapper.setAttribute("route", missingTrailingPath); | ||
|
||
document.body.appendChild(editWrapper); | ||
|
||
await editWrapper.updateComplete; | ||
|
||
editLink = editWrapper.querySelector("a"); | ||
}); | ||
|
||
it("should include a href attribute which includes index.md", () => { | ||
const expected = `${EXPECTED_BASE}some/path/to/hosting/index.md`; | ||
|
||
expect(editLink.getAttribute("href")).equal(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import "./edit-on-github.js"; | ||
|
||
export default { | ||
title: "Components/Edit on GitHub", | ||
component: "app-edit-on-github", | ||
}; | ||
|
||
const Template = (props) => { | ||
return ` | ||
<div style="margin:1em 0;"><p>Linked Route: ${props.args.route}</p></div> | ||
<app-edit-on-github route="${props.args.route}"></app-edit-on-github> | ||
`; | ||
}; | ||
|
||
export const PageRoot = Template.bind( | ||
{}, | ||
{ | ||
args: { | ||
route: "/guides/", | ||
}, | ||
}, | ||
); | ||
|
||
export const SectionRoot = Template.bind( | ||
{}, | ||
{ | ||
args: { | ||
route: "/guides/hosting/", | ||
}, | ||
}, | ||
); | ||
|
||
export const Section = Template.bind( | ||
{}, | ||
{ | ||
args: { | ||
route: "/guides/hosting/netlify/", | ||
}, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here re: needing to actually mock out content data like this?