Skip to content

Commit 8dd70c4

Browse files
feat(app-degree-pages): allow list view including both GR and UGCM certs
1 parent 14bf82c commit 8dd70c4

File tree

6 files changed

+65
-12
lines changed

6 files changed

+65
-12
lines changed

packages/app-degree-pages/src/components/ListingPage/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const ListingPage = ({
9191
const [dataInitView, setDataInitView] = useState([]);
9292
const [searchKeyword, setSearchKeyword] = useState("");
9393
// start set default data view
94-
const settingDefaultView = programList.settings?.defaultView;
94+
const settingDefaultView = programList?.settings?.defaultView;
9595
const defaultView = [LIST_VIEW_ID, GRID_VIEW_ID].includes(settingDefaultView)
9696
? settingDefaultView
9797
: LIST_VIEW_ID;

packages/app-degree-pages/src/components/ListingPage/index.stories.jsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,41 @@ DefaultWithCertificate.args = {
187187
},
188188
};
189189

190+
/**
191+
* @type {{ args: AppProps }}
192+
*/
193+
export const GradWithCertificate = Template.bind({});
194+
GradWithCertificate.args = {
195+
...defaultArgs,
196+
introContent: null,
197+
programList: {
198+
...defaultArgs.programList,
199+
dataSource: {
200+
...defaultArgs.programList.dataSource,
201+
program: "graduate",
202+
cert: "true",
203+
showInactivePrograms: "true",
204+
},
205+
},
206+
};
207+
/**
208+
* @type {{ args: AppProps }}
209+
*/
210+
export const AllWithCertificate = Template.bind({});
211+
AllWithCertificate.args = {
212+
...defaultArgs,
213+
introContent: null,
214+
programList: {
215+
...defaultArgs.programList,
216+
dataSource: {
217+
...defaultArgs.programList.dataSource,
218+
program: "all",
219+
cert: "true",
220+
showInactivePrograms: "true",
221+
},
222+
},
223+
};
224+
190225
/**
191226
* @type {{ args: AppProps}}
192227
*/

packages/app-degree-pages/src/core/services/degree-data-manager-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function filterData({
8080

8181
// If showing certificates is enabled and the program is graduate,
8282
// include it only if it's a minor or certificate.
83-
if (showCerts === "true" && program === "graduate") {
83+
if (showCerts === "true") {
8484
return resolver.isMinorOrCertificate();
8585
}
8686

packages/app-degree-pages/src/core/types/listing-page-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @property {"true" | "false"} [init]
5353
* @property {"true" | "false"} [cert]
5454
* @property {string} [fields]
55-
* @property {"undergrad" | "graduate"} [program]
55+
* @property {"undergrad" | "graduate" | "all"} [program]
5656
* @property {string} [collegeAcadOrg]
5757
* @property {string} [acadPlan]
5858
* @property {string} [departmentCode]

packages/app-degree-pages/src/core/types/shared-local-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const DegreeDataPropResolverServiceType = degreeDataPropResolverService({});
7979
* showInactivePrograms?: boolean | "true" | "false"
8080
* blacklistAcadPlans?: Array
8181
* showCerts?: "true" | "false"
82-
* program: "undergrad" | "graduate"
82+
* program: "undergrad" | "graduate" | "all"
8383
* }} FiltersState
8484
*/
8585

packages/app-degree-pages/src/core/utils/http-url-resolver.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ function urlResolver(dataSource, defaultDataSource) {
2222
// to accommodate Data Potluck API changes.
2323
const { program } = httpParameters;
2424

25-
if (httpParameters.cert === "true" && program === "undergrad") {
25+
if (httpParameters.cert === "true" && program === "all") {
26+
httpParameters["degreeType"] = "GR,UGCM";
27+
} else if (program === "all") {
28+
httpParameters["degreeType"] = "GR,UG";
29+
} else if (httpParameters.cert === "true" && program === "undergrad") {
2630
httpParameters["degreeType"] = "UGCM";
2731
} else if (program === "graduate") {
2832
httpParameters["degreeType"] = "GR";
@@ -47,20 +51,34 @@ function urlResolver(dataSource, defaultDataSource) {
4751
4852
*/
4953

50-
const { endpoint, include, ...keyValues } = httpParameters;
54+
const { endpoint, ...keyValues } = httpParameters;
5155

52-
const formattedIncludes = include
53-
.split(",")
54-
.map(item => `include=${item.trim()}`)
55-
.join("&");
56+
const splitParamsContainingCommas = (paramName, csvString) => {
57+
// httpParameters that are arrays format to send to API should have 1 paramName seperated by commas
58+
// input: paramName = "foo", csvString = ["bar", "baz"]
59+
// output: "foo=bar,baz"
60+
if (Array.isArray(csvString)) {
61+
return `${paramName}=${csvString}`;
62+
}
63+
// If the paramName is a string already including commas, we need to split it into multiple params
64+
// input: paramName = "foo", csvString = "bar,baz"
65+
// output: "foo=bar&foo=baz"
66+
return csvString
67+
.split(",")
68+
.map(item => `${paramName}=${item.trim()}`)
69+
.join("&");
70+
};
5671

5772
const params = Object.keys(keyValues).reduce(
5873
(accumulator, paramName) =>
59-
`${accumulator}&${paramName}=${httpParameters[paramName]}`,
74+
`${accumulator}&${splitParamsContainingCommas(
75+
paramName,
76+
httpParameters[paramName]
77+
)}`,
6078
""
6179
);
6280

63-
return `${endpoint}?${params}&${formattedIncludes}`;
81+
return `${endpoint}?${params}`;
6482
}
6583

6684
export { urlResolver };

0 commit comments

Comments
 (0)