| Total Complexity | 0 |
| Complexity/F | 0 |
| Lines of Code | 40 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 91.67% |
| Changes | 0 | ||
| 1 | import React, { useEffect, useState } from 'react'; |
||
| 2 | import PropTypes from 'prop-types'; |
||
| 3 | import Paginator from './Paginator'; |
||
| 4 | |||
| 5 | 1 | const ShortUrls = (SearchBar, ShortUrlsList) => { |
|
| 6 | 1 | const propTypes = { |
|
| 7 | match: PropTypes.shape({ |
||
| 8 | params: PropTypes.object, |
||
| 9 | }), |
||
| 10 | shortUrlsList: PropTypes.object, |
||
| 11 | }; |
||
| 12 | |||
| 13 | 1 | const ShortUrlsComponent = (props) => { |
|
| 14 | 1 | const { match: { params }, shortUrlsList } = props; |
|
| 15 | 1 | const { page, serverId } = params; |
|
| 16 | 1 | const { data = [], pagination } = shortUrlsList; |
|
| 17 | 1 | const [ urlsListKey, setUrlsListKey ] = useState(`${serverId}_${page}`); |
|
| 18 | |||
| 19 | // Using a key on a component makes react to create a new instance every time the key changes |
||
| 20 | // Without it, pagination on the URL will not make the component to be refreshed |
||
| 21 | 1 | useEffect(() => { |
|
| 22 | setUrlsListKey(`${serverId}_${page}`); |
||
| 23 | }, [ serverId, page ]); |
||
| 24 | |||
| 25 | 1 | return ( |
|
| 26 | <React.Fragment> |
||
| 27 | <div className="form-group"><SearchBar /></div> |
||
| 28 | <ShortUrlsList {...props} shortUrlsList={data} key={urlsListKey} /> |
||
| 29 | <Paginator paginator={pagination} serverId={serverId} /> |
||
| 30 | </React.Fragment> |
||
| 31 | ); |
||
| 32 | }; |
||
| 33 | |||
| 34 | 1 | ShortUrlsComponent.propTypes = propTypes; |
|
| 35 | |||
| 36 | 1 | return ShortUrlsComponent; |
|
| 37 | }; |
||
| 38 | |||
| 39 | export default ShortUrls; |
||
| 40 |