From 1634c0462e59584d7d4bd3eee93dcdc76e2c473e Mon Sep 17 00:00:00 2001 From: koushikFusion Date: Mon, 27 May 2024 00:05:16 +0530 Subject: [PATCH 1/5] update endpoint implemented --- package.json | 19 +-- src/app/App.tsx | 6 +- src/app/components/Asset/Asset.tsx | 130 ++++++++++++--------- src/app/components/TextInput/TextInput.tsx | 26 +++++ 4 files changed, 118 insertions(+), 63 deletions(-) diff --git a/package.json b/package.json index 999ad91..c525657 100644 --- a/package.json +++ b/package.json @@ -12,24 +12,25 @@ }, "dependencies": { "@pieces.app/pieces-os-client": "^2.0.0-2", + "jest-environment-jsdom": "^29.7.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "^5.0.1", - "ts-node": "^10.9.1", - "jest-environment-jsdom": "^29.7.0" + "ts-node": "^10.9.2" }, "devDependencies": { - "@types/node": "^20.8.7", - "@types/react": "^18.2.45", - "@types/react-dom": "^18.2.17", - "cross-env": "^7.0.3", - "rimraf": "^3.0.2", - "typescript": "^4.9.5", "@testing-library/jest-dom": "^6.2.0", "@testing-library/react": "^14.1.2", "@types/jest": "^29.5.11", + "@types/node": "^20.12.12", + "@types/react": "^18.2.45", + "@types/react-dom": "^18.2.17", + "cross-env": "^7.0.3", "jest": "^29.7.0", - "ts-jest": "^29.1.1" + "rimraf": "^3.0.2", + "ts-jest": "^29.1.1", + "tslib": "^2.6.2", + "typescript": "^4.9.5" }, "browserslist": { "production": [ diff --git a/src/app/App.tsx b/src/app/App.tsx index 0efa16d..a0bc3f9 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -10,6 +10,7 @@ import { Indicator } from "./components/Indicator/Indicator"; import CopilotStreamController from "./controllers/copilotStreamController"; import "./global.css"; import WorkflowActivityList from "./components/WorkflowActivity"; +// import { UpdateAssetButton } from "./components/TextInput/TextInput"; // types @@ -225,7 +226,8 @@ export function App(): React.JSX.Element { } - + +
@@ -234,11 +236,11 @@ export function App(): React.JSX.Element {

Create a New Snippet

+ {/* */}
- {/* this is the copilot container. the copilot logic is inside the /components/Copilot.tsx */}
diff --git a/src/app/components/Asset/Asset.tsx b/src/app/components/Asset/Asset.tsx index b832d63..9e2c04a 100644 --- a/src/app/components/Asset/Asset.tsx +++ b/src/app/components/Asset/Asset.tsx @@ -1,65 +1,65 @@ import * as Pieces from "@pieces.app/pieces-os-client"; -import {SeededAsset, SeedTypeEnum} from "@pieces.app/pieces-os-client"; -import {Application} from "@pieces.app/pieces-os-client"; +import { SeededAsset, SeedTypeEnum } from "@pieces.app/pieces-os-client"; +import { Application } from "@pieces.app/pieces-os-client"; type LocalAsset = { name: string, id: string, classification: Pieces.ClassificationSpecificEnum, - } +} //==============================[/create]==================================// export function createAsset(applicationData: Application, data: string, name: string) { - let _seededAsset: SeededAsset = { - application: applicationData, - format: { - fragment: { - string: { raw: data }, - }, - }, - metadata: { - name: name - } - } - - // create your seed - let _seed: Pieces.Seed = { - asset: _seededAsset, - type: SeedTypeEnum.Asset - } - - console.log("seed:", _seed) - - // make your api call. - new Pieces.AssetsApi().assetsCreateNewAsset({seed: _seed}).then(_a => { - console.log("well howdy", _a); - }) + let _seededAsset: SeededAsset = { + application: applicationData, + format: { + fragment: { + string: { raw: data }, + }, + }, + metadata: { + name: name + } + } + + // create your seed + let _seed: Pieces.Seed = { + asset: _seededAsset, + type: SeedTypeEnum.Asset + } + + console.log("here at asset seed:", _seed) + + // make your api call. + new Pieces.AssetsApi().assetsCreateNewAsset({ seed: _seed }).then(_a => { + console.log("well howdy", _a); + }) } //==============================[.end /create]==================================// -export function deleteAsset(_id: String,setArray:Function){ +export function deleteAsset(_id: String, setArray: Function) { - const newAssetsList : Array = []; + const newAssetsList: Array = []; - new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { - for (let i = 0; i < _assetList.iterable.length; i++) { - if (_assetList.iterable[i].id == _id) { - new Pieces.AssetsApi().assetsDeleteAsset({asset: _assetList.iterable[i].id }).then(()=>console.log(_id)); + new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { + for (let i = 0; i < _assetList.iterable.length; i++) { + if (_assetList.iterable[i].id == _id) { + new Pieces.AssetsApi().assetsDeleteAsset({ asset: _assetList.iterable[i].id }).then(() => console.log(_id)); } - else{ - newAssetsList.push( { + else { + newAssetsList.push({ id: _assetList.iterable[i].id, name: _assetList.iterable[i].name, classification: _assetList.iterable[i].original.reference.classification.specific }) } - } - window.alert("selected snippet got deleted"); - setArray(newAssetsList); - }) + } + window.alert("selected snippet got deleted"); + setArray(newAssetsList); + }) } // used to rename an asset, takes in an _id and _name that comes from the input fields on @@ -67,20 +67,46 @@ export function deleteAsset(_id: String,setArray:Function){ // // this uses your asset snapshot to get your list of snippets, then() to get the snippet list back, // then use the _id to select the snippet from the list of all snippets. -export function renameAsset(_name: string, _id: String){ +export function renameAsset(_name: string, _id: String) { + + new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { + console.log("_assetList in rename", _assetList) + for (let i = 0; i < _assetList.iterable.length; i++) { + if (_assetList.iterable[i].id == _id) { + + let _asset = _assetList.iterable[i]; + + _asset.name = _name; + + new Pieces.AssetApi().assetUpdate({ asset: _asset }).then(_updated => { + console.log("updated:", _updated); + }) + } + } + }) +} + +//==============================[Udit/Update]==================================// + +export function updateAsset(_id: string, data: string, setArray: Function) { + + const AssestList: Array = [] - new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { - for (let i = 0; i < _assetList.iterable.length; i++) { - if (_assetList.iterable[i].id == _id) { + new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { - let _asset = _assetList.iterable[i]; + for (let i = 0; i < _assetList.iterable.length; i++) { + if (_assetList.iterable[i].id == _id) { - _asset.name = _name; + let _asset = _assetList.iterable[i]; + + new Pieces.AssetApi().assetAssociateTag({ asset: _asset.id, tag: data }).then(() => { + console.log("Tag associated with asset successfully"); + setArray([...AssestList]); + }).catch(error => { + console.error("Failed to associate tag with asset:", error); + }); + } + } + }) +} - new Pieces.AssetApi().assetUpdate({asset: _asset}).then(_updated => { - console.log("updated:", _updated); - }) - } - } - }) -} \ No newline at end of file diff --git a/src/app/components/TextInput/TextInput.tsx b/src/app/components/TextInput/TextInput.tsx index c023d0e..c385ecc 100644 --- a/src/app/components/TextInput/TextInput.tsx +++ b/src/app/components/TextInput/TextInput.tsx @@ -2,6 +2,7 @@ import * as React from "react"; import { useState } from "react"; import { deleteAsset, renameAsset } from "../Asset/Asset"; import { CreateButton } from "../Button/Button"; +import {updateAsset} from "../Asset/Asset" import "./TextInput.css"; export function DataTextInput({ applicationData }) { @@ -46,6 +47,8 @@ export function DeleteAssetButton({ assetID, selectedIndex ,setArray}) { ); } + + export function RenameAssetInput({ assetID }) { const [name, setNameValue] = useState(""); @@ -70,4 +73,27 @@ export function RenameAssetInput({ assetID }) { ); } +// export function UpdateAssetButton({ assetID, setArray }) { +// const [data, setData] = useState(""); +// const handleDataChange = (event) => { +// setData(event.target.value); +// }; + +// const editAsset = () => { +// updateAsset(assetID, data, setArray); +// }; +// return ( +// <> +// +// +// +// ); +// } From 08a84fb0e557d8b21928fbe5e230b1b1fc58f72c Mon Sep 17 00:00:00 2001 From: koushikFusion Date: Mon, 27 May 2024 19:19:02 +0530 Subject: [PATCH 2/5] spaces corrected --- src/app/components/Asset/Asset.tsx | 61 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/app/components/Asset/Asset.tsx b/src/app/components/Asset/Asset.tsx index 9e2c04a..283f78a 100644 --- a/src/app/components/Asset/Asset.tsx +++ b/src/app/components/Asset/Asset.tsx @@ -1,6 +1,6 @@ import * as Pieces from "@pieces.app/pieces-os-client"; -import { SeededAsset, SeedTypeEnum } from "@pieces.app/pieces-os-client"; -import { Application } from "@pieces.app/pieces-os-client"; +import {SeededAsset, SeedTypeEnum} from "@pieces.app/pieces-os-client"; +import {Application} from "@pieces.app/pieces-os-client"; type LocalAsset = { @@ -12,30 +12,30 @@ type LocalAsset = { //==============================[/create]==================================// export function createAsset(applicationData: Application, data: string, name: string) { - let _seededAsset: SeededAsset = { - application: applicationData, - format: { - fragment: { - string: { raw: data }, - }, +let _seededAsset: SeededAsset = { + application: applicationData, + format: { + fragment: { + string: { raw: data }, }, - metadata: { - name: name - } + }, + metadata: { + name: name } +} // create your seed - let _seed: Pieces.Seed = { - asset: _seededAsset, - type: SeedTypeEnum.Asset - } +let _seed: Pieces.Seed = { + asset: _seededAsset, + type: SeedTypeEnum.Asset +} - console.log("here at asset seed:", _seed) +console.log("here at asset seed:", _seed) // make your api call. - new Pieces.AssetsApi().assetsCreateNewAsset({ seed: _seed }).then(_a => { - console.log("well howdy", _a); - }) + new Pieces.AssetsApi().assetsCreateNewAsset({ seed: _seed }).then(_a => { + console.log("well howdy", _a); +}) } //==============================[.end /create]==================================// @@ -44,22 +44,22 @@ export function deleteAsset(_id: String, setArray: Function) { const newAssetsList: Array = []; - new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { - for (let i = 0; i < _assetList.iterable.length; i++) { - if (_assetList.iterable[i].id == _id) { - new Pieces.AssetsApi().assetsDeleteAsset({ asset: _assetList.iterable[i].id }).then(() => console.log(_id)); +new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { + for (let i = 0; i < _assetList.iterable.length; i++) { + if (_assetList.iterable[i].id == _id) { + new Pieces.AssetsApi().assetsDeleteAsset({ asset: _assetList.iterable[i].id }).then(() => console.log(_id)); } - else { + else{ newAssetsList.push({ id: _assetList.iterable[i].id, name: _assetList.iterable[i].name, classification: _assetList.iterable[i].original.reference.classification.specific }) } - } - window.alert("selected snippet got deleted"); - setArray(newAssetsList); - }) + } + window.alert("selected snippet got deleted"); + setArray(newAssetsList); +}) } // used to rename an asset, takes in an _id and _name that comes from the input fields on @@ -93,9 +93,8 @@ export function updateAsset(_id: string, data: string, setArray: Function) { const AssestList: Array = [] new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { - - for (let i = 0; i < _assetList.iterable.length; i++) { - if (_assetList.iterable[i].id == _id) { + for(let i = 0; i < _assetList.iterable.length; i++) { + if(_assetList.iterable[i].id == _id) { let _asset = _assetList.iterable[i]; From 87e6595d15a5b71b39d4c556634d918f26455270 Mon Sep 17 00:00:00 2001 From: koushikFusion Date: Wed, 29 May 2024 22:17:08 +0530 Subject: [PATCH 3/5] ui updated for update end-point --- src/app/App.tsx | 4 +- src/app/components/Asset/Asset.tsx | 13 ++++++- src/app/components/TextInput/TextInput.tsx | 44 +++++++++++----------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/app/App.tsx b/src/app/App.tsx index a0bc3f9..85188df 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -10,7 +10,7 @@ import { Indicator } from "./components/Indicator/Indicator"; import CopilotStreamController from "./controllers/copilotStreamController"; import "./global.css"; import WorkflowActivityList from "./components/WorkflowActivity"; -// import { UpdateAssetButton } from "./components/TextInput/TextInput"; +import { UpdateAssetButton } from "./components/TextInput/TextInput"; // types @@ -236,7 +236,7 @@ export function App(): React.JSX.Element {

Create a New Snippet

- {/* */} + diff --git a/src/app/components/Asset/Asset.tsx b/src/app/components/Asset/Asset.tsx index 283f78a..866aa07 100644 --- a/src/app/components/Asset/Asset.tsx +++ b/src/app/components/Asset/Asset.tsx @@ -97,8 +97,10 @@ export function updateAsset(_id: string, data: string, setArray: Function) { if(_assetList.iterable[i].id == _id) { let _asset = _assetList.iterable[i]; - - new Pieces.AssetApi().assetAssociateTag({ asset: _asset.id, tag: data }).then(() => { + console.log("_asset before updated",_asset) + new Pieces.AssetApi().assetAssociateTag({ asset: _asset.id, tag: data }) + .then((response) => { + console.log("response",response) console.log("Tag associated with asset successfully"); setArray([...AssestList]); }).catch(error => { @@ -106,6 +108,13 @@ export function updateAsset(_id: string, data: string, setArray: Function) { }); } } + for(let i = 0; i < _assetList.iterable.length; i++) { + if(_assetList.iterable[i].id == _id) { + + let _asset = _assetList.iterable[i]; + console.log("_asset after updated",_asset) + } + } }) } diff --git a/src/app/components/TextInput/TextInput.tsx b/src/app/components/TextInput/TextInput.tsx index c385ecc..afb6495 100644 --- a/src/app/components/TextInput/TextInput.tsx +++ b/src/app/components/TextInput/TextInput.tsx @@ -73,27 +73,27 @@ export function RenameAssetInput({ assetID }) { ); } -// export function UpdateAssetButton({ assetID, setArray }) { -// const [data, setData] = useState(""); -// const handleDataChange = (event) => { -// setData(event.target.value); -// }; +export function UpdateAssetButton({ assetID, setArray }) { + const [data, setData] = useState(""); + const handleDataChange = (event) => { + setData(event.target.value); + }; -// const editAsset = () => { -// updateAsset(assetID, data, setArray); -// }; + const editAsset = () => { + updateAsset(assetID, data, setArray); + }; -// return ( -// <> -// -// -// -// ); -// } + return ( + <> + + + + ); +} From cc41559b240d2f8b353ae68c4634cd906b9933fb Mon Sep 17 00:00:00 2001 From: koushikFusion Date: Wed, 29 May 2024 22:18:14 +0530 Subject: [PATCH 4/5] ui updated for update-api endpoint --- src/app/components/Asset/Asset.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/app/components/Asset/Asset.tsx b/src/app/components/Asset/Asset.tsx index 866aa07..d43c88d 100644 --- a/src/app/components/Asset/Asset.tsx +++ b/src/app/components/Asset/Asset.tsx @@ -97,10 +97,10 @@ export function updateAsset(_id: string, data: string, setArray: Function) { if(_assetList.iterable[i].id == _id) { let _asset = _assetList.iterable[i]; - console.log("_asset before updated",_asset) + new Pieces.AssetApi().assetAssociateTag({ asset: _asset.id, tag: data }) .then((response) => { - console.log("response",response) + console.log("Tag associated with asset successfully"); setArray([...AssestList]); }).catch(error => { @@ -108,13 +108,6 @@ export function updateAsset(_id: string, data: string, setArray: Function) { }); } } - for(let i = 0; i < _assetList.iterable.length; i++) { - if(_assetList.iterable[i].id == _id) { - - let _asset = _assetList.iterable[i]; - console.log("_asset after updated",_asset) - } - } }) } From 22652822a8342e596437aa95ea13fc58468d452a Mon Sep 17 00:00:00 2001 From: koushikFusion Date: Wed, 5 Jun 2024 20:05:03 +0530 Subject: [PATCH 5/5] Input validation issue resolve --- src/app/App.tsx | 2 +- src/app/components/Asset/Asset.tsx | 1 - src/app/components/TextInput/TextInput.tsx | 14 ++++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/app/App.tsx b/src/app/App.tsx index 85188df..3f39d50 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -235,7 +235,7 @@ export function App(): React.JSX.Element {

