Skip to content

Commit

Permalink
Merge pull request #612 from coq-community/expanded-search-results
Browse files Browse the repository at this point in the history
Expanded search results
  • Loading branch information
rtetley authored Sep 11, 2023
2 parents dead809 + 2def129 commit 382ac37
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
7 changes: 5 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,15 @@
"command": "extension.coq.collapseAllQueries",
"title": "Collapse All",
"category": "Coq",
"icon": "$(collapse-all)"
"icon": "$(collapse-all)",
"enablement": "vscoq.hasSearchResults"
},
{
"command": "extension.coq.expandAllQueries",
"title": "Expand All",
"category": "Coq",
"icon": "$(expand-all)"
"icon": "$(expand-all)",
"enablement": "vscoq.hasSearchResults"
}
],
"menus": {
Expand Down Expand Up @@ -355,6 +357,7 @@
{
"command": "extension.coq.expandAllQueries",
"group": "navigation",
"enablement": "editorHasSelection",
"when": "view == vscoq.search && !vscoq.expandedQueries"
}
]
Expand Down
44 changes: 38 additions & 6 deletions client/search-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const defaultTab = {
type: QueryType.search,
data: []
} as SearchResultType,
error: undefined
error: undefined,
expanded: true
};

const defaultQueryPanelState = {
Expand Down Expand Up @@ -114,6 +115,18 @@ const app = () => {
ready();
}, []);

useEffect(() => {
const {tabs, currentTab} = queryPanelState;
if(tabs[currentTab].type === QueryType.search &&
(tabs[currentTab].result as SearchResultType).data.length) {
enableCollapseButton();
updateCollapseButton(tabs[currentTab].expanded!);
} else {
disableCollapseButton();
}

}, [queryPanelState]);

const ready = () => {
vscode.postMessage({
command: "ready",
Expand All @@ -140,8 +153,8 @@ const app = () => {
const newTabs = state.tabs.map(tab => {
if(tab.id === notification.id) {
//This is only for typescript, but should always be the case
if(tab.result.type === QueryType.search) {
const data = tab.result.data.concat([{name: notification.name, statement: notification.statement, collapsed: true}]);
if(tab.result.type === QueryType.search) {
const data = tab.result.data.concat([{name: notification.name, statement: notification.statement, collapsed: false}]);
return {...tab, result: {...tab.result, data: data}};
}
}
Expand Down Expand Up @@ -349,6 +362,25 @@ const app = () => {
});
};

const updateCollapseButton = (buttonStatus: boolean) => {
vscode.postMessage({
command: "toggleExpandButton",
value: buttonStatus
});
};

const enableCollapseButton = () => {
vscode.postMessage({
command: "enableCollapseButton"
});
};

const disableCollapseButton = () => {
vscode.postMessage({
command: "disableCollapseButton"
});
};

const copyNameToClipboard = (name: string) => {
vscode.postMessage({
command: "copySearchResult",
Expand All @@ -360,7 +392,7 @@ const app = () => {
setQueryPanelState(
state => {
const result = {type: QueryType.search, data: []} as SearchResultType;
const newTab : QueryTab[] = [{id: uuid(), title: "New Tab", pattern: "", result: result, type: QueryType.search}];
const newTab : QueryTab[] = [{id: uuid(), title: "New Tab", pattern: "", result: result, type: QueryType.search, expanded: true}];
return {currentTab: state.tabs.length, tabs: state.tabs.concat(newTab)};
},
(state) => saveState({state, history, historyIndex})
Expand Down Expand Up @@ -406,7 +438,7 @@ const app = () => {
type: QueryType.search,
data: data
} as SearchResultType;
return {...tab, result: result};
return {...tab, result: result, expanded: false};
}
return tab;
});
Expand All @@ -425,7 +457,7 @@ const app = () => {
type: "search",
data: data
} as SearchResultType;
return {...tab, result: result};
return {...tab, result: result, expanded: true};
}
return tab;
});
Expand Down
3 changes: 2 additions & 1 deletion client/search-ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export interface QueryTab {
pattern: string,
type: QueryType,
result: QueryResultType,
error?: QueryError
error?: QueryError,
expanded?: boolean
};
export type QueryPanelState = {
currentTab: number;
Expand Down
13 changes: 10 additions & 3 deletions client/src/panels/SearchViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,16 @@ export default class SearchViewProvider implements vscode.WebviewViewProvider {
vscode.window.showInformationMessage('Successfuly copied command ' + message.text + ' to clipboard.');
return;

case "toggleExpandButton":
const flag = (message.text === 'true');
vscode.commands.executeCommand('setContext', 'vscoq.expandedQueries', flag);
case "toggleExpandButton":
vscode.commands.executeCommand('setContext', 'vscoq.expandedQueries', message.value);
return;

case "enableCollapseButton":
vscode.commands.executeCommand('setContext', 'vscoq.hasSearchResults', true);
return;

case "disableCollapseButton":
vscode.commands.executeCommand('setContext', 'vscoq.hasSearchResults', false);
return;
}
}
Expand Down

0 comments on commit 382ac37

Please sign in to comment.