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

PAC-1650-filters data persisted, version tabs hidden, version based r… #2792

Merged
merged 9 commits into from
May 23, 2024

Conversation

nage1234
Copy link

@nage1234 nage1234 commented May 8, 2024

…outing

Describe the Change

This PR ....

Changed Pages

💻 Add Preview URL for Page

Jira Tickets

🎫 Jira Ticket

Backports

Can this PR be backported?

  • Yes. Remember to add the relevant backport labels to your PR.
  • No. Please leave a short comment below about why this PR cannot be backported.

@nage1234 nage1234 requested a review from a team as a code owner May 8, 2024 11:26
@nage1234 nage1234 requested review from karl-cardenas-coding, lennessyy and caroldelwing and removed request for a team May 8, 2024 11:26
@nage1234 nage1234 marked this pull request as draft May 8, 2024 11:26
@@ -12,22 +12,16 @@ interface PackFiltersProps {
}

export default function PacksFilters({ categories, registries, setSelectedSearchFilters, selectedFilters }: PackFiltersProps) {
const additionalFiltersProps: string[] = [
const sourceList: string[] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

these options are static. can be moved outside of this. I'd be careful to how labels are capitalized, so include value and label

@@ -204,10 +206,12 @@ async function pluginPacksAndIntegrationsData(context, options) {
const packUrl = "v1/packs/";
const packMDMap = new Map();
let apiPacksData = [];
const packuid = mappedRepos?.[0]?.uid;
Copy link
Contributor

Choose a reason for hiding this comment

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

preferedRegistryUid

const promises = packDataArr.map((packData) => {
packMDMap[packData.spec.name] = packData;
const cloudType = packData.spec.cloudTypes.includes("all") ? "aws" : packData.spec.cloudTypes[0];
const url = `${packUrl}${packData.spec.name}/registries/${packData.spec.registries[0].uid}?cloudType=${cloudType}&layer=${packData.spec.layer}`;
const packUid = packData.spec.registries.find((registry) => registry.uid === packuid);
Copy link
Contributor

Choose a reason for hiding this comment

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

preferedRegistry

const promises = packDataArr.map((packData) => {
packMDMap[packData.spec.name] = packData;
const cloudType = packData.spec.cloudTypes.includes("all") ? "aws" : packData.spec.cloudTypes[0];
const url = `${packUrl}${packData.spec.name}/registries/${packData.spec.registries[0].uid}?cloudType=${cloudType}&layer=${packData.spec.layer}`;
const packUid = packData.spec.registries.find((registry) => registry.uid === packuid);
const url = `${packUrl}${packData.spec.name}/registries/${packUid?.uid || packData.spec.registries[0].uid}?cloudType=${cloudType}&layer=${packData.spec.layer}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

packUid?.uid you already have the UID from mappedRepos?.[0]?.uid;
Why create packUid once more?

Copy link
Author

Choose a reason for hiding this comment

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

@codrin-iftimie say, i have given A, B in the docusaurus config file. So, our conclusion is to use A as the preferred registry to fetch the details of the pack
There can be another scenario, while traversing the list of packs, some packs may be part of registry B, not A. So, this could end up in error if i fetch the details of those packs which are not part of A. Thats the reason why i am creating another packUid here.. i will update the proper comments for this for future correspondence

<InfoCircleOutlined className={styles.infoIcon} />
{"Info"}
</div>
<div className={styles.content}>{infoContent[0]}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

why show only one if you go in all of the trouble of creating this array?

Copy link
Author

Choose a reason for hiding this comment

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

let me do simply with the conditional operators.. as they are simple booleans

...selectedSearchFilters
}));
};
localStorage.setItem("selectedFilters", JSON.stringify(updatedFilters));
Copy link
Contributor

Choose a reason for hiding this comment

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

Better make this a bit more specific "packList.selectedFilters" and make it a constant (to be used in both places when you set or get the value in the local storage)
and include the search value in these filters. There is no need for two different storage items

Copy link
Contributor

Choose a reason for hiding this comment

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

search is still a filter

const packUid = packData.spec.registries.find((registry) => registry.uid === packuid);
const url = `${packUrl}${packData.spec.name}/registries/${packUid?.uid || packData.spec.registries[0].uid}?cloudType=${cloudType}&layer=${packData.spec.layer}`;
const preferredRegistry = packData.spec.registries.find((registry) => registry.uid === preferredRegistryUid);
//there is a scenario where the pack is not part of preferred registry, in that case, the item of the pack registries is sent to API request
Copy link
Contributor

Choose a reason for hiding this comment

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

then lets make this obvious.

const hasPreferredRegistry = packData.spec.registries.some((registry) => registry.uid === preferredRegistryUid);
let packRegistryUid = packData.spec.registries[0].uid
if (hasPreferredRegistry) {
  packRegistryUid = preferedRegistryUid
}
const url = `${packUrl}${packData.spec.name}/registries/${packRegistryUid}?cloudType=${cloudType}&layer=${packData.spec.layer}`;

Comment on lines 93 to 95
const infoContent = packData.disabled ? "This pack is currently disabled." : (
packData.deprecated ? "This pack is deprecated." : undefined
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ternary operators (multiple) makes this hard to read.

@@ -212,13 +210,13 @@ export default function PacksReadme() {
</div>
</div>
</div>
{infoContent.length > 0 && (
{infoContent && (
Copy link
Contributor

Choose a reason for hiding this comment

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

{infoContent ? (// etc) : null}

if (filters) {
setSelectedFilters(JSON.parse(filters));
const { selectedFilters, searchValue } = JSON.parse(filters);
Copy link
Contributor

Choose a reason for hiding this comment

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

JSON.parse can fail

Copy link
Author

Choose a reason for hiding this comment

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

handled with try and catch

@nage1234 nage1234 marked this pull request as ready for review May 23, 2024 07:18
@nage1234 nage1234 merged commit 122c012 into PAC-938_nageswari May 23, 2024
10 of 13 checks passed
@nage1234 nage1234 deleted the PAC-1650-nageswari branch May 23, 2024 09:00
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.

None yet

2 participants