Skip to content

Commit b46045a

Browse files
authored
feat: Worlds Storage component (#2928)
* fix: Add classnames dep * fix: (WIP) Add worlds storage component * fix: Format * fix: Add translations and cast from BigInt to Number * fix: Add component tests * fix: Only show 2 decimals * feat: use numbers instead of strings * fix: Import * fix: Use progress bar from decentraland ui
1 parent 264e97f commit b46045a

File tree

11 files changed

+111
-2
lines changed

11 files changed

+111
-2
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"apollo-link-http": "^1.5.17",
2828
"blob-to-buffer": "^1.2.9",
2929
"cids": "^0.7.2",
30+
"classnames": "^2.3.2",
3031
"connected-react-router": "^6.9.2",
3132
"date-fns": "^2.28.0",
3233
"dcl-catalyst-client": "^21.5.5",

src/components/WorldListPage_WorldsForEnsOwnersFeature/WorldListPage.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import LoggedInDetailPage from 'components/LoggedInDetailPage'
2424
import { NavigationTab } from 'components/Navigation/Navigation.types'
2525
import { Props, SortBy } from './WorldListPage.types'
2626
import NameTabs from './NameTabs'
27+
import WorldsStorage from './WorldsStorage'
2728
import './WorldListPage.css'
2829

2930
const EXPLORER_URL = config.get('EXPLORER_URL', '')
@@ -240,8 +241,19 @@ const WorldListPage: React.FC<Props> = props => {
240241
isLoading={isLoading}
241242
isPageFullscreen={true}
242243
>
243-
<h1>Worlds</h1>
244-
<NameTabs />
244+
{/** The following elements are just for show until the feature is complete, disregard the layout, just preview the components */}
245+
<Container>
246+
<h1>Worlds</h1>
247+
<NameTabs />
248+
<div
249+
style={{
250+
marginBottom: '1rem'
251+
}}
252+
>
253+
<WorldsStorage maxBytes={100000000} currentBytes={75000000} />
254+
</div>
255+
</Container>
256+
{/** Old ens list which will be removed or replaced with the new worlds for ens owners feature */}
245257
{ensList.length > 0 ? renderEnsList() : renderEmptyPage()}
246258
</LoggedInDetailPage>
247259
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.worldsStorage {
2+
background-color: var(--dark-two);
3+
border-radius: 10px;
4+
padding: 22px;
5+
}
6+
7+
.spaceContainer {
8+
display: flex;
9+
justify-content: space-between;
10+
margin-bottom: 1rem;
11+
}
12+
13+
.currentMbs {
14+
font-size: 1.5rem;
15+
}
16+
17+
.bar {
18+
margin-bottom: 1rem !important;
19+
background-color: #a09ba8 !important;
20+
}
21+
22+
.bar:global(.ui.progress .bar) {
23+
background-color: #ff2d55;
24+
}
25+
26+
.viewDetails {
27+
text-align: right;
28+
cursor: pointer;
29+
text-decoration: underline;
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { render, screen } from '@testing-library/react'
2+
import WorldsStorage, { CURRENT_MBS_TEST_ID, PROGRESS_TEST_ID } from './WorldsStorage'
3+
4+
describe('when rendering the worlds storage component', () => {
5+
describe('when the provided current bytes is 50550000 and the max bytes is 100000000', () => {
6+
beforeEach(() => {
7+
render(<WorldsStorage currentBytes={50550000} maxBytes={100000000} />)
8+
})
9+
10+
it('should render 50.55/100.00mb', () => {
11+
expect(screen.getByTestId(CURRENT_MBS_TEST_ID).textContent).toEqual('50.55 / 100.00 mb')
12+
})
13+
14+
it('should render the storage front bar with 50%', () => {
15+
expect(screen.getByTestId(PROGRESS_TEST_ID).children[0].getAttribute('style')).toEqual('width: 50%;')
16+
})
17+
})
18+
})
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react'
2+
import { Progress } from 'decentraland-ui'
3+
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
4+
import { Props } from './WorldsStorage.types'
5+
import styles from './WorldsStorage.module.css'
6+
7+
export const CURRENT_MBS_TEST_ID = 'worlds-storage-current-mbs'
8+
export const PROGRESS_TEST_ID = 'worlds-storage-bar-front'
9+
10+
const WorldsStorage = ({ maxBytes, currentBytes }: Props) => {
11+
const maxMbs = maxBytes / 1000000
12+
const currentMbs = currentBytes / 1000000
13+
const usedPercentage = (currentMbs * 100) / maxMbs
14+
15+
return (
16+
<div className={styles.worldsStorage}>
17+
<div className={styles.spaceContainer}>
18+
<span>{t('worlds_list_page.worlds_storage.space_used')}</span>
19+
<div data-testid={CURRENT_MBS_TEST_ID}>
20+
<span className={styles.currentMbs}>{currentMbs.toFixed(2)}</span> / {maxMbs.toFixed(2)} mb
21+
</div>
22+
</div>
23+
<Progress data-testid={PROGRESS_TEST_ID} percent={Math.trunc(usedPercentage)} className={styles.bar} size="small" />
24+
<div className={styles.viewDetails}>{t('worlds_list_page.worlds_storage.view_details')}</div>
25+
</div>
26+
)
27+
}
28+
29+
export default React.memo(WorldsStorage)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type Props = {
2+
maxBytes: number
3+
currentBytes: number
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import WorldStorage from './WorldsStorage'
2+
export default WorldStorage

src/modules/translation/languages/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@
611611
"name_tabs": {
612612
"dcl_names": "Decentraland names",
613613
"ens_names": "ENS names"
614+
},
615+
"worlds_storage": {
616+
"space_used": "Space used",
617+
"view_details": "view details"
614618
}
615619
},
616620
"error_page": {

src/modules/translation/languages/es.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@
613613
"name_tabs": {
614614
"dcl_names": "Nombres de Decentraland",
615615
"ens_names": "Nombre de ENS"
616+
},
617+
"worlds_storage": {
618+
"space_used": "Espacio utilizado",
619+
"view_details": "ver detalles"
616620
}
617621
},
618622
"error_page": {

0 commit comments

Comments
 (0)