Skip to content

Commit 7713f54

Browse files
fix: Data browser redirects to wrong class when changing app (#2526)
1 parent b37ca74 commit 7713f54

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

src/dashboard/Data/Browser/Browser.react.js

+45-17
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class Browser extends DashboardView {
100100
processedScripts: 0,
101101
};
102102

103+
this.addLocation = this.addLocation.bind(this);
104+
this.removeLocation = this.removeLocation.bind(this);
103105
this.prefetchData = this.prefetchData.bind(this);
104106
this.fetchData = this.fetchData.bind(this);
105107
this.fetchRelation = this.fetchRelation.bind(this);
@@ -186,29 +188,18 @@ class Browser extends DashboardView {
186188
}
187189

188190
componentDidMount() {
189-
if (window.localStorage) {
190-
const pathname = window.localStorage.getItem(BROWSER_LAST_LOCATION);
191-
window.localStorage.removeItem(BROWSER_LAST_LOCATION);
192-
if (pathname) {
193-
setTimeout(
194-
function () {
195-
this.props.navigate(pathname);
196-
}.bind(this)
197-
);
198-
}
199-
}
191+
this.addLocation(this.props.params.appId);
200192
}
201193

202194
componentWillUnmount() {
203-
if (window.localStorage) {
204-
window.localStorage.setItem(
205-
BROWSER_LAST_LOCATION,
206-
this.props.location.pathname + this.props.location.search
207-
);
208-
}
195+
this.removeLocation();
209196
}
210197

211198
componentWillReceiveProps(nextProps, nextContext) {
199+
if (nextProps.params.appId !== this.props.params.appId) {
200+
this.removeLocation();
201+
this.addLocation(nextProps.params.appId);
202+
}
212203
if (
213204
this.props.params.appId !== nextProps.params.appId ||
214205
this.props.params.className !== nextProps.params.className ||
@@ -228,6 +219,43 @@ class Browser extends DashboardView {
228219
}
229220
}
230221

222+
addLocation(appId) {
223+
if (window.localStorage) {
224+
let pathname = null;
225+
const newLastLocations = [];
226+
227+
const lastLocations = JSON.parse(window.localStorage.getItem(BROWSER_LAST_LOCATION));
228+
lastLocations?.forEach(lastLocation => {
229+
if (lastLocation.appId !== appId) {
230+
newLastLocations.push(lastLocation);
231+
} else {
232+
pathname = lastLocation.location;
233+
}
234+
});
235+
236+
window.localStorage.setItem(BROWSER_LAST_LOCATION, JSON.stringify(newLastLocations));
237+
if (pathname) {
238+
setTimeout(
239+
function () {
240+
this.props.navigate(pathname);
241+
}.bind(this)
242+
);
243+
}
244+
}
245+
}
246+
247+
removeLocation() {
248+
if (window.localStorage) {
249+
const lastLocation = {
250+
appId: this.props.params.appId,
251+
location: `${this.props.location.pathname}${this.props.location.search}`,
252+
};
253+
const currentLastLocation = JSON.parse(window.localStorage.getItem(BROWSER_LAST_LOCATION));
254+
const updatedLastLocation = [...(currentLastLocation || []), lastLocation];
255+
window.localStorage.setItem(BROWSER_LAST_LOCATION, JSON.stringify(updatedLastLocation));
256+
}
257+
}
258+
231259
async prefetchData(props, context) {
232260
const filters = this.extractFiltersFromQuery(props);
233261
const { className, entityId, relationName } = props.params;

0 commit comments

Comments
 (0)