Skip to content

Commit

Permalink
fix: Make sure currentView value isn't being reset
Browse files Browse the repository at this point in the history
Add in a reference to previous results value so we can ensure it has changed before resetting currentView to Table
  • Loading branch information
OiNutter committed Sep 7, 2021
1 parent b8de6ea commit 34e617d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/ResultsWindow.tsx
Expand Up @@ -60,20 +60,30 @@ const ResultsWindow: FunctionComponent<ResultsWindowProps> = ({
const error = results?.error;
const currentScript = results?.script;

const previousResultsRef = useRef();
const previousResults = previousResultsRef.current;

let rows: Array<{} | string> = [];
let columns: Array<IColumn> = [];

if (currentResults) {
const processed = ResultsProcessor.process(currentResults);

if (Array.isArray(processed)) {
if (currentView !== ResultsView.Table) {
if (
currentView !== ResultsView.Table &&
currentResults != previousResults
)
setCurrentView(ResultsView.Table);
}

[columns, rows] = processed as [Array<IColumn>, Array<{}>];
}
}

useEffect(() => {
previousResultsRef.current = currentResults;
});

let viewOptions: ICommandBarItemProps[] = [];
if (Array.isArray(currentResults) && currentResults.length > 0) {
viewOptions = [
Expand Down Expand Up @@ -238,7 +248,7 @@ const ResultsWindow: FunctionComponent<ResultsWindowProps> = ({
) : (
<>
{typeof currentResults === "string" ||
currentView == ResultsView.Raw ? (
currentView === ResultsView.Raw ? (
<pre className="raw-results-view">
{currentResults ? stringify(currentResults) : ""}
</pre>
Expand Down

0 comments on commit 34e617d

Please sign in to comment.