forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a button to return to studio (openedx#322)
- Loading branch information
1 parent
6aaedfc
commit c49779a
Showing
12 changed files
with
453 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 32 additions & 26 deletions
58
src/editors/__snapshots__/VideoSelectorPage.test.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,51 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Video Selector Page snapshots rendering correctly with expected Input 1`] = ` | ||
<ErrorBoundary> | ||
<Provider | ||
store={ | ||
Object { | ||
"dispatch": [Function], | ||
"getState": [Function], | ||
"replaceReducer": [Function], | ||
"subscribe": [Function], | ||
Symbol(Symbol.observable): [Function], | ||
} | ||
<Provider | ||
store={ | ||
Object { | ||
"dispatch": [Function], | ||
"getState": [Function], | ||
"replaceReducer": [Function], | ||
"subscribe": [Function], | ||
Symbol(Symbol.observable): [Function], | ||
} | ||
} | ||
> | ||
<ErrorBoundary | ||
learningContextId="course-v1:edX+DemoX+Demo_Course" | ||
studioEndpointUrl="fakeurl.com" | ||
> | ||
<Component | ||
<VideoSelector | ||
learningContextId="course-v1:edX+DemoX+Demo_Course" | ||
lmsEndpointUrl="evenfakerurl.com" | ||
studioEndpointUrl="fakeurl.com" | ||
/> | ||
</Provider> | ||
</ErrorBoundary> | ||
</ErrorBoundary> | ||
</Provider> | ||
`; | ||
|
||
exports[`Video Selector Page snapshots rendering with props to null 1`] = ` | ||
<ErrorBoundary> | ||
<Provider | ||
store={ | ||
Object { | ||
"dispatch": [Function], | ||
"getState": [Function], | ||
"replaceReducer": [Function], | ||
"subscribe": [Function], | ||
Symbol(Symbol.observable): [Function], | ||
} | ||
<Provider | ||
store={ | ||
Object { | ||
"dispatch": [Function], | ||
"getState": [Function], | ||
"replaceReducer": [Function], | ||
"subscribe": [Function], | ||
Symbol(Symbol.observable): [Function], | ||
} | ||
} | ||
> | ||
<ErrorBoundary | ||
learningContextId={null} | ||
studioEndpointUrl={null} | ||
> | ||
<Component | ||
<VideoSelector | ||
learningContextId={null} | ||
lmsEndpointUrl={null} | ||
studioEndpointUrl={null} | ||
/> | ||
</Provider> | ||
</ErrorBoundary> | ||
</ErrorBoundary> | ||
</Provider> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,89 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Button, Container, Row, Col, | ||
} from '@edx/paragon'; | ||
|
||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import messages from './messages'; | ||
import { navigateTo } from '../../hooks'; | ||
import { selectors } from '../../data/redux'; | ||
|
||
/** | ||
* An error page that displays a generic message for unexpected errors. Also contains a "Try | ||
* Again" button to refresh the page. | ||
*/ | ||
export const ErrorPage = ({ | ||
message, | ||
studioEndpointUrl, | ||
learningContextId, | ||
// redux | ||
unitData, | ||
// injected | ||
intl, | ||
}) => ( | ||
<Container fluid className="py-5 justify-content-center align-items-start text-center"> | ||
<Row> | ||
<Col> | ||
<p className="text-muted"> | ||
{intl.formatMessage(messages.unexpectedError)} | ||
</p> | ||
{message && ( | ||
<div role="alert" className="my-4"> | ||
<p>{message}</p> | ||
</div> | ||
)} | ||
<Button onClick={global.location.reload()}> | ||
{intl.formatMessage(messages.unexpectedErrorButtonLabel)} | ||
</Button> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}) => { | ||
const outlineType = learningContextId?.startsWith('library-v1') ? 'library' : 'course'; | ||
const outlineUrl = `${studioEndpointUrl}/${outlineType}/${learningContextId}`; | ||
const unitUrl = unitData?.data ? `${studioEndpointUrl}/container/${unitData?.data.ancestors[0].id}` : null; | ||
|
||
return ( | ||
<Container fluid className="py-5 justify-content-center align-items-start text-center"> | ||
<Row> | ||
<Col> | ||
<p className="text-muted"> | ||
{intl.formatMessage(messages.unexpectedError)} | ||
</p> | ||
{message && ( | ||
<div role="alert" className="my-4"> | ||
<p>{message}</p> | ||
</div> | ||
)} | ||
<Row className="justify-content-center"> | ||
{learningContextId && (unitUrl && outlineType !== 'library' ? ( | ||
<Button className="mr-2" variant="outline-primary" onClick={() => navigateTo(unitUrl)}> | ||
{intl.formatMessage(messages.returnToUnitPageLabel)} | ||
</Button> | ||
) : ( | ||
<Button className="mr-2" variant="outline-primary" onClick={() => navigateTo(outlineUrl)}> | ||
{intl.formatMessage(messages.returnToOutlineLabel, { outlineType })} | ||
</Button> | ||
))} | ||
<Button className="ml-2" onClick={() => global.location.reload()}> | ||
{intl.formatMessage(messages.unexpectedErrorButtonLabel)} | ||
</Button> | ||
</Row> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
ErrorPage.propTypes = { | ||
message: PropTypes.string, | ||
learningContextId: PropTypes.string.isRequired, | ||
studioEndpointUrl: PropTypes.string.isRequired, | ||
// redux | ||
unitData: PropTypes.shape({ | ||
data: PropTypes.shape({ | ||
ancestors: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string, | ||
}), | ||
), | ||
}), | ||
}), | ||
// injected | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
ErrorPage.defaultProps = { | ||
message: null, | ||
unitData: null, | ||
}; | ||
|
||
export default injectIntl(ErrorPage); | ||
export const mapStateToProps = (state) => ({ | ||
unitData: selectors.app.unitUrl(state), | ||
}); | ||
|
||
export default injectIntl(connect(mapStateToProps)(ErrorPage)); |
Oops, something went wrong.