From 7f84cde9548a853acccbc6c7fdd1f483d704dc10 Mon Sep 17 00:00:00 2001 From: pojol Date: Wed, 5 Jul 2023 20:12:28 +0800 Subject: [PATCH] fix: Correct the implementation logic of the filter --- editor/src/pages/bots.tsx | 8 +++--- editor/src/pages/edit/blackboard.tsx | 1 + editor/src/pages/edit/side.tsx | 40 +++++++++++----------------- editor/src/pages/prefab.tsx | 22 +++++---------- editor/src/utils/request.js | 2 +- 5 files changed, 27 insertions(+), 46 deletions(-) diff --git a/editor/src/pages/bots.tsx b/editor/src/pages/bots.tsx index dfda46a..0794fd7 100644 --- a/editor/src/pages/bots.tsx +++ b/editor/src/pages/bots.tsx @@ -153,13 +153,11 @@ const Bots = (props: BotsProps) => { var intags = (tags: Array) => { for (var i = 0; i < selectedTag.length; i++) { - for (var j = 0; j < tags.length; j++) { - if (selectedTag[i] === tags[j]) { - return true - } + if (!tags.includes(selectedTag[i])) { + return false } } - return false + return true } if (bots.length > 0) { diff --git a/editor/src/pages/edit/blackboard.tsx b/editor/src/pages/edit/blackboard.tsx index b76de5f..d938da0 100644 --- a/editor/src/pages/edit/blackboard.tsx +++ b/editor/src/pages/edit/blackboard.tsx @@ -71,6 +71,7 @@ export default function Blackboard() { setActive("2") } + setRuntimeerr("") setChange(msg) } diff --git a/editor/src/pages/edit/side.tsx b/editor/src/pages/edit/side.tsx index 5d0b9f2..b28069e 100644 --- a/editor/src/pages/edit/side.tsx +++ b/editor/src/pages/edit/side.tsx @@ -60,46 +60,37 @@ export const EditSidePlane: React.FC = ({ graph, isGraphCreated }) => })) resizeSidePane() - reloadPrefab() + reloadPrefab([]) } }, [isGraphCreated]) - /* - PubSub.subscribe(Topic.PrefabUpdateAll, (topic: string, info: any) => { - this.reloadPrefab() - }); - - */ - const matchTags = (tags: string[]): boolean => { - - let selecttags = selectTags - for (var i = 0; i < selecttags.length; i++) { - for (var j = 0; j < tags.length; j++) { - if (tags[j] === selecttags[i]) { - console.info(tags[j], "match", selecttags[i]) - return true - } + const matchTags = (matchtags:string[], tags: string[]): boolean => { + + for (let i = 0; i < matchtags.length; i++) { + if (!tags.includes(matchtags[i])) { + return false; } } - - return false + return true; + } - const reloadPrefab = () => { + const reloadPrefab = (newtags :string[]) => { const prefabMap = pmap - setSelectTags([]) setTags([]) let tmplst = new Array() let taglst = new Array() var tagSet = new Set() + console.info("new tags", newtags) + prefabMap.forEach((value: PrefabInfo) => { - if (selectTags.length !== 0) { - if (matchTags(value.tags)) { + if (newtags !== undefined && newtags.length !== 0) { + if (matchTags(newtags, value.tags)) { tmplst.push(value.name) } } else { @@ -123,7 +114,7 @@ export const EditSidePlane: React.FC = ({ graph, isGraphCreated }) => const resizeSidePane = () => { var div = document.getElementById("prefab-pane") if (div !== null) { - var clienth = document.documentElement.clientHeight - 260 + var clienth = document.documentElement.clientHeight - 270 div.style.height = clienth.toString() + "px" div.style.overflow = "auto" console.info("set", document.documentElement.clientHeight.toString()) @@ -148,10 +139,9 @@ export const EditSidePlane: React.FC = ({ graph, isGraphCreated }) => const onSelectChange = (value: string[]) => { setSelectTags(value) - reloadPrefab() + reloadPrefab(value) }; - return (
diff --git a/editor/src/pages/prefab.tsx b/editor/src/pages/prefab.tsx index b9ad13e..c8bfd73 100644 --- a/editor/src/pages/prefab.tsx +++ b/editor/src/pages/prefab.tsx @@ -23,7 +23,7 @@ import { connect, ConnectedProps } from 'react-redux'; import { addItem, removeItem, cleanItems } from '../models/prefab'; import { RootState } from '@/models/store'; -import { useSelector } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; const { Post, PostGetBlob, PostBlob } = require("../utils/request"); @@ -44,9 +44,8 @@ interface DataType { type DataIndex = keyof DataType; -interface PrefabProps extends PropsFromRedux { } -const Prefab = (props: PrefabProps) => { +export default function Prefab () { const [data, setData] = useState([]); const [code, setCode] = useState(""); @@ -55,6 +54,8 @@ const Prefab = (props: PrefabProps) => { const [newPrefabName, setNewPrefabName] = useState(""); const [searchedColumn, setSearchedColumn] = useState(); + const dispatch = useDispatch() + const { themeValue } = useSelector((state: RootState) => state.configSlice) let obj: any = null @@ -100,7 +101,7 @@ const Prefab = (props: PrefabProps) => { const syncConfig = () => { - props.dispatch(cleanItems()) + dispatch(cleanItems()) Post(localStorage.remoteAddr, Api.PrefabList, {}).then((json: any) => { if (json.Code !== 200) { @@ -137,7 +138,7 @@ const Prefab = (props: PrefabProps) => { tags: element.tags, code: String(reader.result), } - props.dispatch(addItem({ key: element.name, value: pi })) + dispatch(addItem({ key: element.name, value: pi })) counter++; if (counter === lst.length) { @@ -413,13 +414,4 @@ const Prefab = (props: PrefabProps) => {
); -} - -const mapStateToProps = (state: RootState) => ({ - prefabMap: state.prefabSlice.pmap -}); - -const connector = connect(mapStateToProps); -type PropsFromRedux = ConnectedProps; - -export default connector(Prefab); \ No newline at end of file +} \ No newline at end of file diff --git a/editor/src/utils/request.js b/editor/src/utils/request.js index f63defb..4961097 100644 --- a/editor/src/utils/request.js +++ b/editor/src/utils/request.js @@ -1,6 +1,6 @@ function Post(url, methon, formData) { - console.info("post methon", methon, "body=>", JSON.stringify(formData)) + //console.info("post methon", methon, "body=>", JSON.stringify(formData)) return new Promise(function (resolve, reject) { fetch(url + "/" + methon, { method: "POST",