🧲 New features Custom user role permissions Employee edit form updated Employee daily task list Attendance and employee distribution charts on dashboard Improvements to company structure and company assets module Improved tables for displaying data in several modules Faster data loading (specially for employee module) Initials based profile pictures Re-designed login page Re-designed user profile page Improvements to filtering New REST endpoints for employee qualifications 🐛 Bug fixes Fixed, issue with managers being able to create performance reviews for employees who are not their direct reports Fixed, issues related to using full profile image instead of using smaller version of profile image Changing third gender to other Improvements and fixes for internal frontend data caching
251 lines
6.9 KiB
JavaScript
251 lines
6.9 KiB
JavaScript
import React, {Component} from 'react';
|
|
import {Col, Form, Input, Row, Table, Space, Button, Tag, message} from 'antd';
|
|
import {
|
|
FilterOutlined,
|
|
PlusCircleOutlined,
|
|
} from '@ant-design/icons';
|
|
const { Search } = Input;
|
|
|
|
class IceTable extends React.Component {
|
|
state = {
|
|
data: [],
|
|
pagination: {},
|
|
loading: true,
|
|
fetchConfig: false,
|
|
//filter: null,
|
|
showLoading: true,
|
|
currentElement: null,
|
|
fetchCompleted: false,
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
}
|
|
|
|
componentDidMount() {
|
|
const fetchConfig = {
|
|
page: 1,
|
|
};
|
|
message.config({
|
|
top: 40,
|
|
});
|
|
this.setState({
|
|
fetchConfig,
|
|
//filter: this.props.adapter.filter,
|
|
pagination: { 'pageSize': this.props.reader.pageSize }
|
|
});
|
|
//this.fetch(fetchConfig);
|
|
}
|
|
|
|
handleTableChange = (pagination, filters, sorter) => {
|
|
const pager = { ...this.state.pagination };
|
|
const { search } = this.state;
|
|
pager.current = pagination.current;
|
|
this.setState({
|
|
pagination: pager,
|
|
});
|
|
|
|
const fetchConfig = {
|
|
limit: pagination.pageSize,
|
|
page: pagination.current,
|
|
sortField: sorter.field,
|
|
sortOrder: sorter.order,
|
|
filters: JSON.stringify(filters),
|
|
search: search,
|
|
};
|
|
|
|
this.setState({
|
|
fetchConfig
|
|
});
|
|
|
|
this.fetch(fetchConfig);
|
|
};
|
|
|
|
reload = () => {
|
|
const fetchConfig = this.state.fetchConfig;
|
|
if (fetchConfig) {
|
|
this.fetch(fetchConfig)
|
|
}
|
|
};
|
|
|
|
search = (value) => {
|
|
console.log('search table:' + value);
|
|
this.setState({ search: value });
|
|
const fetchConfig = this.state.fetchConfig;
|
|
console.log(fetchConfig);
|
|
if (fetchConfig) {
|
|
fetchConfig.search = value;
|
|
this.setState({
|
|
fetchConfig
|
|
});
|
|
this.fetch(fetchConfig)
|
|
}
|
|
}
|
|
|
|
addNew = () => {
|
|
this.props.adapter.renderForm();
|
|
}
|
|
|
|
showFilters = () => {
|
|
this.props.adapter.showFilters();
|
|
}
|
|
|
|
setFilterData = (filter) => {
|
|
this.setState({
|
|
filter,
|
|
});
|
|
}
|
|
|
|
setCurrentElement = (currentElement) => {
|
|
this.setState({currentElement});
|
|
}
|
|
|
|
setLoading(value) {
|
|
this.setState({ loading: value });
|
|
}
|
|
|
|
fetch = (params = {}) => {
|
|
console.log('params:', params);
|
|
//this.setState({ loading: this.state.showLoading });
|
|
this.setState({ loading: true });
|
|
//const hideMessage = message.loading({ content: 'Loading Latest Data ...', key: 'loadingTable', duration: 1});
|
|
const pagination = { ...this.state.pagination };
|
|
console.log('pagination:', pagination);
|
|
|
|
if (this.props.adapter.localStorageEnabled) {
|
|
try {
|
|
const cachedResponse = this.props.reader.getCachedResponse(params);
|
|
if (cachedResponse.items) {
|
|
this.setState({
|
|
loading: false,
|
|
data: cachedResponse.items,
|
|
pagination,
|
|
showLoading: false,
|
|
});
|
|
} else {
|
|
this.props.reader.clearCachedResponse(params);
|
|
}
|
|
} catch (e) {
|
|
this.props.reader.clearCachedResponse(params);
|
|
}
|
|
}
|
|
|
|
this.props.reader.get(params)
|
|
.then(data => {
|
|
// Read total count from server
|
|
// pagination.total = data.totalCount;
|
|
pagination.total = data.total;
|
|
//hideMessage();
|
|
// setTimeout(
|
|
// () => message.success({ content: 'Loading Completed!', key: 'loadingSuccess', duration: 1 }),
|
|
// 600
|
|
// );
|
|
this.setState({
|
|
loading: false,
|
|
data: data.items,
|
|
pagination,
|
|
showLoading: false,
|
|
fetchCompleted: true,
|
|
});
|
|
});
|
|
};
|
|
|
|
getChildrenWithProps(element) {
|
|
const childrenWithProps = React.Children.map(this.props.children, child => {
|
|
// checking isValidElement is the safe way and avoids a typescript error too
|
|
const props = {
|
|
element,
|
|
adapter: this.props.adapter,
|
|
loading: this.state.loading,
|
|
};
|
|
if (React.isValidElement(child)) {
|
|
return React.cloneElement(child, props);
|
|
}
|
|
return child;
|
|
});
|
|
|
|
return childrenWithProps;
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<Row direction="vertical" style={{ width: '100%' }}>
|
|
{!this.state.currentElement &&
|
|
<Col span={24}>
|
|
<Row gutter={24}>
|
|
<Col span={18}>
|
|
<Space>
|
|
{this.props.adapter.hasAccess('save') && this.props.adapter.getShowAddNew() &&
|
|
<Button type="primary" onClick={this.addNew}><PlusCircleOutlined/> Add New</Button>
|
|
}
|
|
{this.props.adapter.getFilters() &&
|
|
<Button onClick={this.showFilters}><FilterOutlined/> Filters</Button>
|
|
}
|
|
|
|
{this.state.fetchCompleted
|
|
&& this.props.adapter.getFilters()
|
|
&& this.props.adapter.filter != null
|
|
&& this.props.adapter.filter !== []
|
|
&& this.props.adapter.filter !== ''
|
|
&& this.props.adapter.getFilterString(this.props.adapter.filter) !== '' &&
|
|
<Tag closable
|
|
style={{'lineHeight': '30px'}}
|
|
color="blue"
|
|
onClose={() => this.props.adapter.resetFilters()}
|
|
visible={this.props.adapter.filter != null && this.props.adapter.filter !== [] && this.props.adapter.filter !== ''}
|
|
>
|
|
{this.props.adapter.getFilterString(this.props.adapter.filter)}
|
|
</Tag>
|
|
}
|
|
|
|
</Space>
|
|
</Col>
|
|
<Col span={6}>
|
|
<Form
|
|
ref={(formRef) => this.form = formRef}
|
|
name="advanced_search"
|
|
className="ant-advanced-search-form"
|
|
>
|
|
<Form.Item name="searchTerm" label=""
|
|
rules={[
|
|
{
|
|
required: false,
|
|
},
|
|
]}
|
|
>
|
|
<Search
|
|
placeholder="input search text"
|
|
enterButton="Search"
|
|
onSearch={value => this.search(value)}
|
|
/>
|
|
</Form.Item>
|
|
</Form>
|
|
</Col>
|
|
</Row>
|
|
<Row gutter={24}>
|
|
<Col span={24}>
|
|
<Table
|
|
// bordered
|
|
rowClassName={(record, index) => index % 2 === 0 ? 'table-row-light' : 'table-row-dark'}
|
|
columns={this.props.columns}
|
|
rowKey={record => record.id}
|
|
dataSource={this.state.data}
|
|
pagination={this.state.pagination}
|
|
loading={this.state.loading}
|
|
onChange={this.handleTableChange}
|
|
reader={this.props.dataPipe}
|
|
/>
|
|
</Col>
|
|
</Row>
|
|
</Col>
|
|
}
|
|
{this.state.currentElement &&
|
|
this.getChildrenWithProps(this.state.currentElement)
|
|
}
|
|
</Row>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default IceTable;
|