diff --git a/src/UI/Components/Board/ConfigList.tsx b/src/UI/Components/Board/ConfigList.tsx index d586d6940..34234813d 100644 --- a/src/UI/Components/Board/ConfigList.tsx +++ b/src/UI/Components/Board/ConfigList.tsx @@ -4,11 +4,13 @@ import { observer } from "mobx-react"; import React from "react"; import { DndProvider } from "react-dnd"; import { HTML5Backend } from "react-dnd-html5-backend"; +import { CompareIsEqual } from "../../../Add-on/BoardFindModify"; import { CustomNumContainer, CustomNumberItem } from "../../../Add-on/CustomNumber/CustomNumContainer"; import { CustomNumberStore } from "../../../Add-on/CustomNumber/CustomNumberPanel"; import { templateTagCommand } from "../../../Add-on/Template/TemplateTagCommand"; import { KeyBoard } from "../../../Common/KeyEnum"; import { commandReg } from "../../../Common/Utils"; +import { ECompareType } from "../../Store/BoardFindInterface"; import { IConfigStore } from "../../Store/BoardStore"; import { configListMapStore } from "../../Store/ConfigListMapStore"; import { userConfigStore } from "../../Store/UserConfigStore"; @@ -33,8 +35,8 @@ interface IConfigListProps configType: Config_ModalType; isNotModify?: boolean; updateBoardOption: (k: string) => void; - handleSaveConfig: () => void; - handleDeleteConfig: () => void; + handleSaveConfig: () => Promise; + handleDeleteConfig: () => Promise; } @observer export class ConfigList extends React.Component @@ -43,7 +45,7 @@ export class ConfigList extends React.Component @observable private isShow = false; @observable private isCNInput: boolean = false; isResetName = observable.box(false); - + @observable private searchName = ""; isShowCoustomNumList = observable.box(false); private tagRef = React.createRef(); disposeAutorun: Function; @@ -58,6 +60,7 @@ export class ConfigList extends React.Component componentWillUnmount() { + this.searchName = ""; if (this.disposeAutorun) this.disposeAutorun(); this.disposeAutorun = undefined; @@ -173,7 +176,6 @@ export class ConfigList extends React.Component shouldDismissPopover={!this.isResetName.get()} text={ intent={Intent.DANGER} disabled={this.isResetName.get()} style={{ marginLeft: 3 }} - onClick={async () => { this.props.handleDeleteConfig(); }} + onClick={async () => { await this.props.handleDeleteConfig(); }} /> ); @@ -245,10 +247,21 @@ export class ConfigList extends React.Component ConfigListTag = (errorMsg: string) => { const { store, type } = this.props; + const configsNames = store.configsNames.filter(name => CompareIsEqual(name, this.searchName, ECompareType.Include)); return (

{`${this.isShowCoustomNumList.get() ? "列表排序" : "配置列表"}`}

+ + { + this.searchName = e.currentTarget.value.trim(); + }} + /> selectedTabId={store.configName} > { - store.configsNames.map((key, i) => + configsNames.map((key, i) => ; isTip?: boolean; } -export const TabContainer: FC = observer(({ index, keyName, type, isResetName, store, isTip }) => +export const TabContainer: FC = observer(({ keyName, type, isResetName, store, isTip }) => { const curIsResetName = useRef(false); let [curInputName, setCurInputName] = useState(""); @@ -73,7 +72,7 @@ export const TabContainer: FC = observer(({ index, keyName, type, { if (curInputName.length && curInputName != keyName) { - await userConfigStore.ResetNameConfig(type, store, keyName, curInputName, index); + await userConfigStore.ResetNameConfig(type, store, keyName, curInputName); } handleClose(); }} diff --git a/src/UI/Store/UserConfigStore.tsx b/src/UI/Store/UserConfigStore.tsx index d451ae51f..3cd3d1f28 100644 --- a/src/UI/Store/UserConfigStore.tsx +++ b/src/UI/Store/UserConfigStore.tsx @@ -516,7 +516,7 @@ export class UserConfigStore extends Singleton /** * 重命名配置,重命名前需要保证名称正确可用 */ - async ResetNameConfig(type: BoardModalType, store: IConfigStore, oldName: string, newName: string, index: number) + async ResetNameConfig(type: BoardModalType, store: IConfigStore, oldName: string, newName: string) { const configList = await configListMapStore.GetConfig(type); if (configList.includes(newName)) @@ -565,7 +565,8 @@ export class UserConfigStore extends Singleton await this.UploadUserConfigNames(dbStore); } - configList[index] = newName; + const nameIndex = configList.findIndex(n => n === oldName); + configList[nameIndex] = newName; await configListMapStore.ResetConfig(type, configList, store); } }