Skip to content

Commit

Permalink
Merge pull request #24 from contentful/smartling-fixes
Browse files Browse the repository at this point in the history
adding more error handling to smartling
  • Loading branch information
davidfateh authored Feb 12, 2020
2 parents 56fc7a1 + 9128448 commit 6fd3174
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 11 deletions.
9 changes: 5 additions & 4 deletions apps/smartling/frontend/src/AppConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
Typography,
FieldGroup,
CheckboxField,
TextField
TextField,
TextLink
} from '@contentful/forma-36-react-components';
import get from 'lodash.get';
// @ts-ignore 2307
Expand Down Expand Up @@ -85,7 +86,7 @@ export default class AppConfig extends React.Component<Props, State> {
};

setProjectId(id: string) {
this.setState({ projectId: id });
this.setState({ projectId: id.trim() });
}

toggleCt(id: string) {
Expand Down Expand Up @@ -115,7 +116,7 @@ export default class AppConfig extends React.Component<Props, State> {
<Heading>About Smartling</Heading>
<Paragraph className="about-p">
This app allows you to view the translation status of entries in the Contentful
web app and easily find corresponding entries within Smartling.
web app and easily find corresponding entries within a <TextLink href="https://dashboard.smartling.com" target="_blank" rel="noopener noreferrer">Smartling</TextLink> project.
</Paragraph>
</Typography>
<hr />
Expand All @@ -134,7 +135,7 @@ export default class AppConfig extends React.Component<Props, State> {
value={this.state.projectId}
// @ts-ignore 2339
onChange={e => this.setProjectId(e.target.value)}
helpText="To get the project ID, see the 'API' settings of your Smartling project."
helpText="To get the project ID, see the 'Project Settings > API' of your Smartling project."
/>
<Typography>
<Heading>Assign to content types</Heading>
Expand Down
26 changes: 23 additions & 3 deletions apps/smartling/frontend/src/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
TextLink,
SkeletonContainer,
SkeletonImage,
Spinner
Spinner,
Note
} from '@contentful/forma-36-react-components';
import smartlingClient from './smartlingClient';

Expand All @@ -24,6 +25,7 @@ interface State {
token: string;
refreshToken: string;
showAllSubs: boolean;
generalError: boolean;
}

const SUBS_TO_SHOW = 3;
Expand Down Expand Up @@ -127,7 +129,8 @@ export default class Sidebar extends React.Component<Props, State> {
smartlingEntry: null,
token: window.localStorage.getItem('token') || '',
refreshToken: window.localStorage.getItem('refreshToken') || '',
showAllSubs: false
showAllSubs: false,
generalError: false,
};

componentDidMount() {
Expand Down Expand Up @@ -177,6 +180,8 @@ export default class Sidebar extends React.Component<Props, State> {
smartlingEntry: formatSmartlingEntry(res.data),
showAllSubs: res.data.translationSubmissions.length <= SUBS_TO_SHOW
});
} else {
this.setState({generalError: true});
}
};

Expand All @@ -197,7 +202,7 @@ export default class Sidebar extends React.Component<Props, State> {

render() {
const { sdk, projectId } = this.props;
const { smartlingEntry, token, showAllSubs } = this.state;
const { smartlingEntry, token, showAllSubs, generalError } = this.state;
const smartlingLink = makeSmartlingLink(projectId, sdk.ids.entry, sdk.ids.space);

const requestButton = (
Expand Down Expand Up @@ -293,8 +298,23 @@ export default class Sidebar extends React.Component<Props, State> {
</div>
);
} else {
statusTag = <></>;
smartlingBody = <></>;
}
} else if (generalError) {
statusTag = (
<Tag className="job-status" tagType="negative">
Disconnected
</Tag>
);

smartlingBody = (
<Note title="Connection error" noteType="negative" className="general-error">
Please ensure that you have access to the connected Smartling project.
<br />
<TextLink href="https://contentful.com/developers/docs/extensibility/apps/smartling/" target="_blank" rel="noopener noreferrer">View documentation</TextLink>
</Note>
);
}

return (
Expand Down
Loading

0 comments on commit 6fd3174

Please sign in to comment.