Skip to content

Commit

Permalink
fix: Correct the implementation logic of the filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pojol committed Jul 5, 2023
1 parent 6275d5f commit 7f84cde
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 46 deletions.
8 changes: 3 additions & 5 deletions editor/src/pages/bots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,11 @@ const Bots = (props: BotsProps) => {

var intags = (tags: Array<string>) => {
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) {
Expand Down
1 change: 1 addition & 0 deletions editor/src/pages/edit/blackboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default function Blackboard() {
setActive("2")
}

setRuntimeerr("")
setChange(msg)
}

Expand Down
40 changes: 15 additions & 25 deletions editor/src/pages/edit/side.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,46 +60,37 @@ export const EditSidePlane: React.FC<SideProps> = ({ 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<string>()
let taglst = new Array<PrefabTagInfo>()
var tagSet = new Set<string>()

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 {
Expand All @@ -123,7 +114,7 @@ export const EditSidePlane: React.FC<SideProps> = ({ 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())
Expand All @@ -148,10 +139,9 @@ export const EditSidePlane: React.FC<SideProps> = ({ graph, isGraphCreated }) =>

const onSelectChange = (value: string[]) => {
setSelectTags(value)
reloadPrefab()
reloadPrefab(value)
};


return (
<div className="dnd-wrap">

Expand Down
22 changes: 7 additions & 15 deletions editor/src/pages/prefab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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<DataType[]>([]);
const [code, setCode] = useState<string>("");
Expand All @@ -55,6 +54,8 @@ const Prefab = (props: PrefabProps) => {
const [newPrefabName, setNewPrefabName] = useState<string>("");
const [searchedColumn, setSearchedColumn] = useState<DataIndex>();

const dispatch = useDispatch()

const { themeValue } = useSelector((state: RootState) => state.configSlice)

let obj: any = null
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -413,13 +414,4 @@ const Prefab = (props: PrefabProps) => {
</Modal>
</div>
);
}

const mapStateToProps = (state: RootState) => ({
prefabMap: state.prefabSlice.pmap
});

const connector = connect(mapStateToProps);
type PropsFromRedux = ConnectedProps<typeof connector>;

export default connector(Prefab);
}
2 changes: 1 addition & 1 deletion editor/src/utils/request.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 7f84cde

Please sign in to comment.