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..3f39d50 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 { } - + +
@@ -233,12 +235,12 @@ 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..cc69815 100644 --- a/src/app/components/Asset/Asset.tsx +++ b/src/app/components/Asset/Asset.tsx @@ -7,59 +7,59 @@ 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( { + 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) { - new Pieces.AssetsApi().assetsSnapshot({}).then(_assetList => { - for (let i = 0; i < _assetList.iterable.length; i++) { - if (_assetList.iterable[i].id == _id) { + let _asset = _assetList.iterable[i]; - let _asset = _assetList.iterable[i]; + _asset.name = _name; - _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) { + + let _asset = _assetList.iterable[i]; + + new Pieces.AssetApi().assetAssociateTag({ asset: _asset.id, tag: data }) + .then((response) => { + + 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..805ff98 100644 --- a/src/app/components/TextInput/TextInput.tsx +++ b/src/app/components/TextInput/TextInput.tsx @@ -2,12 +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 "./TextInput.css"; export function DataTextInput({ applicationData }) { const [name, setName] = useState(""); const [data, setData] = useState(""); - const handleDataChange = (event) => { setData(event.target.value); }; @@ -31,26 +31,29 @@ export function DataTextInput({ applicationData }) { className="textarea-data" onChange={handleDataChange} /> - + ); } -export function DeleteAssetButton({ assetID, selectedIndex ,setArray}) { +export function DeleteAssetButton({ assetID, selectedIndex, setArray }) { return ( <> - ); } + + export function RenameAssetInput({ assetID }) { const [name, setNameValue] = useState(""); - const handleNameChange = (event) => { + if (assetID !== "") { setNameValue(event.target.value); + } }; return ( @@ -70,4 +73,29 @@ export function RenameAssetInput({ assetID }) { ); } +export function UpdateAssetButton({ assetID, setArray }) { + const [data, setData] = useState(""); + const handleDataChange = (event) => { + if (assetID !== "") { + setData(event.target.value); + } + }; + const editAsset = () => { + updateAsset(assetID, data, setArray); + }; + + return ( + <> + + + + ); +}