Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/ProjectBar/ProjectBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ProjectBar = ({ nameEditable = true }) => {
const loading = useSelector((state) => state.editor.loading);
const lastSavedTime = useSelector((state) => state.editor.lastSavedTime);
const offlineEnabled = useSelector((state) => state.editor.offlineEnabled);
const saveDisabled = useSelector((state) => state.editor.saveDisabled);
const projectOwner = isOwner(user, project);
const readOnly = useSelector((state) => state.editor.readOnly);
const isOnline = useIsOnline();
Expand All @@ -39,7 +40,7 @@ const ProjectBar = ({ nameEditable = true }) => {
type="tertiary"
/>
</div>
{!projectOwner && !readOnly && (
{!projectOwner && !readOnly && !saveDisabled && (
<div className="project-bar__btn-wrapper">
<SaveButton className="project-bar__btn btn--save" />
</div>
Expand Down
19 changes: 19 additions & 0 deletions src/components/ProjectBar/ProjectBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ describe("When logged in and user owns project", () => {
});
});

describe("When logged in and save is disabled", () => {
beforeEach(() => {
renderProjectBar({
editor: {
project,
saveDisabled: true,
lastSavedTime: new Date().getTime(),
},
auth: {
user,
},
});
});

test("Save button is not shown", () => {
expect(screen.queryByText("header.save")).not.toBeInTheDocument();
});
});

describe("When logged in and no project identifier", () => {
const projectWithoutId = { ...project, identifier: null };

Expand Down
6 changes: 6 additions & 0 deletions src/containers/WebComponentLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
setSenseHatAlwaysEnabled,
setOfflineEnabled,
setFriendlyErrorsEnabled,
setSaveDisabled,
setLoadRemixDisabled,
setReactAppApiEndpoint,
setScratchApiEndpoint,
Expand Down Expand Up @@ -72,6 +73,7 @@ const WebComponentLoader = (props) => {
loadCache = true, // Always use cache unless explicitly disabled
initialProject = null,
offlineEnabled = false,
saveDisabled = false,
} = props;
const dispatch = useDispatch();

Expand Down Expand Up @@ -204,6 +206,10 @@ const WebComponentLoader = (props) => {
dispatch(setOfflineEnabled(offlineEnabled));
}, [offlineEnabled, dispatch]);

useEffect(() => {
dispatch(setSaveDisabled(saveDisabled));
}, [saveDisabled, dispatch]);

useEffect(() => {
// Create a script element to save the existing Prism object if there is one
const script = document.createElement("script");
Expand Down
5 changes: 5 additions & 0 deletions src/redux/EditorSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const editorInitialState = {
scratchIframeProjectIdentifier: null,
friendlyErrorsEnabled: false,
friendlyError: null,
saveDisabled: false,
};

const isScratchProject = (state) =>
Expand Down Expand Up @@ -300,6 +301,9 @@ const EditorSlice = createSlice({
setFriendlyError: (state, action) => {
state.friendlyError = action.payload;
},
setSaveDisabled: (state, action) => {
state.saveDisabled = action.payload;
},
setLoadRemixDisabled: (state, action) => {
state.loadRemixDisabled = action.payload;
},
Expand Down Expand Up @@ -531,6 +535,7 @@ export const {
setSenseHatEnabled,
setFriendlyErrorsEnabled,
setLoadRemixDisabled,
setSaveDisabled,
setReactAppApiEndpoint,
setScratchApiEndpoint,
stopCodeRun,
Expand Down
7 changes: 7 additions & 0 deletions src/redux/EditorSlice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import reducer, {
scratchSaveFailed,
setFriendlyErrorsEnabled,
setFriendlyError,
setSaveDisabled,
} from "./EditorSlice";

const mockCreateRemix = jest.fn();
Expand Down Expand Up @@ -128,6 +129,12 @@ test("Action setOfflineEnabled correctly sets offlineEnabled", () => {
);
});

test("Action setSaveDisabled sets saveDisabled", () => {
const previousState = { saveDisabled: false };
const expectedState = { saveDisabled: true };
expect(reducer(previousState, setSaveDisabled(true))).toEqual(expectedState);
});

test("Action addProjectComponent adds component to project with correct content", () => {
const previousState = {
project: {
Expand Down
2 changes: 2 additions & 0 deletions src/web-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class WebComponent extends HTMLElement {
"load_cache",
"offline_enabled",
"friendly_errors_enabled",
"save_disabled",
];
}

Expand All @@ -101,6 +102,7 @@ class WebComponent extends HTMLElement {
"load_cache",
"offline_enabled",
"friendly_errors_enabled",
"save_disabled",
];
const jsonAttrs = [
"instructions",
Expand Down
Loading