Skip to content

Commit 3df01bf

Browse files
committed
fix(query): use replaceIn to avoid mangling browser history
To ensure that the user retains a cleaner history of browsing through Flat Viewer, set query parameters with `replaceIn` when: repo-detail: - File/commit metadata is loaded json-detail-container: - A file is loaded and a tab chosen - `onGridChange()` is invoked The latter bears noting, as this means we will no longer retain a user's history of manipulating the grid. Given that `onGridChange()` is invoked when data is loaded into the grid, we think that ensuring a cleaner overall history is more important to the user than retaining the specific click history for grid manipuation, which the user may find difficult to follow anyway.
1 parent 5d6171d commit 3df01bf

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/components/json-detail-container.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function JSONDetail(props: JSONDetailProps) {
4242
query.tab && data.find((d) => d.key === query.tab)
4343
? query.tab
4444
: (data.find((d) => d.key) || {}).key;
45-
setQuery({ tab });
45+
setQuery({ tab }, "replaceIn");
4646
},
4747
}
4848
);
@@ -89,11 +89,14 @@ export function JSONDetail(props: JSONDetailProps) {
8989
return;
9090
}
9191

92-
setQuery({
93-
sort: newState.sort.join(","),
94-
stickyColumnName: newState.stickyColumnName,
95-
filters: encodeFilterString(newState.filters),
96-
});
92+
setQuery(
93+
{
94+
sort: newState.sort.join(","),
95+
stickyColumnName: newState.stickyColumnName,
96+
filters: encodeFilterString(newState.filters),
97+
},
98+
"replaceIn"
99+
);
97100
};
98101

99102
React.useEffect(() => {

src/components/repo-detail.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function RepoDetail(props: RepoDetailProps) {
4949
{
5050
onSuccess: (data) => {
5151
if (!data.length) return;
52-
setFilename(filename || data[0]);
52+
setFilename(filename || data[0], "replaceIn");
5353
},
5454
}
5555
);
@@ -73,10 +73,10 @@ export function RepoDetail(props: RepoDetailProps) {
7373
duration: 4000,
7474
}
7575
);
76-
setSelectedSha(mostRecentCommitSha);
76+
setSelectedSha(mostRecentCommitSha, "replaceIn");
7777
}
7878
} else {
79-
setSelectedSha(mostRecentCommitSha);
79+
setSelectedSha(mostRecentCommitSha, "replaceIn");
8080
}
8181
}
8282
},

0 commit comments

Comments
 (0)