Add behavior can filter by name

This commit is contained in:
2022-03-29 14:32:28 +08:00
parent b6f8828c3b
commit d4cd06196f
3 changed files with 96 additions and 17 deletions
@@ -1,10 +1,10 @@
import { Component, ReactNode } from "react";
import { Component, ReactNode, Fragment } from "react";
import { Popup } from "@Context/Popups";
import { Localization, I18N } from "@Component/Localization/Localization";
import { Localization } from "@Component/Localization/Localization";
import { SearchBox } from "@Component/SearchBox/SearchBox";
import { ConfirmContent } from "@Component/ConfirmPopup/ConfirmPopup";
import { BehaviorList } from "@Component/BehaviorList/BehaviorList";
import { AllBehaviors } from "@Behavior/Behavior";
import { AllBehaviorsWithCategory, ICategoryBehavior } from "@Behavior/Behavior";
import { Message } from "@Component/Message/Message";
import { IRenderBehavior } from "@Model/Behavior";
import { useStatus, IMixinStatusProps } from "@Context/Status";
@@ -90,21 +90,28 @@ class BehaviorPopupComponent extends Component<
/>
}
public render(): ReactNode {
return <ConfirmContent
className="behavior-popup"
actions={[{
i18nKey: "Popup.Add.Behavior.Action.Add",
disable: this.state.focusBehavior.size <= 0
}]}
header={this.renderHeader}
customFooter={this.renderActionBar}
headerHeight={46}
>
<Message i18nKey="ZH_CN" isTitle first/>
private renderBehaviors = (behaviors: ICategoryBehavior, first: boolean) => {
let language = this.props.setting?.language ?? "EN_US";
let filterItem = behaviors.item.filter((item) => {
let name = item.getTerms(item.behaviorName, this.props.setting?.language);
if (this.state.searchValue) {
return name.includes(this.state.searchValue);
} else {
return true;
}
})
if (filterItem.length <= 0) return undefined;
return <Fragment key={behaviors.key}>
<Message
text={behaviors.category[language] ?? behaviors.key}
first={first} isTitle
/>
<BehaviorList
focusBehaviors={Array.from(this.state.focusBehavior)}
behaviors={AllBehaviors}
behaviors={filterItem}
action={this.showBehaviorInfo}
click={(behavior) => {
if (this.state.focusBehavior.has(behavior)) {
@@ -115,6 +122,28 @@ class BehaviorPopupComponent extends Component<
this.forceUpdate();
}}
/>
</Fragment>
}
public render(): ReactNode {
let first: boolean = true;
return <ConfirmContent
className="behavior-popup"
actions={[{
i18nKey: "Popup.Add.Behavior.Action.Add",
disable: this.state.focusBehavior.size <= 0
}]}
header={this.renderHeader}
customFooter={this.renderActionBar}
headerHeight={46}
>
{AllBehaviorsWithCategory.map((behavior) => {
let renderItem = this.renderBehaviors(behavior, first);
if (renderItem) {
first = false;
}
return renderItem;
}).filter((x) => !!x)}
</ConfirmContent>
}
}