Skip to content

Commit

Permalink
feat(resourceCatalog): Updated the standlone Resource Catalog/On-Ramp…
Browse files Browse the repository at this point in the history
…s Sorting to use the sorting specified by ACCESS admins
  • Loading branch information
rebeccaeve committed Nov 20, 2024
1 parent 6fc4f19 commit b8d158b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 79 deletions.
98 changes: 58 additions & 40 deletions src/onramps-resource-catalog/helpers/catalogSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const initialState = {
onRamps: false,
resources: [],
resourcesLoaded: false,
resourceSorting: {
"NSF Capacity Resources": 1,
"NSF Innovative Testbeds": 2,
"Other NSF-funded Resources": 3,
"Services and Support": 4
}
};

export const getResources = createAsyncThunk(
Expand Down Expand Up @@ -132,52 +138,58 @@ const useFilter = (allowed, excluded, item) => {
const formatResourceFeatures = (catalog, resource, categories) => {

const featureList = [];

let sortCategory = "";
resource.featureCategories
.filter((f) => f.categoryIsFilter)
.forEach((category) => {
const categoryId = category.categoryId;

if (
!categories[categoryId] &&
useFilter(
catalog.allowedCategories,
catalog.excludedCategories,
category.categoryName
)
) {
categories[categoryId] = {
categoryId: categoryId,
categoryName: category.categoryName,
categoryDescription: category.categoryDescription,
features: {},
};
}

category.features.forEach((feat) => {
const feature = {
featureId: feat.featureId,
name: feat.name,
description: feat.description,
categoryId: categoryId,
selected: false,
};

const filterIncluded = useFilter(
catalog.allowedFilters,
catalog.excludedFilters,
feature.name
);
if (filterIncluded) featureList.push(feature);

if(category.categoryName == "ACCESS Resource Grouping"){
sortCategory = category.features[0].name;
} else {
if (
categories[categoryId] &&
filterIncluded &&
!categories[categoryId].features[feat.featureId]
!categories[categoryId] &&
useFilter(
catalog.allowedCategories,
catalog.excludedCategories,
category.categoryName
)
) {
categories[categoryId].features[feat.featureId] = feature;
categories[categoryId] = {
categoryId: categoryId,
categoryName: category.categoryName,
categoryDescription: category.categoryDescription,
features: {},
};
}
});

category.features.forEach((feat) => {
const feature = {
featureId: feat.featureId,
name: feat.name,
description: feat.description,
categoryId: categoryId,
selected: false,
};

const filterIncluded = useFilter(
catalog.allowedFilters,
catalog.excludedFilters,
feature.name
);
if (filterIncluded) featureList.push(feature);

if (
categories[categoryId] &&
filterIncluded &&
!categories[categoryId].features[feat.featureId]
) {
categories[categoryId].features[feat.featureId] = feature;
}
});
}


});

const featureNames = featureList
Expand All @@ -189,6 +201,7 @@ const formatResourceFeatures = (catalog, resource, categories) => {
resourceName: resource.resourceName.trim(),
features: featureNames,
featureIds: featureList.map((f) => f.featureId),
sortCategory
};

return { formattedResource, categories }
Expand Down Expand Up @@ -223,9 +236,14 @@ export const catalogSlice = createSlice({
state.filters = state.filters.sort((a, b) =>
a.categoryName.localeCompare(b.categoryName)
);
state.resources = resources.sort((a, b) =>
state.resources = resources
.sort((a, b) =>
a.resourceName.localeCompare(b.resourceName)
);
)
.sort((a, b) =>
state.resourceSorting[a.sortCategory] > state.resourceSorting[b.sortCategory]
)

state.filteredResources = [...state.resources];
state.resourcesLoaded = true;
},
Expand Down
94 changes: 55 additions & 39 deletions src/resource-catalog/helpers/catalogSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const initialState = {
filteredResources: [],
resourcesLoaded: false,
hasErrors: false,
resourceSorting: {
"NSF Capacity Resources": 1,
"NSF Innovative Testbeds": 2,
"Other NSF-funded Resources": 3,
"Services and Support": 4
}
};

export const getResources = createAsyncThunk(
Expand Down Expand Up @@ -68,52 +74,56 @@ export const catalogSlice = createSlice({
.filter((r) => !excludedResources.includes(r.resourceName))
.forEach((r) => {
const feature_list = [];

let sortCategory = "";
r.featureCategories
.filter((f) => f.categoryIsFilter)
.forEach((category) => {
const categoryId = category.categoryId;

if (
!categories[categoryId] &&
useFilter(
allowedCategories,
excludedCategories,
category.categoryName
)
) {
categories[categoryId] = {
categoryId: categoryId,
categoryName: category.categoryName,
categoryDescription: category.categoryDescription,
features: {},
};
}

category.features.forEach((feat) => {
const feature = {
featureId: feat.featureId,
name: feat.name,
description: feat.description,
categoryId: categoryId,
selected: false,
};

const filterIncluded = useFilter(
allowedFilters,
excludedFilters,
feature.name
);
if (filterIncluded) feature_list.push(feature);

if(category.categoryName == "ACCESS Resource Grouping"){
sortCategory = category.features[0].name;
} else {
if (
categories[categoryId] &&
filterIncluded &&
!categories[categoryId].features[feat.featureId]
!categories[categoryId] &&
useFilter(
allowedCategories,
excludedCategories,
category.categoryName
)
) {
categories[categoryId].features[feat.featureId] = feature;
categories[categoryId] = {
categoryId: categoryId,
categoryName: category.categoryName,
categoryDescription: category.categoryDescription,
features: {},
};
}
});

category.features.forEach((feat) => {
const feature = {
featureId: feat.featureId,
name: feat.name,
description: feat.description,
categoryId: categoryId,
selected: false,
};

const filterIncluded = useFilter(
allowedFilters,
excludedFilters,
feature.name
);
if (filterIncluded) feature_list.push(feature);

if (
categories[categoryId] &&
filterIncluded &&
!categories[categoryId].features[feat.featureId]
) {
categories[categoryId].features[feat.featureId] = feature;
}
});
}
});

const resource = {
Expand All @@ -128,6 +138,7 @@ export const catalogSlice = createSlice({
recommendedUse: r.recommendedUse,
features: feature_list.map((f) => f.name).sort((a, b) => a > b),
featureIds: feature_list.map((f) => f.featureId),
sortCategory
};

resources.push(resource);
Expand All @@ -150,9 +161,14 @@ export const catalogSlice = createSlice({
state.filters = state.filters.sort((a, b) =>
a.categoryName.localeCompare(b.categoryName)
);
state.resources = resources.sort((a, b) =>
state.resources = resources
.sort((a, b) =>
a.resourceName.localeCompare(b.resourceName)
)
.sort((a, b) =>
state.resourceSorting[a.sortCategory] > state.resourceSorting[b.sortCategory]
);

state.filteredResources = [...state.resources];
state.resourcesLoaded = true;
},
Expand Down

0 comments on commit b8d158b

Please sign in to comment.