-
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.
BASIRA #292 - Adding "/places" and "/people" list pages
- Loading branch information
1 parent
0582e34
commit ed0cb87
Showing
10 changed files
with
333 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @flow | ||
|
||
import { ListTable } from '@performant-software/semantic-components'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
import { Container } from 'semantic-ui-react'; | ||
import NavBar from './NavBar'; | ||
|
||
type Props = { | ||
className?: string, | ||
collectionName: string, | ||
columns: Array<any>, | ||
onLoad: (params: any) => Promise<any> | ||
}; | ||
|
||
const ListPage = (props: Props) => { | ||
const location = useLocation(); | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Container | ||
className='list-page' | ||
fluid | ||
> | ||
<NavBar /> | ||
<Container> | ||
<ListTable | ||
actions={[{ | ||
as: Link, | ||
asProps: (item) => ({ | ||
to: `${location.pathname}/${item.id}` | ||
}), | ||
name: 'navigate', | ||
icon: 'arrow alternate circle right outline', | ||
popup: { | ||
content: t('ListPage.actions.navigate.content'), | ||
title: t('ListPage.actions.navigate.title') | ||
} | ||
}]} | ||
className={props.className} | ||
collectionName={props.collectionName} | ||
columns={props.columns} | ||
onLoad={props.onLoad} | ||
searchable | ||
/> | ||
</Container> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ListPage; |
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,52 @@ | ||
// @flow | ||
|
||
import { useCallback, useMemo } from 'react'; | ||
import _ from 'underscore'; | ||
import Qualifiables from '../utils/Qualifiables'; | ||
|
||
const useQualifiable = (attributes) => { | ||
/** | ||
* Adds the `resolve` attribute for any column with `object` and `group` attributes. | ||
* | ||
* @type {[]} | ||
*/ | ||
const columns = useMemo(() => { | ||
const value = []; | ||
|
||
_.each(attributes, (c) => { | ||
const column = { ...c }; | ||
|
||
if (column.object && column.group) { | ||
const resolve = (item) => Qualifiables.getValueListValue(item, column.object, column.group); | ||
_.extend(column, { resolve }) | ||
} | ||
|
||
value.push(column); | ||
}); | ||
|
||
return value; | ||
}, [attributes]); | ||
|
||
/** | ||
* Adds the `sort_by_object` and `sort_by_group` parameters if the current sort column | ||
* contains `object` and `group` attributes. | ||
* | ||
* @type {function(*): *} | ||
*/ | ||
const getParameters = useCallback((params) => { | ||
const sortColumn = _.findWhere(columns, { name: params.sort_by }); | ||
|
||
if (sortColumn && sortColumn.object && sortColumn.group) { | ||
_.extend(params, { sort_by_object: sortColumn.object, sort_by_group: sortColumn.group }); | ||
} | ||
|
||
return params; | ||
}, [columns]); | ||
|
||
return { | ||
columns, | ||
getParameters | ||
}; | ||
}; | ||
|
||
export default useQualifiable; |
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,38 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import ListPage from '../components/ListPage'; | ||
import PeopleService from '../services/People'; | ||
import useQualifiable from '../hooks/Qualifiable'; | ||
|
||
const People = () => { | ||
const { t } = useTranslation(); | ||
|
||
const { columns, getParameters } = useQualifiable([{ | ||
name: 'display_name', | ||
label: t('People.columns.name'), | ||
sortable: true | ||
}, { | ||
name: 'person_type', | ||
label: t('People.columns.type'), | ||
sortable: true | ||
}, { | ||
name: 'nationality', | ||
label: t('People.columns.nationality'), | ||
object: 'Person', | ||
group: 'Nationality', | ||
sortable: true | ||
}]); | ||
|
||
return ( | ||
<ListPage | ||
className='people' | ||
collectionName='people' | ||
columns={columns} | ||
onLoad={(params) => PeopleService.fetchAll(getParameters(params))} | ||
/> | ||
); | ||
}; | ||
|
||
export default People; |
Oops, something went wrong.