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

refactor: improve typing of sorting in facetGetters/category.vue #1080

Merged
merged 2 commits into from
May 31, 2022

Conversation

sethidden
Copy link
Contributor

@sethidden sethidden commented May 31, 2022

Fix issue where AgnosticSort was totally different type than what would appear at runtime

import type { UseFacetSearchResult } from '~/modules/catalog/category/composables/useFacet/useFacet';

export interface FacetsGetters {
getSortOptions: (searchData: UseFacetSearchResult) => SortingModel;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously the type here was AgnosticSort which turned out to be completely different at runtime. TypeScript didn't report an error since the searchData argument was any.

};
};

const getProducts = (searchData): ProductInterface[] => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I inlined the methods into the exported asserted interface since I didn't want to duplicate the typedefs

@@ -1,3 +1,13 @@
export interface SortingModel {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SortingModel as to avoid having "SortingOptions" and "SortingOption" interfaces with similar names

M2-645

related to M2-524 since it removes AgnosticSort
@sethidden sethidden force-pushed the M2-645-fix-facet-getters-category-sorting branch from 9f7d1fc to 68b0ba7 Compare May 31, 2022 10:13
} as AgnosticSort;
}
options: searchData.data.availableSortingOptions,
selected: searchData.input.sort,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if there will be no sort param?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CategoryNavbar will not show any sort option. This will only happen if someone puts a sort id that doesn't exist into the url.

@sethidden sethidden merged commit 7d2b733 into develop May 31, 2022
@sethidden sethidden deleted the M2-645-fix-facet-getters-category-sorting branch May 31, 2022 12:36
@Frodigo Frodigo added this to the 1.0.0-rc.9 milestone Jun 1, 2022
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.

3 participants