Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Delay loading search field dropdown data #1731

Merged
merged 6 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

- Delay loading search field dropdown data [#1731](https://github.com/open-apparel-registry/open-apparel-registry/pull/1731)

### Deprecated

### Removed
Expand Down
3 changes: 1 addition & 2 deletions src/app/src/actions/filterOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,9 @@ export function fetchNumberOfWorkersOptions() {
};
}

export function fetchAllFilterOptions() {
export function fetchAllPrimaryFilterOptions() {
return dispatch => {
dispatch(fetchContributorOptions());
dispatch(fetchContributorTypeOptions());
dispatch(fetchCountryOptions());
dispatch(fetchListOptions());
};
Expand Down
69 changes: 3 additions & 66 deletions src/app/src/components/FilterSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,13 @@ import {
import {
fetchContributorOptions,
fetchListOptions,
fetchContributorTypeOptions,
fetchCountryOptions,
fetchFacilityProcessingTypeOptions,
fetchProductTypeOptions,
fetchNumberOfWorkersOptions,
fetchAllFilterOptions,
fetchAllPrimaryFilterOptions,
} from '../actions/filterOptions';

import {
contributorOptionsPropType,
contributorTypeOptionsPropType,
countryOptionsPropType,
facilityProcessingTypeOptionsPropType,
productTypeOptionsPropType,
numberOfWorkerOptionsPropType,
} from '../util/propTypes';

import { allListsAreEmpty } from '../util/util';
Expand All @@ -67,59 +59,26 @@ class FilterSidebar extends Component {
componentDidMount() {
const {
contributorsData,
contributorTypesData,
countriesData,
facilityProcessingTypeData,
productTypeData,
numberOfWorkersData,
fetchFilterOptions,
fetchContributors,
fetchLists,
fetchContributorTypes,
fetchCountries,
fetchFacilityProcessingType,
fetchProductType,
fetchNumberOfWorkers,
contributors,
} = this.props;

if (
allListsAreEmpty(
contributorsData,
contributorTypesData,
countriesData,
facilityProcessingTypeData,
productTypeData,
numberOfWorkersData,
)
) {
if (allListsAreEmpty(contributorsData, countriesData)) {
return fetchFilterOptions();
}

if (!contributorsData.length) {
fetchContributors();
}

if (!contributorTypesData.length) {
fetchContributorTypes();
}

if (!countriesData.length) {
fetchCountries();
}

if (!facilityProcessingTypeData.length) {
fetchFacilityProcessingType();
}

if (!productTypeData.length) {
fetchProductType();
}

if (!numberOfWorkersData.length) {
fetchNumberOfWorkers();
}

if (contributors && contributors.length) {
fetchLists();
}
Expand Down Expand Up @@ -266,18 +225,9 @@ FilterSidebar.propTypes = {
makeFacilitiesTabActive: func.isRequired,
fetchFilterOptions: func.isRequired,
fetchContributors: func.isRequired,
fetchContributorTypes: func.isRequired,
fetchCountries: func.isRequired,
fetchFacilityProcessingType: func.isRequired,
fetchProductType: func.isRequired,
fetchNumberOfWorkers: func.isRequired,
contributorsData: contributorOptionsPropType.isRequired,
contributorTypesData: contributorTypeOptionsPropType.isRequired,
countriesData: countryOptionsPropType.isRequired,
facilityProcessingTypeData:
facilityProcessingTypeOptionsPropType.isRequired,
productTypeData: productTypeOptionsPropType.isRequired,
numberOfWorkersData: numberOfWorkerOptionsPropType.isRequired,
vectorTileFeatureIsActive: bool.isRequired,
fetchingFeatureFlags: bool.isRequired,
};
Expand All @@ -287,11 +237,7 @@ function mapStateToProps({
filterOptions: {
contributors: { data: contributorsData },
lists: { data: listsData },
contributorTypes: { data: contributorTypesData },
countries: { data: countriesData },
facilityProcessingType: { data: facilityProcessingTypeData },
productType: { data: productTypeData },
numberOfWorkers: { data: numberOfWorkersData },
},
featureFlags: { flags, fetching: fetchingFeatureFlags },
embeddedMap: { embed },
Expand All @@ -303,11 +249,7 @@ function mapStateToProps({
return {
activeFilterSidebarTab,
contributorsData,
contributorTypesData,
countriesData,
facilityProcessingTypeData,
productTypeData,
numberOfWorkersData,
listsData,
vectorTileFeatureIsActive: get(flags, 'vector_tile', false),
fetchingFeatureFlags,
Expand All @@ -323,15 +265,10 @@ function mapDispatchToProps(dispatch) {
makeSearchTabActive: () => dispatch(makeSidebarSearchTabActive()),
makeFacilitiesTabActive: () =>
dispatch(makeSidebarFacilitiesTabActive()),
fetchFilterOptions: () => dispatch(fetchAllFilterOptions()),
fetchFilterOptions: () => dispatch(fetchAllPrimaryFilterOptions()),
fetchContributors: () => dispatch(fetchContributorOptions()),
fetchLists: () => dispatch(fetchListOptions()),
fetchContributorTypes: () => dispatch(fetchContributorTypeOptions()),
fetchCountries: () => dispatch(fetchCountryOptions()),
fetchFacilityProcessingType: () =>
dispatch(fetchFacilityProcessingTypeOptions()),
fetchProductType: () => dispatch(fetchProductTypeOptions()),
fetchNumberOfWorkers: () => dispatch(fetchNumberOfWorkersOptions()),
};
}

Expand Down