Skip to content

update endpoint implemented #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 5 additions & 3 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -225,20 +226,21 @@ export function App(): React.JSX.Element {
}
</div>
</div>



<div className="snippet-grid-container">
<form onSubmit={handleSearch}>
<input type="text" className="search-input-style" name="search-term" />
<button className="search-button-style" type='submit'>Search</button>
</form>
<h3 className="snippets-heading-2">Create a New Snippet</h3>
<DataTextInput applicationData={appData}/>
<RenameAssetInput assetID={((selectedIndex < array.length && selectedIndex!=-1) ? array[selectedIndex].id : "")}/>
<RenameAssetInput assetID={((selectedIndex < array.length && selectedIndex!=-1) ? array[selectedIndex].id : "")}/>
<UpdateAssetButton assetID={((selectedIndex < array.length && selectedIndex!=-1) ? array[selectedIndex].id : "")} setArray={setArray} />
</div>
</div>
</div>

{/* this is the copilot container. the copilot logic is inside the /components/Copilot.tsx */}
<div className="copilot-container">
<CopilotChat />
</div>
Expand Down
124 changes: 75 additions & 49 deletions src/app/components/Asset/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,106 @@ 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<LocalAsset> = [];
const newAssetsList: Array<LocalAsset> = [];

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
// NameInput + DataInput fields.
//
// 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<LocalAsset> = []

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);
})
}
}
})
}
38 changes: 33 additions & 5 deletions src/app/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -31,26 +31,29 @@ export function DataTextInput({ applicationData }) {
className="textarea-data"
onChange={handleDataChange}
/>
<CreateButton applicationData={applicationData} data={data} name={name}/>
<CreateButton applicationData={applicationData} data={data} name={name} />
</>
);
}

export function DeleteAssetButton({ assetID, selectedIndex ,setArray}) {
export function DeleteAssetButton({ assetID, selectedIndex, setArray }) {
return (
<>
<button className="delete-button" onClick={() => deleteAsset(assetID,setArray)}>
<button className="delete-button" onClick={() => deleteAsset(assetID, setArray)}>
DELETE
</button>
</>
);
}



export function RenameAssetInput({ assetID }) {
const [name, setNameValue] = useState("");

const handleNameChange = (event) => {
if (assetID !== "") {
setNameValue(event.target.value);
}
};

return (
Expand All @@ -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 (
<>
<input
placeholder="Add your code/text content into this box"
value={data}
className="textarea-data"
onChange={handleDataChange}
/>
<button className="rename-button" onClick={editAsset}>
Edit Selected Snippet
</button>
</>
);
}