Skip to content

Commit

Permalink
fix: server glossary entry service to return warnings, display ant no…
Browse files Browse the repository at this point in the history
…tifications
  • Loading branch information
efloden committed Jun 11, 2018
1 parent a3d3b3e commit 0711d65
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 51 deletions.
Expand Up @@ -337,6 +337,12 @@ public Response post(List<GlossaryEntry> glossaryEntries,
}
GlossaryResults results = saveOrUpdateGlossaryEntries(glossaryEntries,
Optional.of(localeId));
List<String> warnings = results.getWarnings();
if (!warnings.isEmpty()) {
return Response.status(Response.Status.BAD_REQUEST)
.entity(warnings)
.build();
}
return Response.ok(results).build();
}

Expand Down
Expand Up @@ -283,8 +283,8 @@ private Optional<String> checkForDuplicateEntry(GlossaryEntry from) {
// Different entry with same source content, pos and description
if (!sameHashEntry.getId().equals(from.getId())) {
return Optional.of("Duplicate glossary entry in source locale \'"
+ srcLocale + "\' ,source content \'" + srcTerm.getContent()
+ "\' ,pos \'" + from.getPos() + "\' ,description \'"
+ srcLocale + "\', source content \'" + srcTerm.getContent()
+ "\', pos \'" + from.getPos() + "\', description \'"
+ from.getDescription() + "\'");
}
return Optional.empty();
Expand Down
Expand Up @@ -13,8 +13,6 @@ import Input from 'antd/lib/input'
import 'antd/lib/input/style/'
import Modal from 'antd/lib/modal'
import 'antd/lib/modal/style/index.less'
import notification from 'antd/lib/notification'
import 'antd/lib/notification/style/css'

import {
glossaryToggleNewEntryModal,
Expand All @@ -27,7 +25,6 @@ class NewEntryModal extends Component {
entry: PropTypes.object,
isSaving: PropTypes.bool,
show: PropTypes.bool,
terms: PropTypes.object,
handleNewEntryDisplay: PropTypes.func,
handleNewEntryCreate: PropTypes.func
}
Expand Down Expand Up @@ -80,33 +77,12 @@ class NewEntryModal extends Component {
})
}

handleCreate = () => {
const { entry } = this.state
const { handleNewEntryCreate, terms } = this.props
const foundDuplicate = terms && Object.values(terms).some((term) => {
return (
term.description === entry.description &&
term.pos === entry.pos &&
term.srcTerm.content === entry.srcTerm.content
)
})
if (foundDuplicate) {
notification.error({
message: 'Could not create Glossary entry.',
description: 'Duplicate entry exists.',
duration: null
})
} else {
handleNewEntryCreate(this.state.entry)
this.resetFields()
}
}

