Skip to content

Commit 48f9419

Browse files
1143 hide project files panel for scratch projects (#1339)
closes RaspberryPiFoundation/digital-editor-issues#1143
1 parent 140da0a commit 48f9419

2 files changed

Lines changed: 49 additions & 11 deletions

File tree

src/components/Menus/Sidebar/Sidebar.jsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ import SidebarPanel from "./SidebarPanel";
2727

2828
const Sidebar = ({ options = [], plugins = [] }) => {
2929
const { t } = useTranslation();
30+
const projectType = useSelector((state) => state.editor.project.project_type);
31+
const projectImages = useSelector((state) => state.editor.project.image_list);
32+
const instructionsSteps = useSelector(
33+
(state) => state.instructions?.project?.steps,
34+
);
35+
const instructionsEditable = useSelector(
36+
(state) => state.editor.instructionsEditable,
37+
);
38+
const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY });
3039

3140
let menuOptions = [
3241
{
@@ -78,7 +87,12 @@ const Sidebar = ({ options = [], plugins = [] }) => {
7887
position: "bottom",
7988
panel: InfoPanel,
8089
},
81-
].filter((option) => options.includes(option.name));
90+
].filter((option) => {
91+
if (!options.includes(option.name)) return false;
92+
if (projectType === "code_editor_scratch" && option.name === "file")
93+
return false;
94+
return true;
95+
});
8296

8397
let pluginMenuOptions = useMemo(
8498
() =>
@@ -103,15 +117,6 @@ const Sidebar = ({ options = [], plugins = [] }) => {
103117

104118
menuOptions = [...menuOptions, ...pluginMenuOptions];
105119

106-
const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY });
107-
const projectImages = useSelector((state) => state.editor.project.image_list);
108-
const instructionsSteps = useSelector(
109-
(state) => state.instructions?.project?.steps,
110-
);
111-
const instructionsEditable = useSelector(
112-
(state) => state.editor.instructionsEditable,
113-
);
114-
115120
const removeOption = (optionName, depArray = []) => {
116121
if ((!depArray || depArray.length === 0) && options.includes(optionName)) {
117122
menuOptions.splice(

src/components/Menus/Sidebar/Sidebar.test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let images = [
1515
},
1616
];
1717

18-
const options = ["file", "images", "instructions"];
18+
const options = ["file", "images", "instructions", "info"];
1919

2020
describe("When project has images", () => {
2121
describe("and no instructions", () => {
@@ -411,3 +411,36 @@ describe("When plugins are provided", () => {
411411
});
412412
});
413413
});
414+
415+
describe("When the project type is code_editor_scratch", () => {
416+
beforeEach(() => {
417+
const mockStore = configureStore([]);
418+
const initialState = {
419+
editor: {
420+
project: {
421+
components: [],
422+
image_list: [],
423+
project_type: "code_editor_scratch",
424+
},
425+
instructionsEditable: false,
426+
},
427+
instructions: {},
428+
};
429+
const store = mockStore(initialState);
430+
render(
431+
<Provider store={store}>
432+
<div id="app">
433+
<Sidebar options={options} />
434+
</div>
435+
</Provider>,
436+
);
437+
});
438+
439+
test("Does not show file icon", () => {
440+
expect(screen.queryByTitle("sidebar.file")).not.toBeInTheDocument();
441+
});
442+
443+
test("Shows the info icon", () => {
444+
expect(screen.queryByTitle("sidebar.information")).toBeInTheDocument();
445+
});
446+
});

0 commit comments

Comments
 (0)