Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | 1x 1x 1x 1x | import React from "react"; import { Chip, Grid, List, Typography } from "@mui/material"; import CheckCircleIcon from "@mui/icons-material/CheckCircle"; import ErrorIcon from "@mui/icons-material/Error"; import AutorenewIcon from "@mui/icons-material/Autorenew"; import { AppState } from "../../../redux"; import { addConceptsToDictionaryErrorListSelector, addConceptsToDictionaryLoadingListSelector, addConceptsToDictionaryProgressListSelector, buildAddConceptToDictionaryMessage, ImportMetaData } from "../../dictionaries"; import { connect } from "react-redux"; import Header from "../../../components/Header"; import { getLocalStorageObject } from "../../../redux/localStorageUtils"; import NotificationCard from "../components/NotificationCard"; import NotificationDetails from "../components/NotificationDetails"; import { NotificationItem } from "../types"; interface Props { loadingList?: (boolean | undefined)[]; inProgressList?: (string | undefined)[]; erroredList?: []; successList?: ({ payload: {} } | undefined)[]; } const SEPARATOR = "--"; const ActionsInProgressPage: React.FC<Props> = ({ loadingList = [], inProgressList = [], erroredList = [], successList = [] }) => { const inProgressListLocalStorage = getLocalStorageObject({ name: "notification", key: "inProgressList", value: inProgressList }); const loadingListLocalStorage = getLocalStorageObject({ name: "notification", key: "loadingList", value: loadingList }); const erroredListLocalStorage = getLocalStorageObject({ name: "notification", key: "erroredList", value: erroredList }); const successListLocalStorage = getLocalStorageObject({ name: "notification", key: "successList", value: successList }); const inProgressItems = loadingListLocalStorage .map((loading: boolean | undefined, index: number) => typeof loading == "boolean" && loading ? inProgressListLocalStorage[index] : null ) .filter((notification: any) => notification) .reverse() as string[]; const successfulItems = loadingListLocalStorage .map((loading: boolean | undefined, index: number) => typeof loading == "boolean" && !loading && !erroredListLocalStorage[index] ? { meta: successListLocalStorage[index]?.meta, result: successListLocalStorage[index]?.payload || "Successful", progress: inProgressListLocalStorage[index] } : null ) .filter( (notification: NotificationItem) => notification && notification.progress ) .reverse() as { result: []; progress: string }[]; const erroredItems = loadingListLocalStorage .map((loading: boolean | undefined, index: number) => typeof loading == "boolean" && !loading && erroredListLocalStorage[index] ? { error: erroredListLocalStorage[index], progress: inProgressListLocalStorage[index] } : null ) .filter( (notification: NotificationItem) => notification && notification.progress ) .reverse() as { error: string; progress: string }[]; const importMetaDataItemsList: ImportMetaData[] = []; const importMetaDataItems = getLocalStorageObject({ name: "notification", key: "importMetaDataList", value: importMetaDataItemsList }).reverse() as ImportMetaData[]; const [notification, setNotification] = React.useState<NotificationItem>({ result: [ { expression: "", added: false, message: "" } ], progress: "" }); const [open, setOpen] = React.useState(false); const [importDateTime, setImportDateTime] = React.useState(""); const handleClose = () => { setOpen(false); }; const openNotificationDetails = ( notification: NotificationItem, importDateTime: string ): void => { setOpen(true); setNotification(notification); setImportDateTime(importDateTime); }; return ( <Header title="Progress Notifications"> <Grid item xs={6}> {inProgressItems.length + erroredItems.length + successfulItems.length ? null : ( <Typography align="center"> Your actions in this session will appear here </Typography> )} {!inProgressItems.length || !importMetaDataItems.length ? null : ( <List subheader={<Chip label="In Progress" icon={<AutorenewIcon />} />} > {inProgressItems.map((item, index) => ( <NotificationCard key={index} headerMessage={item.split(SEPARATOR)[0]} subHeaderMessage={item.split(SEPARATOR)[1] || ""} importMetaData={importMetaDataItems[index]} /> ))} </List> )} {!erroredItems.length || !importMetaDataItems.length ? null : ( <List subheader={<Chip label="Failed" icon={<ErrorIcon />} />}> {erroredItems.map((item, index) => ( <NotificationCard key={index} headerMessage={item.progress.split(SEPARATOR)[0]} subHeaderMessage={item.error} importMetaData={importMetaDataItems[index]} /> ))} </List> )} {!successfulItems.length || !importMetaDataItems.length ? null : ( <List subheader={<Chip label="Completed" icon={<CheckCircleIcon />} />} > {successfulItems.map((notification, index) => ( <NotificationCard key={index} headerMessage={notification.progress.split(SEPARATOR)[0]} subHeaderMessage={buildAddConceptToDictionaryMessage( notification.result )} importMetaData={importMetaDataItems[index]} openNotificationDetails={openNotificationDetails} notification={notification} /> ))} </List> )} <NotificationDetails handleClose={handleClose} notification={notification} importDateTime={importDateTime} open={open} /> </Grid> </Header> ); }; const mapStateToProps = (state: AppState) => ({ isLoggedIn: state.auth.isLoggedIn, loadingList: addConceptsToDictionaryLoadingListSelector(state), inProgressList: addConceptsToDictionaryProgressListSelector(state), erroredList: addConceptsToDictionaryErrorListSelector(state), successList: state.dictionaries.addReferencesResults }); const mapDispatchToProps = {}; export default connect( mapStateToProps, mapDispatchToProps )(ActionsInProgressPage); |