Create a New Snippet

- + diff --git a/src/app/components/Asset/Asset.tsx b/src/app/components/Asset/Asset.tsx index d43c88d..cc69815 100644 --- a/src/app/components/Asset/Asset.tsx +++ b/src/app/components/Asset/Asset.tsx @@ -101,7 +101,6 @@ export function updateAsset(_id: string, data: string, setArray: Function) { new Pieces.AssetApi().assetAssociateTag({ asset: _asset.id, tag: data }) .then((response) => { - console.log("Tag associated with asset successfully"); setArray([...AssestList]); }).catch(error => { console.error("Failed to associate tag with asset:", error); diff --git a/src/app/components/TextInput/TextInput.tsx b/src/app/components/TextInput/TextInput.tsx index afb6495..805ff98 100644 --- a/src/app/components/TextInput/TextInput.tsx +++ b/src/app/components/TextInput/TextInput.tsx @@ -2,13 +2,12 @@ import * as React from "react"; import { useState } from "react"; import { deleteAsset, renameAsset } from "../Asset/Asset"; import { CreateButton } from "../Button/Button"; -import {updateAsset} from "../Asset/Asset" +import { updateAsset } from "../Asset/Asset" import "./TextInput.css"; export function DataTextInput({ applicationData }) { const [name, setName] = useState(""); const [data, setData] = useState(""); - const handleDataChange = (event) => { setData(event.target.value); }; @@ -32,15 +31,15 @@ export function DataTextInput({ applicationData }) { className="textarea-data" onChange={handleDataChange} /> - + ); } -export function DeleteAssetButton({ assetID, selectedIndex ,setArray}) { +export function DeleteAssetButton({ assetID, selectedIndex, setArray }) { return ( <> - @@ -51,9 +50,10 @@ export function DeleteAssetButton({ assetID, selectedIndex ,setArray}) { export function RenameAssetInput({ assetID }) { const [name, setNameValue] = useState(""); - const handleNameChange = (event) => { + if (assetID !== "") { setNameValue(event.target.value); + } }; return ( @@ -76,7 +76,9 @@ export function RenameAssetInput({ assetID }) { export function UpdateAssetButton({ assetID, setArray }) { const [data, setData] = useState(""); const handleDataChange = (event) => { + if (assetID !== "") { setData(event.target.value); + } }; const editAsset = () => {