Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[student-libraries] Exporter ui fail #31502

Merged
merged 7 commits into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/i18n/common/en_us.json
Expand Up @@ -795,8 +795,9 @@
"libraryExportNoCommentError": "This function cannot be exported until you add a comment to it.",
"libraryExportTitle": "Export Functions as a Library",
"libraryName": "Library Name:",
"libraryPublishTitle": "Successfully published your library: ",
"libraryPublishExplanation": "Share this ID with others so they can use your library in their project:",
"libraryPublishFail": "There was an error publishing your library. Please check your internet connection and try again.",
"libraryPublishTitle": "Successfully published your library: ",
"linesOfCode": "Lines of Code",
"listVariable": "list",
"loading": "Loading...",
Expand Down
Expand Up @@ -13,10 +13,12 @@ import Button from '@cdo/apps/templates/Button';

const styles = {
alert: {
color: 'red'
color: 'red',
width: '90%'
},
libraryBoundary: {
padding: 10
padding: 10,
width: '90%'
},
largerCheckbox: {
width: 20,
Expand Down Expand Up @@ -55,7 +57,8 @@ function select(event) {
export const LoadingState = {
LOADING: 'loading',
DONE_LOADING: 'done_loading',
PUBLISHED: 'published'
PUBLISHED: 'published',
ERROR_PUBLISH: 'error_publish'
};

class LibraryCreationDialog extends React.Component {
Expand Down Expand Up @@ -128,6 +131,7 @@ class LibraryCreationDialog extends React.Component {
libraryJson,
error => {
console.warn(`Error publishing library: ${error}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still want this console warn now that there's UI for it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jessie and I chatted and we decided yes, because then we can help debug if someone writes in with issues.

this.setState({loadingState: LoadingState.ERROR_PUBLISH});
},
() => {
this.setState({loadingState: LoadingState.PUBLISHED});
Expand Down Expand Up @@ -213,9 +217,11 @@ class LibraryCreationDialog extends React.Component {
disabled={!this.state.canPublish}
/>
{this.state.loadingState === LoadingState.ERROR_PUBLISH && (
<p id="error-alert" style={styles.alert}>
{i18n.libraryPublishFail()}
</p>
<div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this container div needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked the idea of having this state-specific behavior in a div, but it's not necessarily needed. I'm going to leave for now to avoid delaying this PR.

<p id="error-alert" style={styles.alert}>
{i18n.libraryPublishFail()}
</p>
</div>
)}
</div>
</form>
Expand Down
Expand Up @@ -41,6 +41,7 @@ describe('LibraryCreationDialog', () => {
const CHECKBOX_SELECTOR = 'input[type="checkbox"]';
const DESCRIPTION_SELECTOR = 'textarea';
const CHANNEL_ID_SELECTOR = 'input[type="text"]';
const PUBLISH_ERROR_SELECTOR = '#error-alert';

before(() => {
replaceOnWindow('dashboard', {
Expand Down Expand Up @@ -157,6 +158,28 @@ describe('LibraryCreationDialog', () => {
wrapper.find(CHANNEL_ID_SELECTOR).instance().value === '123'
);
});

it('does not display publish error message when loading is finished before publish', () => {
wrapper.setState({
libraryName: 'testLibrary',
librarySource: LIBRARY_SOURCE,
loadingState: LoadingState.LOADING,
sourceFunctionList: libraryParser.getFunctions(LIBRARY_SOURCE)
});

expect(wrapper.find(PUBLISH_ERROR_SELECTOR).exists()).to.be.false;
});

it('displays publish error message after being set to error state', () => {
wrapper.setState({
libraryName: 'testLibrary',
librarySource: LIBRARY_SOURCE,
loadingState: LoadingState.ERROR_PUBLISH,
sourceFunctionList: libraryParser.getFunctions(LIBRARY_SOURCE)
});

expect(wrapper.find(PUBLISH_ERROR_SELECTOR).exists()).to.be.true;
});
});

describe('publish', () => {
Expand Down