Skip to content

Commit

Permalink
search: tweak results views
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Dec 1, 2024
1 parent cd2e046 commit 45807e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
43 changes: 30 additions & 13 deletions src/components/SearchCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ColorDefault, ColorEmphasis, ColorError, ColorPrivate, ColorSubdued } f
import { copyShortcut, drilldownShortcut, tertiaryActionShortcut } from "./shortcuts";
import { SearchHistory } from "../searchHistory";
import { useTelemetry } from "../hooks/telemetry";
import path from "path";

const link = new LinkBuilder("search");

Expand Down Expand Up @@ -653,11 +654,10 @@ function ResultView({

const { match } = searchResult;
const navigationTitle = `View ${match.type} result`;
let markdownTitle: string;
let markdownContent = "";
const metadata: ReactNode[] = [
<Detail.Metadata.TagList title="Match type" key={nanoid()}>
<Detail.Metadata.TagList.Item text={match.type} icon={icon} />
<Detail.Metadata.TagList.Item text={match.type} icon={icon} color={ColorDefault} />
</Detail.Metadata.TagList>,
];
if ("repository" in match) {
Expand All @@ -676,17 +676,34 @@ function ResultView({

case "content":
case "symbol":
markdownTitle = bold(match.repository);
return <MultiResultView searchResult={{ url: searchResult.url, match }} key={nanoid()} />;

// Match types that use markdown view

case "repo":
markdownTitle = bold(match.repository);
markdownContent = match.description || "";
markdownContent = `${bold(match.repository)}`;
if (match.description) {
markdownContent += ` - ${match.description}\n`;
}
metadata.push(
<Detail.Metadata.Label title="Visibility" text={match.private ? "Private" : "Public"} key={nanoid()} />,
<Detail.Metadata.Label
title="Visibility"
text={{
value: match.private ? "Private" : "Public",
color: match.private ? ColorPrivate : Color.PrimaryText,
}}
key={nanoid()}
/>,
);
if (match.topics) {
metadata.push(
<Detail.Metadata.TagList title="Topics" key={nanoid()}>
{match.topics.map((topic) => (
<Detail.Metadata.TagList.Item text={topic} key={nanoid()} />
))}
</Detail.Metadata.TagList>,
);
}
if (!fileContents.called) {
getFileContents({
variables: {
Expand All @@ -702,8 +719,10 @@ function ResultView({
break;

case "path":
markdownTitle = bold(match.repository);
markdownContent = `${codeBlock(match.path)}\n\n---\n\n`;
metadata.push(
<Detail.Metadata.Link title="File" text={path.basename(match.path)} key={nanoid()} target={searchResult.url} />,
);
markdownContent = `${bold(match.path)}\n\n---\n\n`;
if (!fileContents.called) {
getFileContents({
variables: {
Expand All @@ -721,11 +740,10 @@ function ResultView({
break;

case "commit": {
markdownTitle = bold(match.repository);
markdownContent = match.message;
metadata.push(
<Detail.Metadata.Label title="Author" text={match.authorName} key={nanoid()} />,
<Detail.Metadata.Label title="Commit" text={match.oid} key={nanoid()} />,
<Detail.Metadata.Link title="Commit" text={match.oid} target={searchResult.url} key={nanoid()} />,
<Detail.Metadata.Label
title="Committed"
text={DateTime.fromISO(match.authorDate).toRelative() || "Unknown"}
Expand All @@ -736,8 +754,7 @@ function ResultView({
}

default:
markdownTitle = bold(sentenceCase(match.type));
markdownContent = `Unsupported result type - full data:\n\n${codeBlock(JSON.stringify(match, null, " "))}`;
markdownContent = `${bold(sentenceCase(match.type))}\n\n---\n\nUnsupported result type - full data:\n\n${codeBlock(JSON.stringify(match, null, " "))}`;
}

if ("repoStars" in match) {
Expand All @@ -747,7 +764,7 @@ function ResultView({
return (
<Detail
navigationTitle={navigationTitle}
markdown={`${markdownTitle}\n\n${markdownContent}`}
markdown={markdownContent}
actions={<ActionPanel>{resultActions(searchResult.url)}</ActionPanel>}
metadata={
<Detail.Metadata>
Expand Down
2 changes: 1 addition & 1 deletion src/markdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function codeBlock(str: string): string {
return `\`\`\`\n${str}\n\`\`\``;
return `\`\`\`\n\n${str}\n\`\`\``;
}

export function inlineCode(str: string): string {
Expand Down

0 comments on commit 45807e9

Please sign in to comment.