-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
Add datasets importing functionality #201
Closed
Closed
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
de78f6b
feat(server/helpers): Add import search
shivam-tripathi acc103f
feat(helpers/utils): Add function to get import models
shivam-tripathi e60449e
feat(helpers/utils): Add function to get import model by name
shivam-tripathi 56670ee
feat(helpers/utils): Add JSDocs for import functions
shivam-tripathi b272cc3
feat(server/helpers/search): Add import support in _fetchEntityModels…
shivam-tripathi c0b695e
feat(server/helpers/): Update licenses
shivam-tripathi 870e0f0
feat(client/components/pages/search): Update search with message for …
shivam-tripathi cf4680e
feat(client/components/pages/parts/search-results): Update search res…
shivam-tripathi 203dc05
feat(client/containers/layout): Add panel link to recent imports
shivam-tripathi 90be205
feat(scripts): Update build-client-js and watch-client-js to track re…
shivam-tripathi 0de46fa
feat(server/routes/imports/recent): Add routes to handle recent imports
shivam-tripathi 3ad38bf
feat(client/controllers/recentImports): Add recentImports controller
shivam-tripathi 8de2735
feat(client/components/pages/parts/recentImports): Add part to hold r…
shivam-tripathi 53b0b6f
feat(client/components/pages/recentImports): Add base component to di…
shivam-tripathi 61657de
feat(server/routes): Add imports route
shivam-tripathi 0344296
feat(client/helpers/utils): Add function to extract imports url
shivam-tripathi 4513011
feat(client/helpers/pagination-props): Add function to determine pagi…
shivam-tripathi 08b4d0a
feat(scripts): Add build and watch command in client scripts for impo…
shivam-tripathi 1426f1f
feat(client/helpers/props): Add function to extract import entity props
shivam-tripathi 2854bff
feat(client/controllers/import-entity): Add import-entity controller
shivam-tripathi 913c54b
feat(client/helpers/import-entity): Add import-entity helper functions
shivam-tripathi 208fc7e
feat(client/components/pages/import-entities/footer): Add footer for …
shivam-tripathi 49639b8
feat(src/client/components/pages/import-entities/title): Add title fr…
shivam-tripathi 2f78a55
feat(src/client/components/pages/import-entities/footer): Remove unne…
shivam-tripathi 21915cd
feat(client/components/pages/import-entities): Add import-entities pages
shivam-tripathi 37ae6a2
feat(server/routes/import-entity): Refactor, add more routes
shivam-tripathi ae662d0
feat(recent-imports): Refactor code
shivam-tripathi 06e8219
feat(scripts/client): Update client build and watch scripts
shivam-tripathi 45fc92d
feat(package.json): Add uuid module
shivam-tripathi f5fba4b
feat(client/components/pages/entities): Make compulsory props of imag…
shivam-tripathi fdc8f17
refactor(client/components/pages/parts/recent-import-results)
shivam-tripathi 48bd1b4
feat(client/discard-import-entity): Add confirm discard vote cast page
shivam-tripathi 8d738f7
feat(client/controllers/recent-imports): Move recent-imports controll…
shivam-tripathi e563583
feat(client/controllers/import-entity): Add controller for import-ent…
shivam-tripathi 2c25f13
refactor(client/helpers/utils): Remove unused function
shivam-tripathi b68bbab
feat(client/helpers/import-entity): Add import-entity helper function…
shivam-tripathi 8ba3a82
feat(client/import-entities/footer): Add feature to prevent multiple …
shivam-tripathi 560d24b
feat(client/components/pages/import-entities): Add import-entity pages
shivam-tripathi 2598bdf
feat(client/entity-editor/submission-section): Add logic for redirect…
shivam-tripathi 7c07651
feat(server/helpers/middleware): Add middleware to load imports into …
shivam-tripathi 0374e40
feat(server/helpers/importEntityRouteUtils): Add logic to load edit p…
shivam-tripathi 5fd6e9a
feat(server/helpers/utils): Add function to validate importId, could …
shivam-tripathi cab5b6a
feat(server/routes/import-entity/transform-form): Add module to trans…
shivam-tripathi b263307
feat(server/routes/import-entity/transform-import): Add module to tra…
shivam-tripathi a5b18db
feat(server/routes/import-entity/import-routes): Add import route hel…
shivam-tripathi 0987520
feat(server/routes/import-entity): Add entity functions, update index
shivam-tripathi c8cb4d0
refactor(server/routes): Update routes to reflect import-entities
shivam-tripathi e450dec
feat(server/routes/import-entity): Add entity routes
shivam-tripathi 762ccd9
feat(client/recent-imports): Add maximum button limit
shivam-tripathi 26d82a7
feat(components/parts/search): Remove inline styles, add break before…
shivam-tripathi 18fc335
feat(client/components/pages/entities): Export all attributes functions
shivam-tripathi 29e3ada
feat(client/commit/pages/import-entities): Reuse attribute functions …
shivam-tripathi 154f76c
feat(client/components/import-entities): Remove inline css
shivam-tripathi 84989c7
feat(discard-import-entity): Remove token mechanism
shivam-tripathi 18199d5
feat(client/import-entity/footer): Change name
shivam-tripathi 35ea8b0
refactor: General refactor, remove redundant code, update credits
shivam-tripathi 2afd166
feat(stylesheets/style.less): Add some style classes
shivam-tripathi b15a144
feat(client/helpers/import-entity): Add space after label, refactor
shivam-tripathi b61c993
feat(client/components/search-results): Use labels to denote imports
shivam-tripathi f8bb16c
feat(client/controllers/import-entity): Improve error handling when l…
shivam-tripathi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import * as bootstrap from 'react-bootstrap'; | ||
import PaginationProps from '../../helpers/pagination-props'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import RecentImportsTable from './parts/recent-import-results'; | ||
import request from 'superagent-bluebird-promise'; | ||
|
||
|
||
const {PageHeader, Pagination} = bootstrap; | ||
|
||
class RecentImports extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.paginationPropsGenerator = PaginationProps({ | ||
displayedPagesRange: 10, | ||
itemsPerPage: props.limit | ||
}); | ||
|
||
this.state = { | ||
currentPage: props.currentPage, | ||
offset: 0, | ||
paginationProps: { | ||
hasBeginningPage: false, | ||
hasEndPage: false, | ||
hasNextPage: false, | ||
hasPreviousPage: false, | ||
totalPages: 0 | ||
}, | ||
recentImports: [] | ||
}; | ||
|
||
this.handleClick = this.handleClick.bind(this); | ||
this.handleCb = this.handleCb.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
this.handleClick(this.state.currentPage); | ||
} | ||
|
||
componentDidUpdate() { | ||
window.history.replaceState( | ||
null, null, `?page=${this.state.currentPage}` | ||
); | ||
} | ||
|
||
async handleClick(pageNumber) { | ||
const {currentPage, limit, offset, totalResults, recentImports} = | ||
await request.get(`/imports/recent/raw?page=${pageNumber}`) | ||
.then((res) => JSON.parse(res.text)); | ||
|
||
const paginationProps = this.paginationPropsGenerator( | ||
totalResults, currentPage | ||
); | ||
|
||
this.setState({ | ||
currentPage, limit, offset, paginationProps, recentImports, | ||
totalResults | ||
}); | ||
} | ||
|
||
handleCb() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is handleCb for? |
||
this.handleClick(this.state.currentPage + 1); | ||
} | ||
|
||
render() { | ||
const {currentPage, limit, totalResults, paginationProps} = this.state; | ||
return ( | ||
<div> | ||
<PageHeader>Recent Imports</PageHeader> | ||
<h4> The following data has been imported recently. </h4> | ||
<RecentImportsTable | ||
offset={this.state.offset} | ||
recentImports={this.state.recentImports} | ||
/> | ||
<p> {`Displaying ${limit} of ${totalResults} results`} </p> | ||
<Pagination | ||
boundaryLinks | ||
ellipsis | ||
activePage={currentPage} | ||
className={paginationProps.totalPages === 0 ? | ||
'hidden' : 'shown'} | ||
first={paginationProps.hasBeginningPage} | ||
items={paginationProps.totalPages} | ||
last={paginationProps.hasEndPage} | ||
next={paginationProps.hasNextPage} | ||
prev={paginationProps.hasPreviousPage} | ||
onSelect={this.handleClick} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
RecentImports.displayName = 'RecentImports'; | ||
RecentImports.propTypes = { | ||
currentPage: PropTypes.number, | ||
limit: PropTypes.number | ||
}; | ||
RecentImports.defaultProps = { | ||
currentPage: 1, | ||
limit: 10 | ||
}; | ||
|
||
export default RecentImports; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause the state to be updated, which is bad inside componentDidMount - https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
Why not just send the initial set of results from the server, rather than requesting them here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's an anti-pattern to use setState in componentDidMount. Infact, React official document calls for using ajax calls inside the componentDidMount and then updating the state. See here => https://reactjs.org/docs/faq-ajax.html
Making ajax calls for data to be displayed makes the displaying the content consistent and keeps logic for getting page layout and content separate.