From fcdf1e8dd2cdb16863b65bc7c98b75dfbf9840cf Mon Sep 17 00:00:00 2001 From: Yaodong Yu <2814461814@qq.com> Date: Thu, 12 Jan 2023 23:11:11 +0800 Subject: [PATCH] feat: improve Select component performance (#1472) --- web/src/ApplicationEditPage.js | 9 +-- web/src/CropperDiv.js | 2 +- web/src/OrganizationEditPage.js | 17 ++-- web/src/PaymentEditPage.js | 2 +- web/src/PermissionEditPage.js | 119 ++++++++++++---------------- web/src/ProviderTable.js | 2 +- web/src/RoleEditPage.js | 37 ++++----- web/src/Setting.js | 8 ++ web/src/SignupTable.js | 6 +- web/src/UserEditPage.js | 42 +++++----- web/src/auth/ForgetPage.js | 4 +- web/src/common/AffiliationSelect.js | 26 +++--- 12 files changed, 115 insertions(+), 159 deletions(-) diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js index c7327773..8dea2b8a 100644 --- a/web/src/ApplicationEditPage.js +++ b/web/src/ApplicationEditPage.js @@ -343,12 +343,9 @@ class ApplicationEditPage extends React.Component { {Setting.getLabel(i18next.t("application:Token format"), i18next.t("application:Token format - Tooltip"))} : - + uploadButton = input} type="file" accept="image/*" onChange={onChange} /> - {this.updateOrganizationField("passwordType", value);})}> - { - ["plain", "salt", "md5-salt", "bcrypt", "pbkdf2-salt", "argon2id"] - .map((item, index) => ) - } - + {this.updateOrganizationField("defaultApplication", value);})}> - { - this.state.applications?.map((item, index) => ) - } - + { + { this.updatePermissionField("owner", owner); - this.getUsers(owner); this.getRoles(owner); this.getModels(owner); this.getResources(owner); - })}> - { - this.state.organizations.map((organization, index) => ) - } - + })} + options={this.state.organizations.map((organization) => Setting.getOption(organization.name, organization.name)) + } /> @@ -202,11 +197,9 @@ class PermissionEditPage extends React.Component { + })} + options={this.state.models.map((model) => Setting.getOption(model.name, model.name)) + } /> @@ -224,11 +217,10 @@ class PermissionEditPage extends React.Component { {Setting.getLabel(i18next.t("role:Sub users"), i18next.t("role:Sub users - Tooltip"))} : - + {this.updatePermissionField("roles", value);})}> - { - this.state.roles.filter(roles => (roles.owner !== this.state.roles.owner || roles.name !== this.state.roles.name)).map((permission, index) => ) - } - + { - this.updatePermissionField("domains", value); - })}> - { - this.state.permission.domains.map((domain, index) => ) - } - + { this.updatePermissionField("resourceType", value); - })}> - { - [ - {id: "Application", name: i18next.t("general:Application")}, - {id: "TreeNode", name: i18next.t("permission:TreeNode")}, - ].map((item, index) => ) - } - + })} + options={[ + {value: "Application", name: i18next.t("general:Application")}, + {value: "TreeNode", name: i18next.t("permission:TreeNode")}, + ].map((item) => Setting.getOption(item.name, item.value))} + /> @@ -279,11 +267,10 @@ class PermissionEditPage extends React.Component { {Setting.getLabel(i18next.t("permission:Resources"), i18next.t("permission:Resources - Tooltip"))} : - + { this.updatePermissionField("actions", value); - })}> - { - [ - {id: "Read", name: i18next.t("permission:Read")}, - {id: "Write", name: i18next.t("permission:Write")}, - {id: "Admin", name: i18next.t("permission:Admin")}, - ].map((item, index) => ) - } - + })} + options={[ + {value: "Read", name: i18next.t("permission:Read")}, + {value: "Write", name: i18next.t("permission:Write")}, + {value: "Admin", name: i18next.t("permission:Admin")}, + ].map((item) => Setting.getOption(item.name, item.value))} + /> @@ -311,14 +296,12 @@ class PermissionEditPage extends React.Component { + })} + options={[ + {value: "Allow", name: i18next.t("permission:Allow")}, + {value: "Deny", name: i18next.t("permission:Deny")}, + ].map((item) => Setting.getOption(item.name, item.value))} + /> @@ -366,7 +349,7 @@ class PermissionEditPage extends React.Component { {Setting.getLabel(i18next.t("permission:State"), i18next.t("permission:State - Tooltip"))} : - { if (this.state.permission.state !== value) { if (value === "Approved") { this.updatePermissionField("approver", this.props.account.name); @@ -378,14 +361,12 @@ class PermissionEditPage extends React.Component { } this.updatePermissionField("state", value); - })}> - { - [ - {id: "Approved", name: i18next.t("permission:Approved")}, - {id: "Pending", name: i18next.t("permission:Pending")}, - ].map((item, index) => ) - } - + })} + options={[ + {value: "Approved", name: i18next.t("permission:Approved")}, + {value: "Pending", name: i18next.t("permission:Pending")}, + ].map((item) => Setting.getOption(item.name, item.value))} + /> diff --git a/web/src/ProviderTable.js b/web/src/ProviderTable.js index e9891e6c..b8430ee9 100644 --- a/web/src/ProviderTable.js +++ b/web/src/ProviderTable.js @@ -179,7 +179,7 @@ class ProviderTable extends React.Component { // width: '120px', // render: (text, record, index) => { // return ( - // { // this.updateField(table, index, 'alertType', value); // })}> // { diff --git a/web/src/RoleEditPage.js b/web/src/RoleEditPage.js index e033d624..74584eb0 100644 --- a/web/src/RoleEditPage.js +++ b/web/src/RoleEditPage.js @@ -16,11 +16,9 @@ import React from "react"; import {Button, Card, Col, Input, Row, Select, Switch} from "antd"; import * as RoleBackend from "./backend/RoleBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend"; -import * as UserBackend from "./backend/UserBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; - -const {Option} = Select; +import * as UserBackend from "./backend/UserBackend"; class RoleEditPage extends React.Component { constructor(props) { @@ -113,11 +111,9 @@ class RoleEditPage extends React.Component { {Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} : - + {this.updateRoleField("users", value);})}> - { - this.state.users.map((user, index) => ) - } - + {this.updateRoleField("roles", value);})}> - { - this.state.roles.filter(role => (role.owner !== this.state.role.owner || role.name !== this.state.role.name)).map((role, index) => ) - } - + { this.updateRoleField("domains", value); - })}> - { - this.state.role.domains?.map((domain, index) => ) - } - + })} + options={this.state.role.domains?.map((domain) => Setting.getOption(domain, domain)) + } /> diff --git a/web/src/Setting.js b/web/src/Setting.js index f6a966ca..b8adb927 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -924,6 +924,14 @@ export function getItem(label, key, icon, children, type) { type, }; } + +export function getOption(label, value) { + return { + label, + value, + }; +} + function repeat(str, len) { while (str.length < len) { str += str.substr(0, len - str.length); diff --git a/web/src/SignupTable.js b/web/src/SignupTable.js index 2a67297e..89990a8e 100644 --- a/web/src/SignupTable.js +++ b/web/src/SignupTable.js @@ -195,11 +195,7 @@ class SignupTable extends React.Component { return ( + })} options={options.map(item => Setting.getOption(item.name, item.id))} /> ); }, }, diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index 68173370..5d5b04f6 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -257,12 +257,9 @@ class UserEditPage extends React.Component { {Setting.getLabel(i18next.t("general:User type"), i18next.t("general:User type - Tooltip"))} : - + { @@ -317,7 +314,7 @@ class UserEditPage extends React.Component { onChange={e => { this.updateUserField("phone", e.target.value); }} /> : - ( {this.updateUserField("tag", value);})}> - { - this.state.application.organizationObj.tags?.map((tag, index) => { - const tokens = tag.split("|"); - const value = tokens[0]; - const displayValue = Setting.getLanguage() !== "zh" ? tokens[0] : tokens[1]; - return ; - }) - } - + { this.updateUserField("tag", e.target.value); @@ -435,11 +430,10 @@ class UserEditPage extends React.Component { {Setting.getLabel(i18next.t("general:Signup application"), i18next.t("general:Signup application - Tooltip"))} : - + : - { - const name = value; - const affiliationOption = Setting.getArrayItem(this.state.affiliationOptions, "name", name); - const id = affiliationOption.id; - this.updateUserField("affiliation", name); - this.updateUserField("score", id); - })}> - { - - } - { - this.state.affiliationOptions.map((affiliationOption, index) => ) - } - +