Commit 81e45c94 authored by Oleksii Savran's avatar Oleksii Savran Committed by Matija Obreza

Admin: List of CodeValues

parent 7784e679
......@@ -76,6 +76,10 @@
"id": "Crop ID",
"name": "Crop"
},
"CodeValueFullInfo": {
"code": "Code",
"group": "Group"
},
"Geography": {
"geography": "Geography",
"currentGeography": "Current Valid Geography",
......
......@@ -65,6 +65,10 @@
"id": "Crop ID",
"name": "Crop"
},
"CodeValueFullInfo": {
"code": "Code",
"group": "Group"
},
"Geography": {
"geography": "Geography",
"currentGeography": "Current Valid Geography",
......
......@@ -161,6 +161,16 @@
}
}
},
"codevalue": {
"admin": {
"p": {
"browse": {
"title": "Code value list",
"item": "CodeValue"
}
}
}
},
"cooperator": {
"public": {
"p": {
......
import Loadable from '@gringlobal/client/utilities/CustomReactLoadable';
// model
import IRoute from '@gringlobal/client/model/common/IRoute';
import { UserRole } from '@gringlobal/client/model/gringlobal/SysUser';
const adminRoutes: IRoute[] = [
{
auth: [ UserRole.ADMINISTRATOR ],
exact: true,
component: Loadable({
loader: () => import(/* webpackMode:"lazy", webpackChunkName: "site" */ 'codevalue/ui/admin/CodeValueBrowsePage'),
}),
path: '/codes',
},
];
export { adminRoutes as codeValueAdminRotes };
{
"admin": {
"p": {
"browse": {
"title": "Code value list",
"item": "CodeValue"
}
}
}
}
import * as React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import { WithTranslation, withTranslation } from 'react-i18next';
// Model
import { ApiCall } from '@gringlobal/client/model/common';
import CodeValueInfo from '@gringlobal/client/model/gringlobal/CodeValueInfo';
// Utils
import memoize from 'memoize-one';
import forOwn from 'lodash/forOwn';
// UI
import ContentHeader from '@gringlobal/client/ui/common/heading/ContentHeader';
import Table from '@gringlobal/client/ui/common/table/Table';
import AddNewButton from '@gringlobal/client/ui/common/button/AddNewButton';
import { BasicTableConfiguration as TableConfiguration } from '@gringlobal/client/ui/common/table/TableConfiguration';
import Button from '@material-ui/core/Button/Button';
import PageTitle from '@gringlobal/client/ui/common/PageTitle';
class CodeValueFullInfo extends CodeValueInfo {
public group: string;
public code: string;
}
interface IBrowsePageProps extends React.ClassAttributes<any>, WithTranslation {
codeValues: ApiCall<Record<string, Record<string, CodeValueInfo>>>;
}
export const SiteTableDefaultConfig = {
defaultColumns: ['group', 'code', 'title', 'description'],
};
const SiteTableConfig = new TableConfiguration(SiteTableDefaultConfig);
class BrowsePage extends React.Component<IBrowsePageProps, { selected: CodeValueFullInfo[] }> {
public constructor(props) {
super(props);
}
private getCodeValuesList = memoize((codeValues: Record<string, Record<string, CodeValueInfo>>): CodeValueFullInfo[] => {
const fullInfoList = [];
forOwn(codeValues, (num, group) => {
forOwn(codeValues[group], (num, code) => {
fullInfoList.push({ ...codeValues[group][code], code, group });
});
});
return fullInfoList;
});
public state = {
selected: [],
};
private remove = () => {
console.log('Will be removed: ', this.state.selected);
};
private rowToggled = (toggledRow: number, selectedRows: number[], rowData: CodeValueFullInfo) => {
console.log(`Row ${toggledRow} was toggled. Have ${selectedRows}`);
console.log('Row data: ', rowData);
};
private columnToggled = (toggledColumn: string, selectedColumns: string[]) => {
console.log(`Column ${toggledColumn} was toggled. Have ${selectedColumns}`);
};
public render() {
const { codeValues, t } = this.props;
const data = codeValues && codeValues.data ? this.getCodeValuesList(codeValues.data) : [];
return (
<>
<PageTitle title={ t('codevalue.admin.p.browse.title') }/>
<ContentHeader title={ t('codevalue.admin.p.browse.title') }>
{ this.state.selected.length > 0 &&
<Button onClick={ this.remove } variant="contained" disabled={ this.state.selected.length < 1 }>
{ t('common:action.remove') }
</Button>
}
</ContentHeader>
<Table
tableKey="code-value-list"
type={ 'CodeValueFullInfo' }
columns={ SiteTableConfig.defaultColumns }
data={ data }
tableConfig={ SiteTableConfig }
total={ data.length }
onRowToggled={ this.rowToggled }
onColumnToggled={ this.columnToggled }
/>
<AddNewButton
title='codevalue.admin.p.browse.item'
path="code/edit/" // todo
/>
</>
);
}
}
const mapStateToProps = (state) => ({
codeValues: state.codeValue.codeValuesCall,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({}, dispatch);
export default compose(
connect(mapStateToProps, mapDispatchToProps),
withTranslation(),
)(BrowsePage);
......@@ -55,6 +55,12 @@ function AdminMenu(): JSX.Element {
</ListItem>
</Link>
<Divider />
<Link to="/admin/codes">
<ListItem button>
<ListItemText primary={ t('codevalue.admin.p.browse.title') } />
</ListItem>
</Link>
<Divider />
</List>
);
}
......
......@@ -14,6 +14,7 @@ import { kpiAdminRoutes } from 'kpi/routes';
import { inventoryGroupPublicRoutes } from 'inventorygroup/routes';
import { repositoryAdminRoutes } from 'repository/routes';
import { cropAdminRoutes, cropPublicRoutes } from 'crop/routes';
import { codeValueAdminRotes } from 'codevalue/routes';
// User
import { userAdminRoutes, userPublicRoutes } from 'user/routes';
......@@ -70,6 +71,7 @@ export const routes: IRoute[] = [
...kpiAdminRoutes,
...repositoryAdminRoutes,
...cropAdminRoutes,
...codeValueAdminRotes,
],
},
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment