Commit c1e9122b authored by jim's avatar jim

fix #1561 fix getDerivedStateFromProps bug

parent 86b9ac0b
...@@ -5,9 +5,10 @@ ...@@ -5,9 +5,10 @@
"private": true, "private": true,
"scripts": { "scripts": {
"precommit": "npm run lint-staged", "precommit": "npm run lint-staged",
"start": "cross-env ESLINT=none roadhog dev", "start": "HARD_SOURCE=none cross-env ESLINT=none roadhog dev",
"start:no-proxy": "cross-env NO_PROXY=true ESLINT=none roadhog dev", "start:no-proxy": "cross-env NO_PROXY=true ESLINT=none roadhog dev",
"build": "cross-env ESLINT=none roadhog build", "build": "cross-env ESLINT=none roadhog build",
"build-site": "roadhog-api-doc static",
"site": "roadhog-api-doc static && gh-pages -d dist", "site": "roadhog-api-doc static && gh-pages -d dist",
"analyze": "cross-env ANALYZE=true roadhog build", "analyze": "cross-env ANALYZE=true roadhog build",
"lint:style": "stylelint \"src/**/*.less\" --syntax less", "lint:style": "stylelint \"src/**/*.less\" --syntax less",
...@@ -40,10 +41,10 @@ ...@@ -40,10 +41,10 @@
"prop-types": "^15.5.10", "prop-types": "^15.5.10",
"qs": "^6.5.0", "qs": "^6.5.0",
"rc-drawer-menu": "^1.1.0", "rc-drawer-menu": "^1.1.0",
"react": "^16.3.1", "react": "^16.4.0",
"react-container-query": "^0.11.0", "react-container-query": "^0.11.0",
"react-document-title": "^2.0.3", "react-document-title": "^2.0.3",
"react-dom": "^16.3.1", "react-dom": "^16.4.0",
"react-fittext": "^1.0.0", "react-fittext": "^1.0.0",
"rollbar": "^2.3.4", "rollbar": "^2.3.4",
"url-polyfill": "^1.0.10" "url-polyfill": "^1.0.10"
......
...@@ -21,15 +21,20 @@ class LoginTab extends Component { ...@@ -21,15 +21,20 @@ class LoginTab extends Component {
this.props.tabUtil.addTab(this.uniqueId); this.props.tabUtil.addTab(this.uniqueId);
} }
render() { render() {
return <TabPane {...this.props} />; return <TabPane {...this.props}>{this.props.children}</TabPane>;
} }
} }
const warpContext = props => { const warpContext = props => {
return ( return (
<LoginContext.Consumer> <LoginContext.Consumer>
{value => <LoginTab tabUtil={value.tabUtil} {...props} />} {value => {
return <LoginTab tabUtil={value.tabUtil} {...props} />;
}}
</LoginContext.Consumer> </LoginContext.Consumer>
); );
}; };
// 标志位 用来判断是不是自定义组件
warpContext.typeName = 'LoginTab';
export default warpContext; export default warpContext;
...@@ -78,7 +78,7 @@ class Login extends Component { ...@@ -78,7 +78,7 @@ class Login extends Component {
return; return;
} }
// eslint-disable-next-line // eslint-disable-next-line
if (item.type.name === 'warpContext') { if (item.type.typeName === 'LoginTab') {
TabChildren.push(item); TabChildren.push(item);
} else { } else {
otherChildren.push(item); otherChildren.push(item);
......
...@@ -233,7 +233,7 @@ export default class SiderMenu extends PureComponent { ...@@ -233,7 +233,7 @@ export default class SiderMenu extends PureComponent {
width={256} width={256}
className={`${styles.sider} ${theme === 'light' ? styles.light : ''}`} className={`${styles.sider} ${theme === 'light' ? styles.light : ''}`}
> >
<div className={styles.logo} key="logo"> <div className={styles.logo} key="logo" id="logo">
<Link to="/"> <Link to="/">
<img src={logo} alt="logo" /> <img src={logo} alt="logo" />
<h1>Ant Design Pro</h1> <h1>Ant Design Pro</h1>
......
...@@ -10,7 +10,7 @@ export default class TopNavHeader extends PureComponent { ...@@ -10,7 +10,7 @@ export default class TopNavHeader extends PureComponent {
<div className={`${styles.head} ${this.props.theme === 'light' ? styles.light : ''}`}> <div className={`${styles.head} ${this.props.theme === 'light' ? styles.light : ''}`}>
<div className={`${styles.main} ${this.props.grid === 'Wide' ? styles.wide : ''}`}> <div className={`${styles.main} ${this.props.grid === 'Wide' ? styles.wide : ''}`}>
<div className={styles.left}> <div className={styles.left}>
<div className={styles.logo} key="logo"> <div className={styles.logo} key="logo" id="logo">
<Link to="/"> <Link to="/">
<img src={this.props.logo} alt="logo" /> <img src={this.props.logo} alt="logo" />
<h1>Ant Design Pro</h1> <h1>Ant Design Pro</h1>
......
...@@ -5,7 +5,7 @@ describe('Homepage', () => { ...@@ -5,7 +5,7 @@ describe('Homepage', () => {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] }); const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
const page = await browser.newPage(); const page = await browser.newPage();
await page.goto('http://localhost:8000', { waitUntil: 'networkidle2' }); await page.goto('http://localhost:8000', { waitUntil: 'networkidle2' });
await page.waitForSelector('h1'); await page.waitForSelector('#logo h1');
const text = await page.evaluate(() => document.body.innerHTML); const text = await page.evaluate(() => document.body.innerHTML);
expect(text).toContain('<h1>Ant Design Pro</h1>'); expect(text).toContain('<h1>Ant Design Pro</h1>');
await page.close(); await page.close();
......
...@@ -17,6 +17,7 @@ export default class TableForm extends PureComponent { ...@@ -17,6 +17,7 @@ export default class TableForm extends PureComponent {
this.state = { this.state = {
data: props.value, data: props.value,
loading: false, loading: false,
editData: [],
}; };
} }
...@@ -39,22 +40,46 @@ export default class TableForm extends PureComponent { ...@@ -39,22 +40,46 @@ export default class TableForm extends PureComponent {
} }
}; };
remove(key) { remove(key) {
const { editData } = this.state;
const editItem = editData.find(item => item.key === key);
if (editItem && editItem.key) {
// 如果存在缓存
if (this.cacheOriginData[key]) {
const data = [...this.state.data];
data.push(this.cacheOriginData[key]);
this.setState(
{
data,
},
() => {
delete this.cacheOriginData[key];
}
);
}
// 从 editData 中删除
this.setState({
editData: editData.filter(item => item.key !== key),
});
return;
}
const newData = this.state.data.filter(item => item.key !== key); const newData = this.state.data.filter(item => item.key !== key);
this.setState({ data: newData }); this.setState({ data: newData });
this.props.onChange(newData); this.props.onChange(newData);
} }
newMember = () => { newMember = () => {
const newData = this.state.data.map(item => ({ ...item })); this.index += 1;
newData.push({ this.setState({
editData: [
{
key: `NEW_TEMP_ID_${this.index}`, key: `NEW_TEMP_ID_${this.index}`,
workId: '', workId: '',
name: '', name: '',
department: '', department: '',
editable: true, editable: true,
isNew: true, isNew: true,
},
],
}); });
this.index += 1;
this.setState({ data: newData });
}; };
handleKeyPress(e, key) { handleKeyPress(e, key) {
if (e.key === 'Enter') { if (e.key === 'Enter') {
...@@ -208,13 +233,13 @@ export default class TableForm extends PureComponent { ...@@ -208,13 +233,13 @@ export default class TableForm extends PureComponent {
}, },
}, },
]; ];
const dataSource = this.state.data.concat(this.state.editData);
return ( return (
<Fragment> <Fragment>
<Table <Table
loading={this.state.loading} loading={this.state.loading}
columns={columns} columns={columns}
dataSource={this.state.data} dataSource={dataSource}
pagination={false} pagination={false}
rowClassName={record => { rowClassName={record => {
return record.editable ? styles.editable : ''; return record.editable ? styles.editable : '';
......
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