Skip to content

Commit

Permalink
feat: ✨ add chooseFirst prop in select table (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsoj authored Sep 1, 2024
1 parent d5015a1 commit 4430e5a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
host: 0.0.0.0
port: 8088
server: http://clab.pku.edu.cn
server: https://clab.pku.edu.cn

theme: default

Expand Down
20 changes: 20 additions & 0 deletions src/components/FormItem/SelectTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default class SelectTable extends React.Component {
imageTabAuto: PropTypes.bool,
refreshFunc: PropTypes.func,
hideRefresh: PropTypes.bool,
chooseFirst: PropTypes.bool,
};

static defaultProps = {
Expand Down Expand Up @@ -131,6 +132,7 @@ export default class SelectTable extends React.Component {
imageTabAuto: false,
refreshFunc: null,
hideRefresh: false,
chooseFirst: false,
};

constructor(props) {
Expand All @@ -154,6 +156,8 @@ export default class SelectTable extends React.Component {

componentDidMount() {
this.getData();
const { chooseFirst } = this.props;
if (chooseFirst) this.setFirst();
}

componentDidUpdate(prevProps, prevState) {
Expand All @@ -167,6 +171,22 @@ export default class SelectTable extends React.Component {
}
}

setFirst = async () => {
// make eslint happy
const { pageSize } = this.state;
const { extraParams } = this.props;
const params = {
limit: pageSize,
page: 1,
...extraParams,
};
const data = await this.fetchDataByPage(params);
this.setState({
selectedRowKeys: [data[0].id],
selectedRows: [data[0]],
});
};

getData() {
const { backendPageStore, pageSize } = this.props;
if (backendPageStore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export class NetworkStep extends Base {
),
backendPageStore: this.securityGroupStore,
extraParams: { project_id: this.currentProjectId },
chooseFirst: true,
hidden: !this.showSecurityGroups,
required: this.showSecurityGroups,
isMulti: true,
Expand Down

0 comments on commit 4430e5a

Please sign in to comment.