-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented dashboard for providers and sources
- Loading branch information
Showing
17 changed files
with
391 additions
and
112 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export function array_move(arr, old_index, new_index) { | ||
| if (new_index >= arr.length) { | ||
| let k = new_index - arr.length + 1; | ||
| while (k--) { | ||
| arr.push(undefined); | ||
| } | ||
| } | ||
| arr.splice(new_index, 0, arr.splice(old_index, 1)[0]); | ||
| return arr; | ||
| } | ||
|
|
||
| export default array_move; |
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,17 @@ | ||
| export function get_cookie (cname) { | ||
| var name = cname + "="; | ||
| var decodedCookie = decodeURIComponent(document.cookie); | ||
| var ca = decodedCookie.split(';'); | ||
| for (var i = 0; i < ca.length; i++) { | ||
| var c = ca[i]; | ||
| while (c.charAt(0) == ' ') { | ||
| c = c.substring(1); | ||
| } | ||
| if (c.indexOf(name) == 0) { | ||
| return c.substring(name.length, c.length); | ||
| } | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| export default get_cookie; |
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,87 @@ | ||
| import React from 'react'; | ||
| import useFetch from 'use-http'; | ||
| import first from 'lodash/first'; | ||
| import last from 'lodash/last'; | ||
| import API_BASE_PATH from '../../App.constant'; | ||
| import { array_move } from '../../core/utility/array_move'; | ||
| import { pick } from 'lodash'; | ||
|
|
||
| const orderPaths = { | ||
| provider: `/MetadataResolversPositionOrder` | ||
| }; | ||
|
|
||
| export const getId = (entity) => { | ||
| return entity.resourceId ? entity.resourceId : entity.id; | ||
| }; | ||
|
|
||
| export const mergeOrderFn = (entities, order) => { | ||
| const ordered = [...entities.sort( | ||
| (a, b) => { | ||
| const aIndex = order.indexOf(getId(a)); | ||
| const bIndex = order.indexOf(getId(b)); | ||
| return aIndex > bIndex ? 1 : bIndex > aIndex ? -1 : 0; | ||
| } | ||
| )]; | ||
| return ordered; | ||
| }; | ||
|
|
||
| export function Ordered ({type = 'provider', entities, children}) { | ||
|
|
||
| const orderEntities = (orderById, list) => { | ||
| setOrdered(mergeOrderFn(list, orderById)); | ||
| }; | ||
|
|
||
| const { get, post, response } = useFetch(`${API_BASE_PATH}`, { | ||
| cachePolicy: 'no-cache' | ||
| }); | ||
|
|
||
| const [order, setOrder] = React.useState([]); | ||
| const [ordered, setOrdered] = React.useState([]); | ||
|
|
||
| const [firstId, setFirstId] = React.useState(null); | ||
| const [lastId, setLastId] = React.useState(null); | ||
|
|
||
| async function changeOrder(resourceIds) { | ||
| const update = await post(`${orderPaths[type]}`, { | ||
| resourceIds | ||
| }); | ||
| if (response.ok) { | ||
| loadOrder(); | ||
| } | ||
| } | ||
|
|
||
| const onOrderUp = (id) => { | ||
| const index = order.indexOf(id); | ||
| const newOrder = array_move(order, index, index - 1); | ||
| changeOrder(newOrder); | ||
| }; | ||
|
|
||
| const onOrderDown = (id) => { | ||
| const index = order.indexOf(id); | ||
| const newOrder = array_move(order, index, index + 1); | ||
| changeOrder(newOrder); | ||
| }; | ||
|
|
||
| async function loadOrder () { | ||
| const o = await get(`${orderPaths[type]}`); | ||
| console.log(o) | ||
| if (response.ok) { | ||
| const ids = o.resourceIds; | ||
| setOrder(ids); | ||
| setFirstId(first(ids)); | ||
| setLastId(last(ids)); | ||
| } | ||
| } | ||
|
|
||
| React.useEffect(() => loadOrder(),[]); | ||
|
|
||
| React.useEffect(() => orderEntities(order, entities), [order, entities]); | ||
|
|
||
| React.useEffect(() => console.log(ordered.map(e => pick(e, ['resourceId']))), [ordered]); | ||
|
|
||
| return ( | ||
| <> | ||
| {children(ordered, firstId, lastId, onOrderUp, onOrderDown)} | ||
| </> | ||
| ); | ||
| } |
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,33 @@ | ||
| import React from 'react'; | ||
|
|
||
| import InfiniteScroll from 'react-infinite-scroll-component'; | ||
|
|
||
| const PAGE_LIMIT = 20; | ||
|
|
||
| export function Scroller ({ entities, children }) { | ||
|
|
||
| const [page, setPage] = React.useState(1); | ||
|
|
||
| const [limited, setLimited] = React.useState([]); | ||
|
|
||
| React.useEffect(() => { | ||
| let maxIndex = (page * PAGE_LIMIT) - 1, | ||
| minIndex = 0; | ||
| const l = entities.filter((resolver, index) => (maxIndex >= index && index >= minIndex)); | ||
| setLimited(l); | ||
| }, [entities, page]) | ||
|
|
||
| const loadNext = () => { | ||
| setPage(page + 1); | ||
| } | ||
|
|
||
| return ( | ||
| <InfiniteScroll | ||
| dataLength={limited.length} //This is important field to render the next data | ||
| next={() => loadNext()} | ||
| hasMore={entities.length > limited.length} | ||
| > | ||
| { children(limited) } | ||
| </InfiniteScroll> | ||
| ); | ||
| } |
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,47 @@ | ||
| import React from 'react'; | ||
| import pick from 'lodash/pick'; | ||
|
|
||
| import { Form, Label, Input, Button, InputGroup, InputGroupAddon, FormGroup} from 'reactstrap'; | ||
| import { includes, some, values } from 'lodash'; | ||
|
|
||
| export function Search ({ entities, searchable, children }) { | ||
|
|
||
| const [searched, setSearched] = React.useState([]); | ||
| const [query, setQuery] = React.useState(''); | ||
|
|
||
| React.useEffect(() => setSearched(entities), [entities]); | ||
|
|
||
| const search = (query) => { | ||
| setQuery(query); | ||
| }; | ||
|
|
||
| React.useEffect(() => { | ||
| if (!query) { | ||
| setSearched(entities); | ||
| } else { | ||
| setSearched(entities.filter((e) => { | ||
| const picked = values(pick(e, searchable)); | ||
| return some(picked, (v) => includes(v.toLowerCase(), query.toLowerCase())); | ||
| })); | ||
| } | ||
| }, [query, entities, searchable]); | ||
|
|
||
| return ( | ||
| <> | ||
| <Form className="w-50"> | ||
| <FormGroup> | ||
| <Label for="search" className="sr-only">Search</Label> | ||
| <InputGroup> | ||
| <Input type="email" name="email" id="search" | ||
| placeholder="Search Files" onChange={ (event) => search(event.target.value) } | ||
| value={query} /> | ||
| <InputGroupAddon addonType="append"> | ||
| <Button color="text" className="px-3" onClick={ () => search('') }>Clear</Button> | ||
| </InputGroupAddon> | ||
| </InputGroup> | ||
| </FormGroup> | ||
| </Form> | ||
| { children(searched) } | ||
| </> | ||
| ); | ||
| } |
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
Oops, something went wrong.