Skip to content

Commit c5dbe72

Browse files
authored
Merge pull request #139 from VishalPawar1010/#78-Show-Snippet-Preview-When-Selected
feat: Added snippet preview
2 parents ba258c1 + eafcf21 commit c5dbe72

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"prettier": "^3.3.2",
3636
"rimraf": "^3.0.2",
3737
"ts-jest": "^29.1.1",
38-
"typescript": "^4.9.5"
38+
"typescript": "^4.9.5",
39+
"react-icons": "5.2.1"
3940
},
4041
"browserslist": {
4142
"production": [

src/app/App.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {connect} from './utils/Connect'
99
import { Indicator } from "./components/Indicator/Indicator";
1010
import "./global.css";
1111
import WorkflowActivityList from "./components/WorkflowActivity";
12+
import Modal from "./components/Asset/Modal";
13+
import { AiFillEye } from 'react-icons/ai';
14+
1215
import { OSApi } from "@pieces.app/pieces-os-client";
1316
import { config } from "../platform.config";
1417
const osApi = new OSApi(); // Create an instance of the OSApi
@@ -42,6 +45,19 @@ export function App(): React.JSX.Element {
4245
const [array, setArray] = useState<Array<LocalAsset>>([]);
4346
const [selectedIndex, setSelectedIndex] = useState<number>(-1);
4447
const [error, setError] = useState(null);
48+
const [previewData, setPreviewData] = useState(null);
49+
const [showModal, setShowModal] = useState(false);
50+
51+
const handlePreview = async (snippetId:string) => {
52+
try {
53+
const asset = await new Pieces.AssetApi(config).assetSnapshot({ asset: snippetId });
54+
console.log('asset ===', asset)
55+
setPreviewData(asset);
56+
setShowModal(true);
57+
} catch (error) {
58+
console.error(error);
59+
}
60+
};
4561

4662
const [userName, setUserName] = useState(null);
4763

@@ -270,8 +286,14 @@ export function App(): React.JSX.Element {
270286
<div>
271287
<h3>{item.name}</h3>
272288
<div className="snippet-details">
273-
<p>{item.id}</p>
289+
{/* <p>{item.id}</p> */}
274290
<p>{item.classification}</p>
291+
<button onClick={() => handlePreview(item.id)}><AiFillEye title="Preview"/></button>
292+
{showModal && (
293+
<Modal asset={previewData} onClose={() => setShowModal(false)} />
294+
)}
295+
<div>
296+
</div>
275297
</div>
276298
</div>
277299
</div>
@@ -295,9 +317,9 @@ export function App(): React.JSX.Element {
295317
</div>
296318

297319
{/* this is the copilot container. the copilot logic is inside the /components/Copilot.tsx */}
298-
<div className="copilot-container">
299-
<CopilotChat />
300-
</div>
320+
321+
<CopilotChat />
322+
301323
</div>
302324
</>
303325
);

src/app/components/Asset/Modal.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from 'react';
2+
3+
const Modal = ({ onClose, asset }) => {
4+
if (!asset) return null;
5+
6+
return (
7+
<div style={{ zIndex:1000, position: 'fixed', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: 'rgba(0,0,0,0.5)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
8+
<div style={{ zIndex:1005, padding: 20, background: 'white', borderRadius: 5, width: '50%', boxShadow: '0 4px 6px rgba(0,0,0,0.1)' }}>
9+
<h2>Snippet Details</h2>
10+
<p>ID: {asset.id}</p>
11+
<p>Name: {asset.name}</p>
12+
<p>Mechanism: {asset?.mechanism}</p>
13+
<p>Preview schema semantic: {asset.preview?.schema?.semantic}</p>
14+
<button onClick={onClose} style={{ marginTop: 20 }}>Close</button>
15+
</div>
16+
</div>
17+
);
18+
};
19+
20+
export default Modal;

src/app/components/Copilot/Copilot.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
/* Container styles */
2+
.copilot-container {
3+
border: 2px solid black;
4+
background-color: #0e1111;
5+
height: 600px;
6+
padding: 20px;
7+
border-radius: 9px;
8+
display: flex;
9+
box-shadow: -4px 4px 5px rgba(0, 0, 0, 0.2);
10+
margin-top: 20px;
11+
}
12+
213
.container {
314
width: -webkit-fill-available;
415
}

src/app/components/Copilot/Copilot.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export function CopilotChat(): React.JSX.Element {
126126
};
127127

128128
return (
129+
<div className="copilot-container">
129130
<div className="container">
130131
<div className="header">
131132
<div>
@@ -155,5 +156,6 @@ export function CopilotChat(): React.JSX.Element {
155156
</div>
156157
</div>
157158
</div>
159+
</div>
158160
);
159161
}

src/app/global.css

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,7 @@ html {
203203
flex-direction: column;
204204
}
205205

206-
.copilot-container {
207-
border: 2px solid black;
208-
background-color: #0e1111;
209-
height: 600px;
210-
padding: 20px;
211-
border-radius: 9px;
212-
display: flex;
213-
box-shadow: -4px 4px 5px rgba(0, 0, 0, 0.2);
214-
margin-top: 20px;
215-
}
206+
216207

217208

218209
/* Common styles for the response formatting body */

0 commit comments

Comments
 (0)