fix: [AA-1018] api cleanup
Fix error when moving from courseHome to courseware.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user