Skip to content

Commit 98a762f

Browse files
refactor: migrate subscriptions bulk enrollment and highlights to withAlgoliaSearch (#1443)
1 parent e841225 commit 98a762f

36 files changed

+954
-357
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"i18n_extract": "fedx-scripts formatjs extract --throws",
1212
"build:with-theme": "paragon install-theme && fedx-scripts webpack && npm install",
1313
"check-types": "tsc --noemit",
14+
"check-types:watch": "npm run check-types -- --watch",
1415
"eslint": "fedx-scripts eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
15-
"lint": "npm run eslint && npm run check-types",
16+
"lint": "npm run eslint",
1617
"lint:fix": "npm run eslint -- --fix",
1718
"precommit": "npm run lint",
1819
"prepublishOnly": "npm run build",
@@ -24,7 +25,7 @@
2425
"debug-test": "node --inspect-brk node_modules/.bin/jest --runInBand --coverage",
2526
"test": "TZ=UTC fedx-scripts jest --coverage --passWithNoTests --maxWorkers=50%",
2627
"test:watch": "npm run test -- --watch",
27-
"test:watch-no-cov": "npm run test -- --watch --collectCoverage=false",
28+
"test:watch-no-cov": "npm run test:watch -- --collectCoverage=false",
2829
"snapshot": "fedx-scripts jest --updateSnapshot"
2930
},
3031
"license": "AGPL-3.0",

src/components/BulkEnrollmentPage/BulkEnrollmentContext.jsx renamed to src/components/BulkEnrollmentPage/BulkEnrollmentContext.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,60 @@
1-
import React, {
1+
import {
22
createContext, useState, useReducer, useMemo,
33
} from 'react';
44
import PropTypes from 'prop-types';
55

6-
import selectedRowsReducer from './data/reducer';
6+
import selectedRowsReducer, { Action, SelectedRow } from './data/reducer';
77

8-
export const BulkEnrollContext = createContext({});
8+
export type Subscription = {
9+
uuid: string;
10+
enterpriseCatalogUuid: string;
11+
};
12+
13+
export type BulkEnrollContextValue = {
14+
courses: [SelectedRow[], React.Dispatch<Action>],
15+
emails: [SelectedRow[], React.Dispatch<Action>],
16+
subscription: [Subscription | null, React.Dispatch<React.SetStateAction<Subscription>>],
17+
};
18+
19+
export const BulkEnrollContext = createContext<BulkEnrollContextValue>({
20+
courses: [[], () => {}],
21+
emails: [[], () => {}],
22+
subscription: [null, () => {}],
23+
});
924

10-
const BulkEnrollContextProvider = ({ children, initialEmailsList }) => {
25+
interface BulkEnrollContextProviderProps {
26+
children: React.ReactNode;
27+
initialEmailsList?: string[];
28+
}
29+
30+
const BulkEnrollContextProvider: React.FC<BulkEnrollContextProviderProps> = ({ children, initialEmailsList = [] }) => {
1131
const [selectedCourses, coursesDispatch] = useReducer(selectedRowsReducer, []);
1232
// this format is to make this consistent with the format used by ReviewStep components
1333
// similar to DataTable row objects, but not exactly
14-
const formattedEmailsList = initialEmailsList.map(email => ({
34+
const formattedEmailsList: SelectedRow[] = initialEmailsList.map(email => ({
1535
id: email,
1636
values: {
1737
userEmail: email,
1838
},
1939
}));
2040
const [selectedEmails, emailsDispatch] = useReducer(selectedRowsReducer, formattedEmailsList);
21-
const [selectedSubscription, setSelectedSubscription] = useState({});
41+
const [selectedSubscription, setSelectedSubscription] = useState<Subscription>();
2242

2343
const contextValue = useMemo(
2444
() => ({
2545
courses: [selectedCourses, coursesDispatch],
2646
emails: [selectedEmails, emailsDispatch],
2747
subscription: [selectedSubscription, setSelectedSubscription],
28-
}),
48+
} as BulkEnrollContextValue),
2949
[selectedCourses, selectedEmails, selectedSubscription],
3050
);
3151

3252
return <BulkEnrollContext.Provider value={contextValue}>{children}</BulkEnrollContext.Provider>;
3353
};
3454

35-
BulkEnrollContextProvider.defaultProps = {
36-
initialEmailsList: [],
37-
};
38-
3955
BulkEnrollContextProvider.propTypes = {
4056
children: PropTypes.node.isRequired,
41-
initialEmailsList: PropTypes.arrayOf(PropTypes.string),
57+
initialEmailsList: PropTypes.arrayOf(PropTypes.string.isRequired),
4258
};
4359

4460
export default BulkEnrollContextProvider;

src/components/BulkEnrollmentPage/data/reducer.js

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
SET_SELECTED_ROWS,
3+
DELETE_ROW,
4+
CLEAR_SELECTION,
5+
} from './actions';
6+
7+
export type SelectedRow = {
8+
id: unknown;
9+
values?: {
10+
userEmail?: string;
11+
};
12+
};
13+
14+
export type State = SelectedRow[];
15+
16+
export type Action =
17+
| { type: typeof SET_SELECTED_ROWS, payload: SelectedRow[] }
18+
| { type: typeof DELETE_ROW, payload: unknown }
19+
| { type: typeof CLEAR_SELECTION };
20+
21+
const selectedRowsReducer = (state: State = [], action: Action) => {
22+
switch (action.type) {
23+
case SET_SELECTED_ROWS:
24+
return action.payload;
25+
case DELETE_ROW:
26+
return state.filter((row) => row.id !== action.payload);
27+
case CLEAR_SELECTION:
28+
return [];
29+
default:
30+
return state;
31+
}
32+
};
33+
34+
export default selectedRowsReducer;

src/components/BulkEnrollmentPage/stepper/AddCoursesStep.jsx

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/components/BulkEnrollmentPage/stepper/AddCoursesStep.test.jsx

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)