Merge remote-tracking branch 'origin/dev' into bug/minimize_handle
This commit is contained in:
commit
5b2ad174f3
2 changed files with 114 additions and 32 deletions
|
|
@ -817,3 +817,46 @@ export async function getStoreTags() {
|
||||||
export const postLikeComponent = (componentId: string) => {
|
export const postLikeComponent = (componentId: string) => {
|
||||||
return api.post(`${BASE_URL_API}store/users/likes/${componentId}`);
|
return api.post(`${BASE_URL_API}store/users/likes/${componentId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing flow in the Store.
|
||||||
|
*
|
||||||
|
* @param {FlowType} updatedFlow - The updated flow data.
|
||||||
|
* @returns {Promise<any>} The updated flow data.
|
||||||
|
* @throws Will throw an error if the update fails.
|
||||||
|
*/
|
||||||
|
export async function updateFlowStore(
|
||||||
|
newFlow: {
|
||||||
|
name?: string;
|
||||||
|
data: ReactFlowJsonObject | null;
|
||||||
|
description?: string;
|
||||||
|
style?: FlowStyleType;
|
||||||
|
is_component?: boolean;
|
||||||
|
parent?: string;
|
||||||
|
last_tested_version?: string;
|
||||||
|
},
|
||||||
|
tags: string[],
|
||||||
|
publicFlow = false,
|
||||||
|
id: string
|
||||||
|
): Promise<FlowType> {
|
||||||
|
try {
|
||||||
|
const response = await api.patch(`${BASE_URL_API}store/components/${id}`, {
|
||||||
|
name: newFlow.name,
|
||||||
|
data: newFlow.data,
|
||||||
|
description: newFlow.description,
|
||||||
|
is_component: newFlow.is_component,
|
||||||
|
parent: newFlow.parent,
|
||||||
|
tags: tags,
|
||||||
|
private: !publicFlow,
|
||||||
|
last_tested_version: newFlow.last_tested_version,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status !== 201) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
import { ReactNode, useContext, useEffect, useMemo, useState } from "react";
|
import { ReactNode, useContext, useEffect, useMemo, useState } from "react";
|
||||||
import EditFlowSettings from "../../components/EditFlowSettingsComponent";
|
import EditFlowSettings from "../../components/EditFlowSettingsComponent";
|
||||||
import IconComponent from "../../components/genericIconComponent";
|
import IconComponent from "../../components/genericIconComponent";
|
||||||
|
|
@ -11,6 +12,7 @@ import {
|
||||||
getStoreComponents,
|
getStoreComponents,
|
||||||
getStoreTags,
|
getStoreTags,
|
||||||
saveFlowStore,
|
saveFlowStore,
|
||||||
|
updateFlowStore,
|
||||||
} from "../../controllers/API";
|
} from "../../controllers/API";
|
||||||
import { FlowType } from "../../types/flow";
|
import { FlowType } from "../../types/flow";
|
||||||
import {
|
import {
|
||||||
|
|
@ -50,7 +52,9 @@ export default function ShareModal({
|
||||||
const [loadingTags, setLoadingTags] = useState<boolean>(false);
|
const [loadingTags, setLoadingTags] = useState<boolean>(false);
|
||||||
const [sharePublic, setSharePublic] = useState(true);
|
const [sharePublic, setSharePublic] = useState(true);
|
||||||
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
||||||
const [unavaliableNames, setUnavaliableNames] = useState<string[]>([]);
|
const [unavaliableNames, setUnavaliableNames] = useState<
|
||||||
|
{ id: string; name: string }[]
|
||||||
|
>([]);
|
||||||
const { saveFlow, flows, tabId } = useContext(FlowsContext);
|
const { saveFlow, flows, tabId } = useContext(FlowsContext);
|
||||||
|
|
||||||
const [loadingNames, setLoadingNames] = useState(false);
|
const [loadingNames, setLoadingNames] = useState(false);
|
||||||
|
|
@ -74,17 +78,18 @@ export default function ShareModal({
|
||||||
|
|
||||||
async function handleGetNames() {
|
async function handleGetNames() {
|
||||||
setLoadingNames(true);
|
setLoadingNames(true);
|
||||||
const unavaliableNames: Array<string> = [];
|
const unavaliableNames: Array<{ id: string; name: string }> = [];
|
||||||
await getStoreComponents({ fields: ["name"], filterByUser: true }).then(
|
await getStoreComponents({
|
||||||
(res) => {
|
fields: ["name", "id"],
|
||||||
res?.results?.forEach((element: any) => {
|
filterByUser: true,
|
||||||
if (element.is_component === is_component)
|
}).then((res) => {
|
||||||
unavaliableNames.push(element.name);
|
res?.results?.forEach((element: any) => {
|
||||||
});
|
if (element.is_component === is_component)
|
||||||
setUnavaliableNames(unavaliableNames);
|
unavaliableNames.push({ name: element.name, id: element.id });
|
||||||
setLoadingNames(false);
|
});
|
||||||
}
|
setUnavaliableNames(unavaliableNames);
|
||||||
);
|
setLoadingNames(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -92,7 +97,7 @@ export default function ShareModal({
|
||||||
setDescription(component?.description ?? "");
|
setDescription(component?.description ?? "");
|
||||||
}, [component, open, internalOpen]);
|
}, [component, open, internalOpen]);
|
||||||
|
|
||||||
const handleShareComponent = async () => {
|
const handleShareComponent = async (update = false) => {
|
||||||
//remove file names from flows before sharing
|
//remove file names from flows before sharing
|
||||||
removeFileNameFromComponents(component);
|
removeFileNameFromComponents(component);
|
||||||
const flow: FlowType = checked
|
const flow: FlowType = checked
|
||||||
|
|
@ -113,28 +118,42 @@ export default function ShareModal({
|
||||||
is_component: is_component,
|
is_component: is_component,
|
||||||
});
|
});
|
||||||
|
|
||||||
await saveFlow(flows.find((flow) => flow.id === tabId)!, true);
|
function successShare() {
|
||||||
|
if (is_component) {
|
||||||
|
addFlow(true, flow);
|
||||||
|
}
|
||||||
|
setSuccessData({
|
||||||
|
title: `${nameComponent} shared successfully`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
saveFlowStore(flow!, getTagsIds(selectedTags, tags), sharePublic).then(
|
await saveFlow(flows.find((flow) => flow.id === tabId)!, true);
|
||||||
() => {
|
if (!update)
|
||||||
if (is_component) {
|
saveFlowStore(flow!, getTagsIds(selectedTags, tags), sharePublic).then(
|
||||||
addFlow(true, flow);
|
successShare,
|
||||||
|
(err) => {
|
||||||
|
setErrorData({
|
||||||
|
title: "Error sharing " + is_component ? "component" : "flow",
|
||||||
|
list: [err["response"]["data"]["detail"]],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setSuccessData({
|
);
|
||||||
title: `${nameComponent} shared successfully`,
|
else
|
||||||
});
|
updateFlowStore(
|
||||||
},
|
flow!,
|
||||||
(err) => {
|
getTagsIds(selectedTags, tags),
|
||||||
|
sharePublic,
|
||||||
|
unavaliableNames.find((e) => e.name === name)!.id
|
||||||
|
).then(successShare, (err) => {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Error sharing " + is_component ? "component" : "flow",
|
title: "Error sharing " + is_component ? "component" : "flow",
|
||||||
list: [err["response"]["data"]["detail"]],
|
list: [err["response"]["data"]["detail"]],
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdateComponent = () => {
|
const handleUpdateComponent = () => {
|
||||||
handleShareComponent();
|
handleShareComponent(true);
|
||||||
if (setOpen) setOpen(false);
|
if (setOpen) setOpen(false);
|
||||||
else internalSetOpen(false);
|
else internalSetOpen(false);
|
||||||
};
|
};
|
||||||
|
|
@ -142,7 +161,7 @@ export default function ShareModal({
|
||||||
let modalConfirmationButton = useMemo(() => {
|
let modalConfirmationButton = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{unavaliableNames.includes(name) ? (
|
{unavaliableNames.find((element) => element.name === name) ? (
|
||||||
<ConfirmationModal
|
<ConfirmationModal
|
||||||
title="Update"
|
title="Update"
|
||||||
titleHeader={name}
|
titleHeader={name}
|
||||||
|
|
@ -168,8 +187,18 @@ export default function ShareModal({
|
||||||
<ConfirmationModal.Trigger>
|
<ConfirmationModal.Trigger>
|
||||||
<div className="text-right">
|
<div className="text-right">
|
||||||
<Button disabled={loadingNames} type="button">
|
<Button disabled={loadingNames} type="button">
|
||||||
{is_component ? "Save and " : ""}Share{" "}
|
{loadingNames ? (
|
||||||
{!is_component ? "Flow" : ""}
|
<>
|
||||||
|
<div className="center w-16">
|
||||||
|
<Loader2 className="m-auto h-4 w-4 animate-spin"></Loader2>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{is_component && !loadingNames ? "Save and " : ""}Share{" "}
|
||||||
|
{!is_component && !loadingNames ? "Flow" : ""}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</ConfirmationModal.Trigger>
|
</ConfirmationModal.Trigger>
|
||||||
|
|
@ -185,8 +214,18 @@ export default function ShareModal({
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
{is_component ? "Save and " : ""}Share{" "}
|
{loadingNames ? (
|
||||||
{!is_component ? "Flow" : ""}
|
<>
|
||||||
|
<div className="center w-16">
|
||||||
|
<Loader2 className="m-auto h-4 w-4 animate-spin"></Loader2>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{is_component && !loadingNames ? "Save and " : ""}Share{" "}
|
||||||
|
{!is_component && !loadingNames ? "Flow" : ""}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
@ -214,7 +253,7 @@ export default function ShareModal({
|
||||||
<BaseModal.Content>
|
<BaseModal.Content>
|
||||||
<EditFlowSettings
|
<EditFlowSettings
|
||||||
name={name}
|
name={name}
|
||||||
invalidNameList={unavaliableNames}
|
invalidNameList={unavaliableNames.map((element) => element.name)}
|
||||||
description={description}
|
description={description}
|
||||||
setName={setName}
|
setName={setName}
|
||||||
setDescription={setDescription}
|
setDescription={setDescription}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue