feat(API): add new function getStoreTags to fetch store tags from API
fix(extraSidebarComponent): fix saveFlowStore function call to pass tag ids instead of tag names for selected tags
This commit is contained in:
parent
cb03095860
commit
1d57800892
2 changed files with 31 additions and 5 deletions
|
|
@ -706,3 +706,15 @@ export async function getNumberOfComponents() {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getStoreTags() {
|
||||||
|
try {
|
||||||
|
const res = await api.get(`${BASE_URL_API}store/tags`);
|
||||||
|
if (res.status === 200) {
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import { useContext, useEffect, useMemo, useState } from "react";
|
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { ReactFlowJsonObject } from "reactflow";
|
import { ReactFlowJsonObject } from "reactflow";
|
||||||
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
||||||
import IconComponent from "../../../../components/genericIconComponent";
|
import IconComponent from "../../../../components/genericIconComponent";
|
||||||
|
|
@ -10,7 +10,7 @@ import { Separator } from "../../../../components/ui/separator";
|
||||||
import { alertContext } from "../../../../contexts/alertContext";
|
import { alertContext } from "../../../../contexts/alertContext";
|
||||||
import { TabsContext } from "../../../../contexts/tabsContext";
|
import { TabsContext } from "../../../../contexts/tabsContext";
|
||||||
import { typesContext } from "../../../../contexts/typesContext";
|
import { typesContext } from "../../../../contexts/typesContext";
|
||||||
import { saveFlowStore } from "../../../../controllers/API";
|
import { getStoreTags, saveFlowStore } from "../../../../controllers/API";
|
||||||
import ApiModal from "../../../../modals/ApiModal";
|
import ApiModal from "../../../../modals/ApiModal";
|
||||||
import ConfirmationModal from "../../../../modals/ConfirmationModal";
|
import ConfirmationModal from "../../../../modals/ConfirmationModal";
|
||||||
import ExportModal from "../../../../modals/exportModal";
|
import ExportModal from "../../../../modals/exportModal";
|
||||||
|
|
@ -56,10 +56,14 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
|
|
||||||
const [tags, setTags] = useState<string[]>([]);
|
const [tags, setTags] = useState<string[]>([]);
|
||||||
const [selectedTags, setSelectedTags] = useState<Set<string>>(new Set());
|
const [selectedTags, setSelectedTags] = useState<Set<string>>(new Set());
|
||||||
|
const tagListId = useRef<{ id: string; name: string }[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//TODO: get tags from api
|
getStoreTags().then((res) => {
|
||||||
setTags(["teste1", "teste2"]);
|
tagListId.current = res;
|
||||||
|
let tags = res.map((tag) => tag.name);
|
||||||
|
setTags(tags);
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function handleTagSelection(tag: string) {
|
function handleTagSelection(tag: string) {
|
||||||
|
|
@ -74,6 +78,12 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTagsIds(tags: string[]) {
|
||||||
|
return tags
|
||||||
|
.map((tag) => tagListId.current.find((tagObj) => tagObj.name === tag))!
|
||||||
|
.map((tag) => tag!.id);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle showing components after use search input
|
// Handle showing components after use search input
|
||||||
function handleSearchInput(e: string) {
|
function handleSearchInput(e: string) {
|
||||||
if (e === "") {
|
if (e === "") {
|
||||||
|
|
@ -139,7 +149,11 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
},
|
},
|
||||||
is_component: false,
|
is_component: false,
|
||||||
};
|
};
|
||||||
saveFlowStore(saveFlow, Array.from(selectedTags), sharePublic).then(
|
saveFlowStore(
|
||||||
|
saveFlow,
|
||||||
|
getTagsIds(Array.from(selectedTags)),
|
||||||
|
sharePublic
|
||||||
|
).then(
|
||||||
() => {
|
() => {
|
||||||
setSuccessData({
|
setSuccessData({
|
||||||
title: "Flow shared successfully",
|
title: "Flow shared successfully",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue