-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search in workspace folder #204
Changes from 8 commits
d8c8be2
7f0923a
4080264
c75e30e
a135b4a
dc946cc
26a6c64
8982eae
5ef34f4
ce3ec85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package model.frontend | ||
|
||
import play.api.libs.json._ | ||
import services.index.WorkspaceSearchContextParams | ||
|
||
case class DropdownOption(label: String, value: String) | ||
|
||
|
@@ -16,6 +17,12 @@ case class DateChip(name: String, template: String) extends Chip | |
case class ExclusiveDateChip(name: String, template: String) extends Chip | ||
case class DropdownChip(name: String, options: List[DropdownOption], template: String) extends Chip | ||
|
||
case class WorkspaceFolderChip(name: String, t: String, workspaceId: String, folderId: String) | ||
|
||
object WorkspaceFolderChip { | ||
implicit val workspaceFolderChip = Json.format[WorkspaceFolderChip] | ||
} | ||
|
||
object Chip { | ||
private val plainChipFormat = Json.format[TextChip] | ||
private val dateChipFormat = Json.format[DateChip] | ||
|
@@ -46,14 +53,29 @@ object Chip { | |
} | ||
} | ||
|
||
case class ParsedChips (query: String, workspace: Option[WorkspaceSearchContextParams]) | ||
|
||
object Chips { | ||
// TODO - when the index supports attempts we can uncomment these lines to make this attempty | ||
//def parseQueryString(q: String): Attempt[String] = { | ||
def parseQueryString(q: String): String = { | ||
def parseQueryString(q: String): ParsedChips = { | ||
//Attempt.catchNonFatal { | ||
val parsedQ = Json.parse(q) | ||
// find WorkspaceSearchContextParams | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be worth adding a slightly more detailed comment here explaning what's happening - i.e extracting the workspace parameters, then ignoring them in the next bit |
||
val workspaceFolder = parsedQ match { | ||
case JsArray(value) => value.collectFirst { | ||
case JsObject(o) if o.get("t").map(_.validate[String].get).get == "workspace_folder" => | ||
WorkspaceSearchContextParams(o.get("workspaceId").map(_.validate[String].get).get, o.get("folderId").map(_.validate[String].get).get) | ||
} | ||
case _ => None | ||
} | ||
|
||
Json.parse(q) match { | ||
case JsArray(v) => v.toList.map { | ||
val query = parsedQ match { | ||
case JsArray(v) => v.toList.filter { | ||
// remove workspace_folder chips | ||
case JsObject(o) if o.get("t").map(_.validate[String].get).get == "workspace_folder" => false | ||
case _ => true | ||
}.map { | ||
// When typing a new chip, we end up with a dangling + which is illegal in the ES query syntax. | ||
// This doesn't matter if you start a chip before an existing term or in between two existing. | ||
// In that case it will be parsed as the boolean operator attached to the subsequent term. | ||
|
@@ -78,6 +100,7 @@ object Chips { | |
}.mkString(" ") | ||
case _ => throw new UnsupportedOperationException("Outer json type must be an array") | ||
} | ||
ParsedChips(query, workspaceFolder) | ||
// } { | ||
// case s: Exception => ClientFailure(s"Invalid query: ${s.getMessage}") | ||
//} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ import { reprocessBlob } from '../../actions/workspaces/reprocessBlob'; | |
import { DeleteModal, DeleteStatus } from './DeleteModal'; | ||
import { PartialUser } from '../../types/User'; | ||
import { getMyPermissions } from '../../actions/users/getMyPermissions'; | ||
import buildLink from '../../util/buildLink'; | ||
import history from '../../util/history'; | ||
|
||
|
||
type Props = ReturnType<typeof mapStateToProps> | ||
|
@@ -542,7 +544,7 @@ class WorkspacesUnconnected extends React.Component<Props, State> { | |
{key : "copyFilePath", content: copyFilePathContent, icon: "copy"}, | ||
// or 'pencil alternate' | ||
{ key: "rename", content: "Rename", icon: "pen square" }, | ||
{ key: "remove", content: "Remove from workspace", icon: "trash" } | ||
{ key: "remove", content: "Remove from workspace", icon: "trash" }, | ||
]; | ||
|
||
if (entry.data.addedBy.username === currentUser.username && isWorkspaceLeaf(entry.data)) { | ||
|
@@ -551,6 +553,8 @@ class WorkspacesUnconnected extends React.Component<Props, State> { | |
|
||
if (isWorkspaceLeaf(entry.data)){ | ||
items.push({ key: "reprocess", content: "Reprocess source file", icon: "redo" }); | ||
} else { | ||
items.push({ key: "search", content: "Search in folder", icon: "search" }) | ||
} | ||
|
||
return <DetectClickOutside onClickOutside={this.closeContextMenu}> | ||
|
@@ -594,6 +598,27 @@ class WorkspacesUnconnected extends React.Component<Props, State> { | |
if (menuItemProps.content === 'Reprocess source file' && (isWorkspaceLeaf(entry.data))) { | ||
this.props.reprocessBlob(workspaceId, entry.data.uri) | ||
} | ||
|
||
if (menuItemProps.content === "Search in folder"){ | ||
history.push( | ||
buildLink("/search", { | ||
q: JSON.stringify([ | ||
"", | ||
{ | ||
n: "Workspace Folder", | ||
v: entry.name, | ||
op: "+", | ||
t: "workspace_folder", | ||
workspaceId: workspace.id, | ||
folderId: entry.id, | ||
}, | ||
"*" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking this might have been a mistake but actually a good shout to start with * so that there are documents visible straight away before the user adds a search There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep that's what I was thinking. Still want to test this in code with a workspace with loads of documents to see if it slows down the initial folder search. |
||
]), | ||
page: 1 | ||
}), | ||
) | ||
} | ||
|
||
setTimeout(() => this.closeContextMenu(), closeMenuDelay); | ||
}} | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
pc
instead ofpt
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parsed tchip