Skip to content
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

feat: Add data panel to display object related data fetched via Cloud Function #2584

Merged
merged 46 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0c4acab
initial commit for aggreation side panel
vardhan0604 Jul 20, 2024
16b8519
updates
vardhan0604 Jul 28, 2024
26bb6c8
Merge branch 'alpha' of https://github.com/parse-community/parse-dash…
vardhan0604 Jul 28, 2024
c32afca
Merge branch 'parse-community:alpha' into 2495
vardhan0604 Jul 28, 2024
4f92208
Merge branch '2495' of https://github.com/vardhan0604/parse-dashboard…
vardhan0604 Jul 28, 2024
152e22b
fix lint
vardhan0604 Jul 28, 2024
775f98e
fixed max resize constraint on the side panel
vardhan0604 Jul 28, 2024
59e01a8
fixed resize handler
vardhan0604 Jul 29, 2024
a093048
fixed resize handler bug
vardhan0604 Jul 29, 2024
7cc202c
fix side panel overflow
vardhan0604 Jul 29, 2024
9301db6
Merge branch 'alpha' into 2495
mtrezza Aug 11, 2024
082bdd5
Merge branch 'alpha' of https://github.com/parse-community/parse-dash…
vardhan0604 Aug 12, 2024
0889527
fixing issues
vardhan0604 Aug 15, 2024
b9ca3fc
Merge branch '2495' of https://github.com/vardhan0604/parse-dashboard…
vardhan0604 Aug 15, 2024
5d714aa
fixing linting issues
vardhan0604 Aug 15, 2024
1f6b36c
fixing get
vardhan0604 Aug 15, 2024
4ec1c68
removed unwanted changes
vardhan0604 Aug 15, 2024
b07bf28
update react-draggable and react-resizable version
vardhan0604 Aug 16, 2024
70b4353
fix issues
vardhan0604 Aug 24, 2024
26e4d95
add loading feature
vardhan0604 Aug 26, 2024
5c3bcee
Merge branch 'alpha' into 2495
mtrezza Sep 2, 2024
d153425
update
vardhan0604 Sep 3, 2024
34037b1
Merge branch 'alpha' of https://github.com/parse-community/parse-dash…
vardhan0604 Sep 3, 2024
4ba8c2f
Merge branch '2495' of https://github.com/vardhan0604/parse-dashboard…
vardhan0604 Sep 3, 2024
35fdbb7
update
vardhan0604 Sep 6, 2024
20e4135
Update src/dashboard/Data/Browser/Browser.react.js
vardhan0604 Sep 7, 2024
8c4e68f
fixed issues
vardhan0604 Sep 11, 2024
081434d
Merge branch '2495' of https://github.com/vardhan0604/parse-dashboard…
vardhan0604 Sep 11, 2024
2322b5d
Merge branch 'alpha' into 2495
mtrezza Sep 15, 2024
1bd146f
fixed bugs
vardhan0604 Sep 18, 2024
1d4dcd2
Merge branch '2495' of https://github.com/vardhan0604/parse-dashboard…
vardhan0604 Sep 18, 2024
13e8e26
fix lint
vardhan0604 Sep 18, 2024
bde2c47
Fixed all required bugs
vardhan0604 Sep 23, 2024
f7fe82b
fix lint
vardhan0604 Sep 23, 2024
3d87049
Merge branch 'alpha' into 2495
mtrezza Sep 26, 2024
db8eff2
shorten panel text
mtrezza Oct 4, 2024
5a614bd
add panel shadow
mtrezza Oct 4, 2024
ac64604
soften panel shadow
mtrezza Oct 4, 2024
9bd827e
minor style adjustments
mtrezza Oct 4, 2024
a498be9
add background color
mtrezza Oct 4, 2024
87881d5
prevent sidebar selection
mtrezza Oct 4, 2024
f6f8990
min panel width 100
mtrezza Oct 4, 2024
ffc683b
button style
mtrezza Oct 4, 2024
e91ea1b
Merge branch 'alpha' of https://github.com/parse-community/parse-dash…
vardhan0604 Oct 5, 2024
28d6349
fix reorder bug
vardhan0604 Oct 5, 2024
32967a9
Merge branch '2495' of https://github.com/vardhan0604/parse-dashboard…
vardhan0604 Oct 5, 2024
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
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
"react-dnd": "10.0.2",
"react-dnd-html5-backend": "10.0.2",
"react-dom": "16.14.0",
"react-draggable": "4.4.6",
"react-helmet": "6.1.0",
"react-json-view": "1.21.3",
"react-popper-tooltip": "4.4.2",
"react-resizable": "3.0.5",
"react-router-dom": "6.4.1",
"regenerator-runtime": "0.13.11"
},
Expand Down
84 changes: 84 additions & 0 deletions src/components/AggregationPanel/AggregationPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import LoaderDots from 'components/LoaderDots/LoaderDots.react';
import React, { useEffect, useMemo } from 'react';
import styles from './AggregationPanel.scss';
import {
AudioElement,
ButtonElement,
ImageElement,
KeyValueElement,
TableElement,
TextElement,
VideoElement,
} from './AggregationPanelComponents';

