diff --git a/src/lib/components/workspace/Functions.svelte b/src/lib/components/workspace/Functions.svelte index 5ecfd19f9..25d16ea16 100644 --- a/src/lib/components/workspace/Functions.svelte +++ b/src/lib/components/workspace/Functions.svelte @@ -20,6 +20,8 @@ import Tooltip from '../common/Tooltip.svelte'; import ConfirmDialog from '../common/ConfirmDialog.svelte'; import { getModels } from '$lib/apis'; + import FunctionMenu from './Functions/FunctionMenu.svelte'; + import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte'; const i18n = getContext('i18n'); @@ -28,6 +30,54 @@ let showConfirm = false; let query = ''; + + const shareHandler = async (tool) => { + console.log(tool); + }; + + const cloneHandler = async (func) => { + const _function = await getFunctionById(localStorage.token, func.id).catch((error) => { + toast.error(error); + return null; + }); + + if (_function) { + sessionStorage.function = JSON.stringify({ + ..._function, + id: `${_function.id}_clone`, + name: `${_function.name} (Clone)` + }); + goto('/workspace/functions/create'); + } + }; + + const exportHandler = async (func) => { + const _function = await getFunctionById(localStorage.token, func.id).catch((error) => { + toast.error(error); + return null; + }); + + if (_function) { + let blob = new Blob([JSON.stringify([_function])], { + type: 'application/json' + }); + saveAs(blob, `function-${_function.id}-export-${Date.now()}.json`); + } + }; + + const deleteHandler = async (func) => { + const res = await deleteFunctionById(localStorage.token, func.id).catch((error) => { + toast.error(error); + return null; + }); + + if (res) { + toast.success('Function deleted successfully'); + + functions.set(await getFunctions(localStorage.token)); + models.set(await getModels(localStorage.token)); + } + }; @@ -87,18 +137,14 @@ {#each $functions.filter((f) => query === '' || f.name .toLowerCase() .includes(query.toLowerCase()) || f.id.toLowerCase().includes(query.toLowerCase())) as func} - - - - - - - - - - + - + {/each} diff --git a/src/lib/components/workspace/Functions/FunctionMenu.svelte b/src/lib/components/workspace/Functions/FunctionMenu.svelte new file mode 100644 index 000000000..9a4177b1e --- /dev/null +++ b/src/lib/components/workspace/Functions/FunctionMenu.svelte @@ -0,0 +1,92 @@ + + + { + if (e.detail === false) { + onClose(); + } + }} +> + + + + +
+ + { + shareHandler(); + }} + > + +
{$i18n.t('Share')}
+
+ + { + cloneHandler(); + }} + > + + +
{$i18n.t('Clone')}
+
+ + { + exportHandler(); + }} + > + + +
{$i18n.t('Export')}
+
+ +
+ + { + deleteHandler(); + }} + > + +
{$i18n.t('Delete')}
+
+
+
+