|
| 1 | +// This file is part of Invenio-RDM-Records |
| 2 | +// Copyright (C) 2026 CERN. |
| 3 | +// |
| 4 | +// Invenio-RDM-Records is free software; you can redistribute it and/or modify it |
| 5 | +// under the terms of the MIT License; see LICENSE file for more details. |
| 6 | + |
| 7 | +import React from "react"; |
| 8 | +import { |
| 9 | + Header, |
| 10 | + Grid, |
| 11 | + Label, |
| 12 | + Progress, |
| 13 | + Table, |
| 14 | + Container, |
| 15 | + Message, |
| 16 | +} from "semantic-ui-react"; |
| 17 | +import PropTypes from "prop-types"; |
| 18 | +import { i18next } from "@translations/invenio_rdm_records/i18next"; |
| 19 | + |
| 20 | +export default function StorageOverview({ storage }) { |
| 21 | + const statusColor = { |
| 22 | + Draft: "warning", |
| 23 | + Published: "positive", |
| 24 | + }; |
| 25 | + |
| 26 | + return ( |
| 27 | + <Container aria-label={i18next.t("Storage")} className="storage-overview"> |
| 28 | + <Header as="h5" className="mb-2"> |
| 29 | + <strong>{i18next.t("Quota overview")}</strong> |
| 30 | + </Header> |
| 31 | + <p className="text-muted mb-4"> |
| 32 | + {i18next.t( |
| 33 | + "You can now manage your record storage by assigning additional quota as needed." |
| 34 | + )}{" "} |
| 35 | + <a href="./">{i18next.t("Find out more.")}</a>{" "} |
| 36 | + {/* Need to link to help guide.*/} |
| 37 | + </p> |
| 38 | + |
| 39 | + <Grid doubling columns={3} stackable className="rel-mb-1"> |
| 40 | + <Grid.Column> |
| 41 | + <Message |
| 42 | + icon="hdd" |
| 43 | + size="tiny" |
| 44 | + header={<Header as="h4">{storage.default_quota} GB</Header>} |
| 45 | + content={i18next.t("Default quota per record")} |
| 46 | + className="rel-p-2" |
| 47 | + /> |
| 48 | + </Grid.Column> |
| 49 | + |
| 50 | + <Grid.Column> |
| 51 | + <Message |
| 52 | + icon="server" |
| 53 | + size="tiny" |
| 54 | + positive={storage.additional_available_quota > 5} |
| 55 | + warning={storage.additional_available_quota < 5} |
| 56 | + header={ |
| 57 | + <Header as="h4">{storage.additional_available_quota} GB</Header> |
| 58 | + } |
| 59 | + content={i18next.t("Available of {{total}} GB allowance", { |
| 60 | + total: storage.total_allowed_quota, |
| 61 | + })} |
| 62 | + className="rel-p-2" |
| 63 | + /> |
| 64 | + </Grid.Column> |
| 65 | + |
| 66 | + <Grid.Column> |
| 67 | + <Message |
| 68 | + icon="sitemap" |
| 69 | + size="tiny" |
| 70 | + info |
| 71 | + header={<Header as="h4">{storage.additional_granted_quota} GB</Header>} |
| 72 | + content={i18next.t("Quota granted across {{count}} records", { |
| 73 | + count: storage.records.length, |
| 74 | + })} |
| 75 | + className="rel-p-2" |
| 76 | + /> |
| 77 | + </Grid.Column> |
| 78 | + </Grid> |
| 79 | + |
| 80 | + <div className="mb-4"> |
| 81 | + <Grid> |
| 82 | + <Grid.Row columns={2}> |
| 83 | + <Grid.Column textAlign="left"> |
| 84 | + <Label className="medium rel-mb-1">0 GB</Label> |
| 85 | + </Grid.Column> |
| 86 | + <Grid.Column textAlign="right"> |
| 87 | + <Label className="medium rel-mb-1"> |
| 88 | + {storage.total_allowed_quota} GB |
| 89 | + </Label> |
| 90 | + </Grid.Column> |
| 91 | + </Grid.Row> |
| 92 | + </Grid> |
| 93 | + <Progress |
| 94 | + value={storage.additional_used_quota} |
| 95 | + total={storage.total_allowed_quota} |
| 96 | + progress="value" |
| 97 | + className="primary" |
| 98 | + /> |
| 99 | + </div> |
| 100 | + |
| 101 | + {/* Storage Allocations Table */} |
| 102 | + <Header as="h5" className="mb-2"> |
| 103 | + <strong>{i18next.t("Allocated storage")}</strong> |
| 104 | + </Header> |
| 105 | + {storage.records.length > 0 ? ( |
| 106 | + <Table size="small" padded> |
| 107 | + <Table.Header> |
| 108 | + <Table.Row> |
| 109 | + <Table.HeaderCell width={7}>{i18next.t("Record")}</Table.HeaderCell> |
| 110 | + <Table.HeaderCell width={2}> |
| 111 | + {i18next.t("Additional quota")} |
| 112 | + </Table.HeaderCell> |
| 113 | + <Table.HeaderCell width={4}>{i18next.t("Usage")}</Table.HeaderCell> |
| 114 | + <Table.HeaderCell width={2}>{i18next.t("Date")}</Table.HeaderCell> |
| 115 | + <Table.HeaderCell width={1}>{i18next.t("Status")}</Table.HeaderCell> |
| 116 | + </Table.Row> |
| 117 | + </Table.Header> |
| 118 | + |
| 119 | + <Table.Body className="storage-overview-table"> |
| 120 | + {storage.records.map((record, idx) => { |
| 121 | + const percent = |
| 122 | + record.total > 0 ? Math.round((record.used / record.total) * 100) : 0; |
| 123 | + |
| 124 | + return ( |
| 125 | + <Table.Row key={idx}> |
| 126 | + <Table.Cell> |
| 127 | + <a href={record.url}>{record.title}</a> |
| 128 | + <p className="text-muted">{record.url}</p> |
| 129 | + </Table.Cell> |
| 130 | + |
| 131 | + <Table.Cell> |
| 132 | + <strong>+{record.additional_quota} GB</strong> |
| 133 | + <div className="ui tiny text-muted"> |
| 134 | + ( |
| 135 | + {i18next.t("{{total}} GB total", { |
| 136 | + total: record.total, |
| 137 | + })} |
| 138 | + ) |
| 139 | + </div> |
| 140 | + </Table.Cell> |
| 141 | + |
| 142 | + <Table.Cell> |
| 143 | + <Grid verticalAlign="middle" columns="equal"> |
| 144 | + <Grid.Column width={9}> |
| 145 | + <Progress |
| 146 | + value={record.used} |
| 147 | + total={record.total} |
| 148 | + className="m-0 primary" |
| 149 | + size="tiny" |
| 150 | + /> |
| 151 | + </Grid.Column> |
| 152 | + <Grid.Column width={7} textAlign="left"> |
| 153 | + <p className="text-muted"> |
| 154 | + {record.used} / {record.total} GB |
| 155 | + </p> |
| 156 | + </Grid.Column> |
| 157 | + </Grid> |
| 158 | + <p className="text-muted"> |
| 159 | + {percent}% {i18next.t("used")} |
| 160 | + </p> |
| 161 | + </Table.Cell> |
| 162 | + |
| 163 | + <Table.Cell> |
| 164 | + <p className="text-muted">{record.date}</p> |
| 165 | + </Table.Cell> |
| 166 | + |
| 167 | + <Table.Cell> |
| 168 | + <Label size="tiny" color={statusColor[record.status] || "grey"}> |
| 169 | + {i18next.t(record.status)} |
| 170 | + </Label> |
| 171 | + </Table.Cell> |
| 172 | + </Table.Row> |
| 173 | + ); |
| 174 | + })} |
| 175 | + </Table.Body> |
| 176 | + </Table> |
| 177 | + ) : ( |
| 178 | + <Message icon size="small"> |
| 179 | + <i className="archive icon" /> |
| 180 | + <Message.Content> |
| 181 | + <Message.Header>{i18next.t("No allocated storage")}</Message.Header> |
| 182 | + <p> |
| 183 | + {i18next.t("No records have been granted any additional quotas yet.")} |
| 184 | + </p> |
| 185 | + </Message.Content> |
| 186 | + </Message> |
| 187 | + )} |
| 188 | + </Container> |
| 189 | + ); |
| 190 | +} |
| 191 | + |
| 192 | +StorageOverview.propTypes = { |
| 193 | + storage: PropTypes.shape({ |
| 194 | + default_quota: PropTypes.number.isRequired, |
| 195 | + total_allowed_quota: PropTypes.number.isRequired, |
| 196 | + additional_granted_quota: PropTypes.number.isRequired, |
| 197 | + additional_available_quota: PropTypes.number.isRequired, |
| 198 | + additional_used_quota: PropTypes.number.isRequired, |
| 199 | + records: PropTypes.arrayOf( |
| 200 | + PropTypes.shape({ |
| 201 | + title: PropTypes.string.isRequired, |
| 202 | + url: PropTypes.string.isRequired, |
| 203 | + additional_quota: PropTypes.number.isRequired, |
| 204 | + total: PropTypes.number.isRequired, |
| 205 | + used: PropTypes.number.isRequired, |
| 206 | + date: PropTypes.string.isRequired, |
| 207 | + status: PropTypes.string.isRequired, |
| 208 | + }) |
| 209 | + ), |
| 210 | + }).isRequired, |
| 211 | +}; |
0 commit comments