From 76f869b7a2ee927cbbd04939904e8fa281aa35e0 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:04:14 -0700 Subject: [PATCH] feat: use scratchFetch BREAKING CHANGE: servers must accept new header x-projectid --- src/containers/gui.jsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/containers/gui.jsx b/src/containers/gui.jsx index 0081c83c5..c8f075e48 100644 --- a/src/containers/gui.jsx +++ b/src/containers/gui.jsx @@ -40,15 +40,31 @@ import cloudManagerHOC from '../lib/cloud-manager-hoc.jsx'; import GUIComponent from '../components/gui/gui.jsx'; import {setIsScratchDesktop} from '../lib/isScratchDesktop.js'; +const {RequestMetadata, setMetadata, unsetMetadata} = storage.scratchFetch; + +const setProjectIdMetadata = projectId => { + // If project ID is '0' or zero, it's not a real project ID. In that case, remove the project ID metadata. + // Same if it's null undefined. + if (projectId && projectId !== '0') { + setMetadata(RequestMetadata.ProjectId, projectId); + } else { + unsetMetadata(RequestMetadata.ProjectId); + } +}; + class GUI extends React.Component { componentDidMount () { setIsScratchDesktop(this.props.isScratchDesktop); this.props.onStorageInit(storage); this.props.onVmInit(this.props.vm); + setProjectIdMetadata(this.props.projectId); } componentDidUpdate (prevProps) { - if (this.props.projectId !== prevProps.projectId && this.props.projectId !== null) { - this.props.onUpdateProjectId(this.props.projectId); + if (this.props.projectId !== prevProps.projectId) { + if (this.props.projectId !== null) { + this.props.onUpdateProjectId(this.props.projectId); + } + setProjectIdMetadata(this.props.projectId); } if (this.props.isShowingProject && !prevProps.isShowingProject) { // this only notifies container when a project changes from not yet loaded to loaded