fix: [AA-1018] api cleanup

Fix error when moving from courseHome to courseware.
This commit is contained in:
Chris Deery
2022-02-04 11:48:58 -05:00
parent 64b0c03d30
commit ec1c3da725
4 changed files with 12 additions and 5 deletions

View File

@@ -24,7 +24,7 @@ function UnitNavigationEffortEstimate({
const sequence = useModel('sequences', sequenceId);
const nextSequence = useModel('sequences', nextSequenceId);
if (!sequence || !nextSequence) {
if (!sequence || Object.keys(sequence).length === 0 || !nextSequence || Object.keys(nextSequence).length === 0) {
return children;
}

View File

@@ -1,8 +1,11 @@
import { useSelector, shallowEqual } from 'react-redux';
/*
Return the selected model with the given id, or an empty object if the model does not exist "{}".
*/
export function useModel(type, id) {
return useSelector(
state => (state.models[type] !== undefined ? state.models[type][id] : {}),
state => ((state.models[type] !== undefined && state.models[type][id] !== undefined) ? state.models[type][id] : {}),
shallowEqual,
);
}
@@ -10,7 +13,7 @@ export function useModel(type, id) {
export function useModels(type, ids) {
return useSelector(
state => ids.map(
id => (state.models[type] !== undefined ? state.models[type][id] : {}),
id => ((state.models[type] !== undefined && state.models[type][id] !== undefined) ? state.models[type][id] : {}),
),
shallowEqual,
);

View File

@@ -10,6 +10,7 @@ export default function TabContainer(props) {
const {
children,
fetch,
slice,
tab,
} = props;
@@ -25,14 +26,14 @@ export default function TabContainer(props) {
const {
courseId,
courseStatus,
} = useSelector(state => state.courseHome);
} = useSelector(state => state[slice]);
return (
<TabPage
activeTabSlug={tab}
courseId={courseId}
courseStatus={courseStatus}
metadataModel="courseHomeMeta"
metadataModel={`${slice}Meta`}
>
{courseId && <OuterExamTimer courseId={courseId} />}
{children}
@@ -43,5 +44,6 @@ export default function TabContainer(props) {
TabContainer.propTypes = {
children: PropTypes.node.isRequired,
fetch: PropTypes.func.isRequired,
slice: PropTypes.string.isRequired,
tab: PropTypes.string.isRequired,
};

View File

@@ -22,6 +22,7 @@ describe('Tab Container', () => {
mockData = {
fetch: mockFetch,
tab: 'dummy',
slice: 'courseware',
};
const store = await initializeTestStore({ excludeFetchSequence: true });
courseId = store.getState().courseware.courseId;
@@ -57,6 +58,7 @@ describe('Tab Container', () => {
<TabContainer
fetch={() => mockFetch(match.params.courseId, match.params.targetUserId)}
tab="dummy"
slice="courseHome"
>
children={[]}
</TabContainer>