-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
361 additions
and
27 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
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
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
34 changes: 34 additions & 0 deletions
34
app/react/ToggledFeatures/tocGeneration/ReviewTocButton.tsx
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { Icon } from 'UI'; | ||
import { FeatureToggle } from 'app/components/Elements/FeatureToggle'; | ||
import { connect, ConnectedProps } from 'react-redux'; | ||
import { bindActionCreators, Dispatch } from 'redux'; | ||
import { ClientFile } from 'app/istore'; | ||
import { tocGenerationActions } from './actions'; | ||
|
||
export interface ReviewTocButtonProps { | ||
file: ClientFile; | ||
children: JSX.Element | string; | ||
} | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch<{}>) => | ||
bindActionCreators({ onClick: tocGenerationActions.reviewToc }, dispatch); | ||
|
||
const connector = connect(null, mapDispatchToProps); | ||
|
||
type MappedProps = ConnectedProps<typeof connector>; | ||
type ComponentProps = ReviewTocButtonProps & MappedProps; | ||
|
||
const ReviewTocButton = ({ file, onClick, children }: ComponentProps) => ( | ||
<FeatureToggle feature="tocGeneration"> | ||
{file.generatedToc && ( | ||
<button type="button" onClick={() => onClick(file._id)} className="edit-toc btn btn-success"> | ||
<Icon icon="pencil-alt" /> | ||
<span className="btn-label">{children}</span> | ||
</button> | ||
)} | ||
</FeatureToggle> | ||
); | ||
|
||
const container = connector(ReviewTocButton); | ||
export { container as ReviewTocButton }; |
14 changes: 14 additions & 0 deletions
14
app/react/ToggledFeatures/tocGeneration/TocGeneratedLabel.tsx
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { FeatureToggle } from 'app/components/Elements/FeatureToggle'; | ||
import { FileType } from 'shared/types/fileType'; | ||
|
||
export interface TocGeneratedLabelProps { | ||
file: FileType; | ||
children: JSX.Element | string; | ||
} | ||
|
||
export const TocGeneratedLabel = ({ file, children }: TocGeneratedLabelProps) => ( | ||
<FeatureToggle feature="tocGeneration"> | ||
{file.generatedToc && <span className="label-generatedToc">{children}</span>} | ||
</FeatureToggle> | ||
); |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { actions } from 'app/BasicReducer/reducer'; | ||
import { actions as formActions } from 'react-redux-form'; | ||
import { RequestParams } from 'app/utils/RequestParams'; | ||
import api from 'app/utils/api'; | ||
import { notificationActions } from 'app/Notifications'; | ||
|
||
const tocGenerationActions = { | ||
reviewToc(fileId: string) { | ||
return async (dispatch, getState) => { | ||
const currentDoc = getState().documentViewer.doc.toJS(); | ||
dispatch(formActions.reset('documentViewer.sidepanel.metadata')); | ||
|
||
const updatedFile = (await api.post('files/tocReviewed', new RequestParams({ fileId }))).json; | ||
//WTF | ||
updatedFile.pdfInfo = {} | ||
const doc = { | ||
...currentDoc, | ||
defaultDoc: updatedFile, | ||
documents: currentDoc.documents.map(d => { | ||
if (d._id === updatedFile._id) { | ||
return updatedFile; | ||
} | ||
return d; | ||
}), | ||
}; | ||
|
||
dispatch(notificationActions.notify('Document updated', 'success')); | ||
dispatch(formActions.reset('documentViewer.sidepanel.metadata')); | ||
dispatch(actions.set('viewer/doc', doc)); | ||
}; | ||
}, | ||
}; | ||
|
||
export { tocGenerationActions }; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { TocGeneratedLabel } from './TocGeneratedLabel'; | ||
export { ReviewTocButton } from './ReviewTocButton'; | ||
export { tocGenerationUtils } from './utils'; |
37 changes: 37 additions & 0 deletions
37
app/react/ToggledFeatures/tocGeneration/specs/ReviewTocButton.spec.tsx
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import configureStore, { MockStore, MockStoreCreator } from 'redux-mock-store'; | ||
import { Provider } from 'react-redux'; | ||
import { FileType } from 'shared/types/fileType'; | ||
import { ReviewTocButton } from '../ReviewTocButton'; | ||
|
||
describe('ReviewTocButton', () => { | ||
let component: ShallowWrapper<typeof ReviewTocButton>; | ||
|
||
const mockStoreCreator: MockStoreCreator<object> = configureStore<object>([]); | ||
const render = (file: FileType) => { | ||
const store: MockStore<object> = mockStoreCreator({}); | ||
component = shallow( | ||
<Provider store={store}> | ||
<ReviewTocButton file={file}> | ||
<span>test</span> | ||
</ReviewTocButton> | ||
</Provider> | ||
) | ||
.dive() | ||
.dive(); | ||
}; | ||
|
||
it('should render nothing if file generatedToc is false', () => { | ||
render({ generatedToc: false }); | ||
expect(component.find('button').length).toEqual(0); | ||
|
||
render({}); | ||
expect(component.find('button').length).toEqual(0); | ||
}); | ||
|
||
it('should render when generatedToc is true', () => { | ||
render({ generatedToc: true }); | ||
expect(component.find('button').length).toEqual(1); | ||
}); | ||
}); |
Oops, something went wrong.