render () {
const {
show,
isSaving,
handleNewEntryDisplay
handleNewEntryDisplay,
handleNewEntryCreate
} = this.props
const isAllowSave = !isEmpty(this.state.entry.srcTerm.content)

Expand All @@ -129,7 +105,11 @@ class NewEntryModal extends Component {
aria-label='button'
type='primary'
disabled={!isAllowSave || isSaving}
onClick={this.handleCreate}>
onClick={
() => {
handleNewEntryCreate(this.state.entry); this.resetFields()
}
}>
<LoaderText loading={isSaving} loadingText='Saving'>
Save
</LoaderText>
Expand Down Expand Up @@ -164,9 +144,8 @@ class NewEntryModal extends Component {
}

const mapStateToProps = (state) => {
const { terms } = state.glossary
const { entry, isSaving, show } = state.glossary.newEntry
return { entry, isSaving, show, terms }
return { entry, isSaving, show }
}

const mapDispatchToProps = (dispatch) => {
Expand Down
39 changes: 22 additions & 17 deletions server/zanata-frontend/src/app/containers/Glossary/index.js
Expand Up @@ -6,7 +6,7 @@ import { connect } from 'react-redux'
import Helmet from 'react-helmet'
import { isUndefined, size, map } from 'lodash'
import ReactList from 'react-list'
import { Icon, LoaderText, Select, Notification } from '../../components/'
import { Icon, LoaderText, Select } from '../../components/'
import { Row } from 'react-bootstrap'
import {
glossaryDeleteTerm,
Expand All @@ -27,6 +27,10 @@ import ViewHeader from './ViewHeader'
import Entry from './Entry'
import Button from 'antd/lib/button'
import Layout from 'antd/lib/layout'
import Notification from 'antd/lib/notification'
import 'antd/lib/notification/style/css'

/* eslint-disable */

/**
* Root component for Glossary page
Expand Down Expand Up @@ -71,7 +75,7 @@ class Glossary extends Component {
pageSize: PropTypes.string
}

componentDidMount () {
componentDidMount() {
const paramProjectSlug = this.props.params.projectSlug
const projectSlug = (!paramProjectSlug || paramProjectSlug === 'undefined')
? undefined : paramProjectSlug
Expand All @@ -82,11 +86,19 @@ class Glossary extends Component {
/**
* Force component to update when changes between project glossary to glossary
*/
componentDidUpdate (prevProps, prevState) {
componentDidUpdate(prevProps, prevState) {
const projectSlug = this.props.params.projectSlug
const { notification } = this.props
if (prevProps.params.projectSlug !== projectSlug) {
this.props.handleInitLoad(projectSlug)
}
if (notification && prevProps.notification !== notification) {
Notification[notification.severity]({
message: notification.message,
description: notification.description,
duration: notification.duration
})
}
}

/**
Expand All @@ -102,7 +114,7 @@ class Glossary extends Component {
* this function, but this stops working properly unless binding is done
* inline in the JSX. Hope you have a good garbage collector.
*/
renderItem (index, key) {
renderItem(index, key) {
const {
handleSelectTerm,
handleTermFieldUpdate,
Expand Down Expand Up @@ -151,7 +163,7 @@ class Glossary extends Component {
)
}

render () {
render() {
const {
terms,
termsLoading,
Expand All @@ -173,7 +185,7 @@ class Glossary extends Component {
const currentPage = page ? parseInt(page) : 1
const displayPaging = totalPage > 1
const pageSizeOption = map(PAGE_SIZE_SELECTION, (size) => {
return {label: size, value: size}
return { label: size, value: size }
})
const headerTitle = project ? 'Project Glossary' : 'Glossary'
let list
Expand Down Expand Up @@ -202,13 +214,6 @@ class Glossary extends Component {

return (
<div>
{notification &&
(<Notification severity={notification.severity}
message={notification.message}
details={notification.details}
show={!!notification} />
)
}
<Helmet title={headerTitle} />
<div className='wideView' id='glossary'>
<Layout>
Expand Down Expand Up @@ -241,9 +246,9 @@ class Glossary extends Component {
className='btn-link' disabled={currentPage <= 1}
title='Previous page' icon='left'
onClick={
() => {
gotoPreviousPage(currentPage, totalPage)
}}
() => {
gotoPreviousPage(currentPage, totalPage)
}}
/>
<span className='u-textNeutral-top'>
{currentPage} of {totalPage}
Expand Down Expand Up @@ -271,7 +276,7 @@ class Glossary extends Component {
</Row>
</span>
</div>
}
}
</Row>
</div>

Expand Down
8 changes: 5 additions & 3 deletions server/zanata-frontend/src/app/reducers/glossary-reducer.js
Expand Up @@ -545,7 +545,8 @@ const glossary = handleActions({
},
notification: {
severity: SEVERITY.INFO,
message: 'Glossary term created.'
message: 'Glossary term created.',
duration: 5
}
}
},
Expand All @@ -562,8 +563,9 @@ const glossary = handleActions({
notification: {
severity: SEVERITY.ERROR,
message:
'We were unable save glossary entry. ' +
'Please refresh this page and try again.'
'We were unable to save the glossary entry.',
description: action.payload.response,
duration: null
}
}
},
Expand Down

0 comments on commit 0711d65

Please sign in to comment.