From b276587c425804a0489ab93f1de2b320e4427e0e Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 15 Apr 2021 11:04:58 +0200 Subject: [PATCH] Merge pull request #3911 from overleaf/ae-share-modal-link-sharing Only use project sharing data from the websocket connection GitOrigin-RevId: 4549a6379dfebb00581ca4ddf276654fbbb3701d --- .../components/link-sharing.js | 9 ++++---- .../components/share-project-modal.test.js | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/share-project-modal/components/link-sharing.js b/services/web/frontend/js/features/share-project-modal/components/link-sharing.js index e18c112bc7..5d2be9bcb8 100644 --- a/services/web/frontend/js/features/share-project-modal/components/link-sharing.js +++ b/services/web/frontend/js/features/share-project-modal/components/link-sharing.js @@ -13,7 +13,7 @@ import CopyLink from '../../../shared/components/copy-link' export default function LinkSharing() { const [inflight, setInflight] = useState(false) - const { monitorRequest, updateProject } = useShareProjectContext() + const { monitorRequest } = useShareProjectContext() const project = useProjectContext() @@ -23,15 +23,16 @@ export default function LinkSharing() { setInflight(true) monitorRequest(() => setProjectAccessLevel(project, publicAccesLevel)) .then(() => { - // TODO: ideally this would use the response from the server - updateProject({ publicAccesLevel }) + // NOTE: not calling `updateProject` here as it receives data via + // project:publicAccessLevel:changed and project:tokens:changed + // over the websocket connection // TODO: eventTracking.sendMB('project-make-token-based') when publicAccesLevel is 'tokenBased' }) .finally(() => { setInflight(false) }) }, - [monitorRequest, project, updateProject] + [monitorRequest, project] ) switch (project.publicAccesLevel) { diff --git a/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js b/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js index 93c252a277..251160a305 100644 --- a/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js +++ b/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js @@ -736,6 +736,21 @@ describe('', function () { it('handles switching between access levels', async function () { fetchMock.post('express:/project/:projectId/settings/admin', 204) + let watchCallbacks = {} + + const ideWithProject = project => { + return { + $scope: { + $watch: (path, callback, deep) => { + watchCallbacks[path] = callback + return () => {} + }, + $applyAsync: () => {}, + project + } + } + } + render( ', function () { publicAccessLevel: 'tokenBased' }) + // NOTE: updating the scoped project data manually, + // as the project data is usually updated via the websocket connection + watchCallbacks.project({ ...project, publicAccesLevel: 'tokenBased' }) + await screen.findByText('Link sharing is on') const disableButton = await screen.findByRole('button', { name: 'Turn off link sharing' @@ -770,6 +789,10 @@ describe('', function () { publicAccessLevel: 'private' }) + // NOTE: updating the scoped project data manually, + // as the project data is usually updated via the websocket connection + watchCallbacks.project({ ...project, publicAccesLevel: 'private' }) + await screen.findByText( 'Link sharing is off, only invited users can view this project.' )