const AggregationPanel = ({
data,
isLoadingCloudFunction,
showAggregatedData,
setErrorAggregatedData,
errorAggregatedData,
showNote,
setSelectedObjectId,
selectedObjectId
}) => {

useEffect(() => {
if (Object.keys(errorAggregatedData).length !== 0) {
setSelectedObjectId(null);
setErrorAggregatedData({});
}
}, [errorAggregatedData, setSelectedObjectId, setErrorAggregatedData]);

const isLoading = useMemo(() =>
selectedObjectId && isLoadingCloudFunction && showAggregatedData,
[selectedObjectId, isLoadingCloudFunction, showAggregatedData]
);

const shouldShowAggregatedData = useMemo(() =>
selectedObjectId && showAggregatedData && Object.keys(data).length !== 0 && Object.keys(errorAggregatedData).length === 0, [selectedObjectId, showAggregatedData, data, errorAggregatedData]
);

return (
<>
{isLoading ? (
<div className={styles.center}>
<LoaderDots />
</div>
) : shouldShowAggregatedData ? (
data.panel.segments.map((segment, index) => (
<div key={index}>
<h2 className={styles.heading}>{segment.title}</h2>
<div className={styles.segmentItems}>
{segment.items.map((item, idx) => {
switch (item.type) {
case 'text':
return <TextElement key={idx} text={item.text} />;
case 'keyValue':
return <KeyValueElement key={idx} item={item} />;
case 'table':
return <TableElement key={idx} columns={item.columns} rows={item.rows} />;
case 'image':
return <ImageElement key={idx} url={item.url} />;
case 'video':
return <VideoElement key={idx} url={item.url} />;
case 'audio':
return <AudioElement key={idx} url={item.url} />;
case 'button':
return <ButtonElement key={idx} item={item} showNote={showNote} />;
default:
return null;
}
})}
</div>
</div>
))
) : (
<div className={styles.loading}>
No object selected.
</div>
)}
</>
);
};

export default AggregationPanel;
99 changes: 99 additions & 0 deletions src/components/AggregationPanel/AggregationPanel.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
@import 'stylesheets/globals.scss';

.heading {
font-size: 14px;
margin-top: 0;
padding: 8px;
padding-left: 10px;
background-color: $blue;
color: $white;
}

.segmentItems {
font-size: 14px;
padding-left: 10px;
padding-right: 10px;
padding-top: 6px;
display: flex;
flex-direction: column;
border-left: 1px solid #e3e3ea;
gap: 10px;
}

.keyValue {
font-size: 14px;
display: flex;
gap: 10px;
}

.video {
width: 100%;
height: 100%;
}

.image {
width: 100%;
height: 100%;
}

.audio {
width: 100%;
}

.segmentItems table,
.segmentItems th,
.segmentItems td {
font-size: 14px;
border: 1px solid #ddd;
}

.segmentItems th,
.segmentItems td {
padding: 4px;
text-align: left;
}

.buttonContainer {
display: flex;
justify-content: center;
align-items: center;
}

.button {
width: auto;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
margin-bottom: 15px;
background-color: $blue;
padding: 3px 13px;
border: none;
color: $white;
line-height: 28px;
outline: 0;
text-decoration: none;
text-align: center;
border-radius: 5px;
font-size: 14px;
&:hover,
&:focus {
background-color: $darkBlue;
}
}

.loading{
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}

.center {
position: absolute;
text-align: center;
top: 50%;
left: 50%;
@include transform(translate(-50%, -50%));
}
97 changes: 97 additions & 0 deletions src/components/AggregationPanel/AggregationPanelComponents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from 'react';
import styles from './AggregationPanel.scss';

// Text Element Component
export const TextElement = ({ text }) => (
<div className="text-element">
<p>{text}</p>
</div>
);

// Key-Value Element Component
export const KeyValueElement = ({ item }) => (
<div className={styles.keyValue}>
{item.key}:
{item.url ? <a href={item.url} target="_blank">{item.value}</a> : <span>{item.value}</span>}
</div>
);

// Table Element Component
export const TableElement = ({ columns, rows }) => (
<div className="table-element">
<table>
<thead>
<tr>
{columns.map((column, idx) => (
<th key={idx}>{column.name}</th>
))}
</tr>
</thead>
<tbody>
{rows.map((row, idx) => (
<tr key={idx}>
{columns.map((column, colIdx) => (
<td key={colIdx}>{row[column.name]}</td>
))}
</tr>
))}
</tbody>
</table>
</div>
);

// Image Element Component
export const ImageElement = ({ url }) => (
<div className="image-element">
<a href={url} target="_blank" rel="noopener noreferrer">
<img src={url} alt="Image" className={styles.image} />
</a>
</div>
);

// Video Element Component
export const VideoElement = ({ url }) => (
<div className="video-element">
<video controls className={styles.video}>
<source src={url} type="video/mp4" />
Your browser does not support the video tag.
</video>
</div>
);

// Audio Element Component
export const AudioElement = ({ url }) => (
<div className="audio-element">
<audio controls className={styles.audio}>
<source src={url} type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
</div>
);

// Button Element Component
export const ButtonElement = ({ item, showNote }) => {
const handleClick = () => {
fetch(item.action.url, {
method: item.action.method,
headers: item.action.headers,
body: JSON.stringify(item.action.body),
})
.then(response => response.json())
.then(data => {
const formattedData = JSON.stringify(data, null, 2);
showNote(`${formattedData}`,false)
})
.catch(error => {
showNote(`${error}`,true)
});
};

return (
<div className={styles.buttonContainer}>
<button onClick={handleClick} className={styles.button}>
{item.text}
</button>
</div>
);
};
Loading
Loading