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

DOP-5036 Refactor Search-Manifest integration #10

Merged
merged 40 commits into from
Oct 8, 2024
Merged

Conversation

anabellabuckvar
Copy link
Collaborator

@anabellabuckvar anabellabuckvar commented Sep 27, 2024

TICKET

DOP-5036

This PR cleans up much of the code in the Search-Manifest integration. This includes:

  • Addresses linting errors
  • Strongly types where there were previously unnecessary any's
  • Adds validation for environment variables
  • Refactors various functions and removes extraneous error handling

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for search-manifest-integration ready!

Name Link
🔨 Latest commit 4550273
🔍 Latest deploy log https://app.netlify.com/sites/search-manifest-integration/deploys/67055218c167830008f7b99d
😎 Deploy Preview https://deploy-preview-10--search-manifest-integration.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for redoc-integration canceled.

Name Link
🔨 Latest commit 4550273
🔍 Latest deploy log https://app.netlify.com/sites/redoc-integration/deploys/6705521832210e0008a0d17d

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for persistence-module-integration canceled.

Name Link
🔨 Latest commit 4550273
🔍 Latest deploy log https://app.netlify.com/sites/persistence-module-integration/deploys/67055218147cff0008b73b4c

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for site-links-display canceled.

Name Link
🔨 Latest commit 4550273
🔍 Latest deploy log https://app.netlify.com/sites/site-links-display/deploys/6705521832210e0008a0d181

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for git-changed-files-plugin-bianca canceled.

Name Link
🔨 Latest commit 4550273
🔍 Latest deploy log https://app.netlify.com/sites/git-changed-files-plugin-bianca/deploys/6705521832210e0008a0d186

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for snooty-cache-plugin canceled.

Name Link
🔨 Latest commit 4550273
🔍 Latest deploy log https://app.netlify.com/sites/snooty-cache-plugin/deploys/670552189e6e210008f9e4aa

@anabellabuckvar anabellabuckvar marked this pull request as ready for review October 4, 2024 14:27
Copy link
Collaborator

@branberry branberry left a comment

Choose a reason for hiding this comment

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

Hey Anabella! Overall, this is looking great.

},
},
};
// const deleteResult = await collection.deleteMany(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed

this.documents = [];
this.global = includeInGlobalSearch;
}
constructor(url = "", includeInGlobalSearch = false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if the url property is empty? Does this cause breaking issues down the line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nothing, it should always be empty upon initialization because the value will be returned from getProperties and then set to the existing manifest later on

this.category = category;
this.value = value;
this.subFacets = subFacets;
if (subFacets) {
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 need this if statement as subFacets should be defined based on it's type definition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually, subFacets should be an array of facets or null, thanks for catching this!

if (subFacets) {
for (const subFacet of subFacets) {
this.subFacets.push(
new Facet(subFacet.category, subFacet.value, subFacet.subFacets ?? [])
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the subFacets array already contain an array of Facet objects, is there a need to create more? It looks like we might be creating duplicates since we push onto this.subFacets which has subFacets assigned to it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this as well- this.subFacets should have been initialized to an empty array, and then we push a new facet onto it on each iteration over the subFacets arg that was passed in

Copy link
Collaborator

@branberry branberry Oct 7, 2024

Choose a reason for hiding this comment

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

Gotcha! I was also wondering if it makes sense to create a new Facet instance if the subFacets array contains Facet objects already. I'm thinking about this more too, and I wonder if this is a good use of a class. I know that we use a class for the Facet type in Mut, but this could just be an object:

interface Facet {
 category: string;
 value: string;
 subFacet: Array<Facet>;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed!

@@ -0,0 +1,31 @@
{
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 need a biome.json for this directory as it finds the nearest biome.json in the project structure.

I think it would be preferable to use the single top level one so that the configurations are consistent, but I'm not opposed to adding one here if there's a specific need.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No specific need!

}
};

export const getDocsetsCollection = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks great!! Thank you for doing this


export const getSearchDb = async () => {
console.log("Getting Search Db");
const uri = ENV_VARS.ATLAS_SEARCH_URI;
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: I think it might be preferable to use the ENV_VARS.ATLAS_SEARCH_URI and other env variables directly as opposed to re-assigning them to another variable. It makes it a little bit harder to track

const uri = ENV_VARS.ATLAS_CLUSTER0_URI;
const dbName = ENV_VARS.SNOOTY_DB_NAME;

if (snootyDb) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think clusterZeroClient could be more descriptive for this, as this variable doesn't hold the instance of the snootyDb.

What you could do instead is cache the Db instance ie snootyDb = db(dbName)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I renamed it to clusterZeroClient

export const getBranch = (branches: Array<BranchEntry>, branchName: string) => {
for (const branchObj of branches) {
if (branchObj.gitBranchName.toLowerCase() === branchName.toLowerCase()) {
return { ...branchObj };
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can just be return branchObj

)}`
);
// helper function to find the associated branch
export const getBranch = (branches: Array<BranchEntry>, branchName: string) => {
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 simplified to (branches, branchName) => branches.find(branch => branch === branchName)

Copy link
Collaborator

@branberry branberry left a comment

Choose a reason for hiding this comment

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

LGTM!

@anabellabuckvar anabellabuckvar merged commit b00a6c9 into main Oct 8, 2024
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants