Skip to content

Commit

Permalink
Fix link to your projects page (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
loiswells97 authored Dec 3, 2024
1 parent 96a2fcd commit 368db16
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

## [0.28.11] - 2024-12-03

### Fixed

- Link to "Your projects" page (#1149)

## [0.28.10] - 2024-11-29

### Fixed
Expand Down Expand Up @@ -995,7 +1001,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Events in Web Component indicating whether Mission Zero criteria have been met (#113)

[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.28.10...HEAD
[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.28.11...HEAD
[0.28.11]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.11
[0.28.10]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.10
[0.28.9]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.9
[0.28.8]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.28.8
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raspberrypifoundation/editor-ui",
"version": "0.28.10",
"version": "0.28.11",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.8",
Expand Down
12 changes: 7 additions & 5 deletions src/components/Menus/Sidebar/ProjectsPanel/ProjectsPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import { MOBILE_MEDIA_QUERY } from "../../../../utils/mediaQueryBreakpoints";
import { useMediaQuery } from "react-responsive";
import SaveStatus from "../../../SaveStatus/SaveStatus";
import DesignSystemButton from "../../../DesignSystemButton/DesignSystemButton";
import { navigateToProjectsPageEvent } from "../../../../events/WebComponentCustomEvents";

const ProjectsPanel = () => {
const {
t,
i18n: { language: locale },
} = useTranslation();
const { t } = useTranslation();

const isLoggedIn = useSelector((state) => state?.auth?.user);
const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY });
Expand All @@ -35,14 +33,18 @@ const ProjectsPanel = () => {
</>
);

const navigateToProjectsPage = () => {
document.dispatchEvent(navigateToProjectsPageEvent);
};

return (
<SidebarPanel
heading={t("projectsPanel.projects")}
Button={() =>
isLoggedIn && (
<DesignSystemButton
className="btn--primary projects-panel__your-projects-button"
href={`/${locale}/projects`}
onClick={navigateToProjectsPage}
text={t("projectsPanel.yourProjectsButton")}
/>
)
Expand Down
16 changes: 16 additions & 0 deletions src/components/Menus/Sidebar/ProjectsPanel/ProjectsPanel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { MemoryRouter } from "react-router-dom";

import ProjectsPanel from "./ProjectsPanel";

document.dispatchEvent = jest.fn();

const initialState = {
editor: {
project: {
Expand Down Expand Up @@ -66,6 +68,20 @@ describe("Projects Panel", () => {
screen.queryByText("projectsPanel.yourProjectsButton"),
).toBeInTheDocument();
});

test("Clicking projects button dispatches navigateToProjectsPageEvent", () => {
const projectsPageButton = screen.getByText(
"projectsPanel.yourProjectsButton",
);
projectsPageButton.click();
expect(document.dispatchEvent).toHaveBeenCalledWith(
new CustomEvent("editor-navigateToProjectsPageEvent", {
bubbles: true,
cancelable: false,
composed: true,
}),
);
});
});

describe("When not read only", () => {
Expand Down
4 changes: 4 additions & 0 deletions src/events/WebComponentCustomEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const webComponentCustomEvent = (type, detail) =>

export const codeChangedEvent = webComponentCustomEvent("editor-codeChanged");

export const navigateToProjectsPageEvent = webComponentCustomEvent(
"editor-navigateToProjectsPage",
);

export const projectIdentifierChangedEvent = (detail) =>
webComponentCustomEvent("editor-projectIdentifierChanged", detail);

Expand Down

0 comments on commit 368db16

Please sign in to comment.