Skip to content
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

feat: add document search to the command menu #713

Merged
merged 9 commits into from
Dec 6, 2023

Conversation

ksushant6566
Copy link
Contributor

resolves #702

Copy link

vercel bot commented Dec 2, 2023

@ksushant6566 is attempting to deploy a commit to the Documenso Team Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2023

Important

Auto Review Skipped

Auto reviews are limited to the following labels: coderabbit. Please add one of these labels to enable auto reviews.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

{ label: string; path: string; recipents: string[] }[]
>([]);

const { isLoading: isSearchingDocuments, refetch: findDocuments } =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the data property instead? Using onSuccess on queries will be deprecated with React Query 5 afaik

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, I'll make change it

Comment on lines 149 to 160
filter: (value, search) => {
const exists = value.includes(search);
if (exists) return 1;

const result = searchResults.find(
(result) => result.label.toLocaleLowerCase() === value.toLocaleLowerCase(),
);

if (result?.recipents.some((recipent) => recipent.includes(search))) return 1;
return 0;
},
}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we can cheat and just use an sr-only thing that contains the recipients so we don't have to add a custom filter fn 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you mean by sr-only? can you please explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new value property in searchResults

const newResults = searchDocuments?.map((document) => ({
        label: document.title,
        path: `/documents/${document.id}`,
        value: document.title + document.Recipient.map((recipient) => recipient.email).join(' '),
      }));

with this we don't need a custom filter function anymore

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant the tailwind sr-only class that would make text invisible unless on a screen reader 😄

If the solution above works that's just as good!

Comment on lines 14 to 31
where: {
OR: [
{
title: {
contains: query,
mode: 'insensitive',
},
},
{
Recipient: {
some: {
email: {
contains: query,
},
},
},
},
],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently missing documents you have received, see findDocuments for some inspo on how to query it.

Consider if we could also use findDocuments instead with some modifications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cools, I'll check and make the necessary changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although the findDocuments does have a filter by term but searching term in recipients email might be a lil confusing & unintuitive for others so I just made the changes in SearchDocumentsWithKeyword to include received documents as well.

data: searchDocuments,
isLoading: isSearchingDocuments,
refetch: findDocuments,
} = trpcReact.document.searchDocuments.useQuery(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we always search and show the most recent documents


useEffect(() => {
if (search) {
void findDocuments();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant since we're using react query it should just automatically fetch whenever query changes


useEffect(() => {
if (searchDocuments) {
const newResults = searchDocuments?.map((document) => ({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done with a map of the results in a use memo or similar, an effect will introduce race conditions

const { query } = input;

try {
const documents = await SearchDocumentsWithKeyword({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do pascal case methods :)

// }, [searchDocuments]);

const searchResults = useMemo(() => {
if (!searchDocuments) return [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No single line if statements please, just wrap it in braces {} 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

},
});

const documents = await prisma.document.findMany({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're missing a limit here, if I were to search for a I might return thousands of results

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be an option passed into the method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done now this takes a limit variable with a default value of 5.

query: search,
},
{
enabled: search !== '',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want results even for an empty search term 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, done!

@@ -83,3 +83,7 @@ export const ZDeleteDraftDocumentMutationSchema = z.object({
});

export type TDeleteDraftDocumentMutationSchema = z.infer<typeof ZDeleteDraftDocumentMutationSchema>;

export const ZSearchDocumentsMutationSchema = z.object({
query: z.string().min(1),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which will meant his also needs to change as well

@ksushant6566
Copy link
Contributor Author

Hey @Mythie , just pushed requested changes. if (anything needs to be changed) { please let me know :) }

@Mythie
Copy link
Collaborator

Mythie commented Dec 3, 2023

round 2

@Mythie
Copy link
Collaborator

Mythie commented Dec 3, 2023

Noting that the searchDocuments endpoint is angry:

image

@ksushant6566
Copy link
Contributor Author

Noting that the searchDocuments endpoint is angry:

image

Oh shit! lemme check

@Mythie
Copy link
Collaborator

Mythie commented Dec 3, 2023

It's because of migrations aha! This PR has been built on top of the other PR for document deletion so it won't work on a fresh checkout like the one I did on Gitpod

@ksushant6566
Copy link
Contributor Author

It's because of migrations aha! This PR has been built on top of the other PR for document deletion so it won't work on a fresh checkout like the one I did on Gitpod

Yes!

@Mythie
Copy link
Collaborator

Mythie commented Dec 3, 2023

As a final request then I'll need a video recording showing the 3 flows:

  • document I own appearing in search results
  • document I received showing in search results
  • search by recipient

Once this has been provided I'm happy to accept this submission 🙌

@ksushant6566
Copy link
Contributor Author

As a final request then I'll need a video recording showing the 3 flows:

  • document I own appearing in search results
  • document I received showing in search results
  • search by recipient

Once this has been provided I'm happy to accept this submission 🙌

cool give me 5 minutes

@ksushant6566
Copy link
Contributor Author

@Mythie
Copy link
Collaborator

Mythie commented Dec 3, 2023

Looks good! I’m happy with it in this state and the code is alright too 🙌🏻

You only lose points for being a dark mode user 🌚

I’ll merge once I know it won’t blow up

@ksushant6566
Copy link
Contributor Author

Looks good! I’m happy with it in this state and the code is alright too 🙌🏻

You only lose points for being a dark mode user 🌚

I’ll merge once I know it won’t blow up

Cool 💯

@kritarth2121
Copy link
Contributor

The cmdk library filters based on whether the item contains a string sequence of search in order, but not necessarily right next to each other,

but the filter you have implemented filters whether the items containing search substring right next to each other

This feature can be implemented with regex, if you want I can build it.
@Mythie

Mythie
Mythie previously approved these changes Dec 3, 2023
@ksushant6566
Copy link
Contributor Author

Hey @Mythie , Since this is approved I'll start working on #703 , in this branch only, since we want the search results in the same command menu.

@Mythie Mythie merged commit bfc630a into documenso:main Dec 6, 2023
7 of 11 checks passed
@ksushant6566 ksushant6566 deleted the document-search-in-command-menu branch December 6, 2023 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OSSHACK] Add document search to the command menu
4 participants