From 9dbe6368e6c82c00d91e2e83541b3812e8bf13b4 Mon Sep 17 00:00:00 2001 From: Gandharv Date: Thu, 28 Apr 2022 16:46:27 +0530 Subject: [PATCH] fix: able to edit app post version released (#2915) * fix: able to edit app post version released * feat: make datasources & queries realtime --- frontend/src/Editor/Editor.jsx | 42 +++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 634abda34a..b949a8683c 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -221,6 +221,11 @@ class Editor extends React.Component { initEventListeners() { document.addEventListener('mousemove', this.onMouseMove); document.addEventListener('mouseup', this.onMouseUp); + this.socket?.addEventListener('message', (event) => { + if (event.data === 'versionReleased') this.fetchApp(); + else if (event.data === 'dataQueriesChanged') this.fetchDataQueries(); + else if (event.data === 'dataSourcesChanged') this.fetchDataSources(); + }); } componentWillUnmount() { @@ -388,12 +393,23 @@ class Editor extends React.Component { }; dataSourcesChanged = () => { - this.fetchDataSources(); + this.socket.send( + JSON.stringify({ + event: 'events', + data: { message: 'dataSourcesChanged', appId: this.state.appId }, + }) + ); }; dataQueriesChanged = () => { - this.fetchDataQueries(); - this.setState({ addingQuery: false }); + this.setState({ addingQuery: false }, () => { + this.socket.send( + JSON.stringify({ + event: 'events', + data: { message: 'dataQueriesChanged', appId: this.state.appId }, + }) + ); + }); }; switchSidebarTab = (tabIndex) => { @@ -792,12 +808,22 @@ class Editor extends React.Component { }; onVersionRelease = (versionId) => { - this.setState({ - app: { - ...this.state.app, - current_version_id: versionId, + this.setState( + { + app: { + ...this.state.app, + current_version_id: versionId, + }, }, - }); + () => { + this.socket.send( + JSON.stringify({ + event: 'events', + data: { message: 'versionReleased', appId: this.state.appId }, + }) + ); + } + ); }; onZoomChanged = (zoom) => {