From 930d46cbef5c0949fa4ab0b15790ef1492cd784e Mon Sep 17 00:00:00 2001 From: zwiterrion Date: Fri, 11 Oct 2024 10:33:30 +0200 Subject: [PATCH] enhance daemon to manage path changs --- .../javascript/src/components/Drafts/DraftEditor.js | 13 +++++++++---- .../src/components/Drafts/DraftEditorSignal.js | 1 + .../javascript/src/pages/RouteDesigner/Designer.js | 6 +++++- .../javascript/src/pages/RouteDesigner/index.js | 7 +------ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/otoroshi/javascript/src/components/Drafts/DraftEditor.js b/otoroshi/javascript/src/components/Drafts/DraftEditor.js index d4d83070a..1347c02c4 100644 --- a/otoroshi/javascript/src/components/Drafts/DraftEditor.js +++ b/otoroshi/javascript/src/components/Drafts/DraftEditor.js @@ -6,10 +6,10 @@ import { QueryClientProvider, } from 'react-query' import { nextClient } from '../../services/BackOfficeServices' -import { Button } from '../Button' -import { draftSignal, draftVersionSignal } from './DraftEditorSignal' +import { draftSignal, draftVersionSignal, resetDraftSignal } from './DraftEditorSignal' import { useSignalValue } from 'signals-react-safe' import { PillButton } from '../PillButton' +import { withRouter } from 'react-router-dom' const queryClient = new QueryClient() @@ -117,13 +117,15 @@ export function DraftEditorContainer(props) { } -export class DraftStateDaemon extends React.Component { +export const DraftStateDaemon = withRouter(class _ extends React.Component { state = { initialized: false } componentDidMount() { + resetDraftSignal() + this.unsubscribe = draftVersionSignal.subscribe(() => { const { value, setValue } = this.props @@ -164,6 +166,9 @@ export class DraftStateDaemon extends React.Component { } } } + if(prevProps.history.location.pathname !== this.props.history.location.pathname) { + resetDraftSignal() + } } componentWillUnmount() { @@ -174,4 +179,4 @@ export class DraftStateDaemon extends React.Component { render() { return null } -} \ No newline at end of file +}) \ No newline at end of file diff --git a/otoroshi/javascript/src/components/Drafts/DraftEditorSignal.js b/otoroshi/javascript/src/components/Drafts/DraftEditorSignal.js index 13d0e4775..2f9435ff0 100644 --- a/otoroshi/javascript/src/components/Drafts/DraftEditorSignal.js +++ b/otoroshi/javascript/src/components/Drafts/DraftEditorSignal.js @@ -16,6 +16,7 @@ export const draftVersionSignal = signal(DRAFT_VERSION_SIGNAL_TEMPLATE) export const draftSignal = signal(DRAFT_SIGNAL_TEMPLATE) export const resetDraftSignal = () => { + console.log('reset') draftSignal.value = DRAFT_SIGNAL_TEMPLATE draftVersionSignal.value = DRAFT_VERSION_SIGNAL_TEMPLATE } \ No newline at end of file diff --git a/otoroshi/javascript/src/pages/RouteDesigner/Designer.js b/otoroshi/javascript/src/pages/RouteDesigner/Designer.js index 550f482d6..527f88a02 100644 --- a/otoroshi/javascript/src/pages/RouteDesigner/Designer.js +++ b/otoroshi/javascript/src/pages/RouteDesigner/Designer.js @@ -1609,7 +1609,11 @@ class Designer extends React.Component { { - this.setState({ route, selectedNode: undefined }, () => this.loadData(this.state.route)) + this.props.setValue(route) + this.setState({ + route, + selectedNode: undefined + }, () => this.loadData(this.state.route)) }} /> { const { routeId } = this.props.match.params || { routeId: undefined };