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

Paging for objects #172

Merged
merged 3 commits into from
Mar 12, 2024
Merged
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
18 changes: 18 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,24 @@ label.panel-block:hover {
margin: 5px 15px 0 0;
}

.pagination {
margin: 1rem 0 0;
justify-content: center;
}

.pagination-previous,
.pagination-next {
order: unset;
cursor: pointer;
min-width: 2em;
font-size: 12px;
margin: 0;
}

.pagination-text {
margin: 0 0.75rem;
}

.footer {
background-color: #f0f5f6;
padding: 40px 20px;
Expand Down
1 change: 1 addition & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export const App = () => {
if (e.message) {
setError({ active: true, type: [], text: e.message });
} else {
onModal();
onPopup('success', 'Container was deleted successfully');
setLoadContainers(true);
}
Expand Down
69 changes: 48 additions & 21 deletions src/Components/ContainerItem/ContainerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export default function ContainerItem({
BearerSignatureHeader,
BearerSignatureKeyHeader,
}) {
const ObjectsPerPage = 40;
const [isOpen, setIsOpen] = useState(false);
const [pagination, setPagination] = useState({
page: 0,
objects: 0,
});
const [objects, setObjects] = useState(null);
const [isLoadingObjects, setLoadingObjects] = useState(false);
const [isLoadingEACL, setLoadingEACL] = useState(false);
Expand Down Expand Up @@ -81,9 +86,10 @@ export default function ContainerItem({
}
}, [walletData]); // eslint-disable-line react-hooks/exhaustive-deps

const onGetObjects = (containerId) => {
const onGetObjects = (containerId, pageTemp = pagination.page) => {
setPagination({ ...pagination, page: pageTemp});
setLoadingObjects(true);
api('POST', `/objects/${containerId}/search?walletConnect=true`, {
api('POST', `/objects/${containerId}/search?walletConnect=true&limit=${ObjectsPerPage}&offset=${pageTemp * ObjectsPerPage}`, {
"filters": [],
}, {
[ContentTypeHeader]: "application/json",
Expand All @@ -96,6 +102,7 @@ export default function ContainerItem({
if (e.message) {
onPopup('failed', e.message);
} else {
setPagination({ objects: e.objects ? e.objects.length : 0, page: pageTemp});
setObjects(e.objects ? formatForTreeView(e.objects) : []);
}
});
Expand Down Expand Up @@ -285,20 +292,34 @@ export default function ContainerItem({
} else if (activePanel === 'objects') {
setActivePanel('');
} else {
onGetObjects(containerItem.containerId);
onGetObjects(containerItem.containerId, 0);
setActivePanel('objects');
}
}}
style={{ cursor: 'pointer', display: 'flex' }}
style={{ cursor: 'pointer', display: 'flex', justifyContent: 'space-between' }}
>
<img
src={activePanel === 'objects' ? '/img/icons/chevron_down.svg' : '/img/icons/chevron_right.svg'}
style={{ marginRight: 10 }}
width={22}
height={22}
alt="chevron"
/>
Objects
<div style={{ display: 'flex', alignItems: 'center' }}>
<img
src={activePanel === 'objects' ? '/img/icons/chevron_down.svg' : '/img/icons/chevron_right.svg'}
style={{ marginRight: 10 }}
width={22}
height={22}
alt="chevron"
/>
Objects
</div>
{activePanel === 'objects' && !isLoadingObjects && (
<Button
size="small"
color="primary"
onClick={(e) => {
onModal('createObject', { containerId: containerItem.containerId })
e.stopPropagation();
}}
>
New object
</Button>
)}
</Heading>
{activePanel === 'objects' && (
<>
Expand All @@ -320,6 +341,21 @@ export default function ContainerItem({
BearerSignatureHeader={BearerSignatureHeader}
BearerSignatureKeyHeader={BearerSignatureKeyHeader}
/>
{!(pagination.page === 0 && pagination.objects === 0) && (
<div className="pagination">
<div
className="pagination-previous"
onClick={() => onGetObjects(containerItem.containerId, pagination.page - 1)}
style={pagination.page === 0 ? { pointerEvents: 'none', borderColor: '#e9e9e9' } : {}}
>{`<`}</div>
<div className="pagination-text">{pagination.page + 1}</div>
<div
className="pagination-next"
onClick={() => onGetObjects(containerItem.containerId, pagination.page + 1)}
style={pagination.objects < ObjectsPerPage ? { pointerEvents: 'none', borderColor: '#e9e9e9' } : {}}
>{`>`}</div>
</div>
)}
</>
) : (
<img
Expand All @@ -330,15 +366,6 @@ export default function ContainerItem({
alt="loader"
/>
)}
{!isLoadingObjects && (
<Button
color="primary"
onClick={() => onModal('createObject', { containerId: containerItem.containerId })}
style={{ display: 'flex', margin: '20px auto 0' }}
>
New object
</Button>
)}
</>
)}
</Section>
Expand Down
4 changes: 4 additions & 0 deletions src/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ const Profile = ({
onModal('failed', 'Session expired, re-login to continue');
}

if (walletData.name === 'CoZ Wallet Prototype') {
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
signers[0].scopes = 1;
}

response = await wcSdk.testInvoke({ invocations, signers }).catch((err) => handleError(err, 'balance'));
}
setIsLoadingNeoBalance(false);
Expand Down
Loading