-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(analytics): improve error-handling (#1443)
* fix(analytics): greatly improve analytics error-handling * test(lint): make linter happy * fix(analytics): search * fix(analytics): remove error message * fix(client): fixed language loading * fix(analytics): lumi file scanning case insensitive * test(analytics): changed test to check case sensitivity * fix(analytics): completed localization * feat(analytics): added error locales * refactor(analytics): added new strings to locales * fix(analytics): fixed plurals Co-authored-by: Sebastian Rettig <serettig@posteo.de>
- Loading branch information
1 parent
653410e
commit 287c675
Showing
51 changed files
with
6,314 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import superagent from 'superagent'; | ||
|
||
import { IFile } from './AnalyticsTypes'; | ||
|
||
export async function importAnalytics(): Promise<{ | ||
users: any[]; | ||
interactions: any[]; | ||
files: IFile[]; | ||
}> { | ||
const response = await superagent.get('/api/v1/analytics'); | ||
|
||
return { | ||
users: response.body.users, | ||
interactions: response.body.interactions | ||
files: response.body | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,130 @@ | ||
import React, { useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { makeStyles, Theme } from '@material-ui/core/styles'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import AnalyticsStartPage from './components/AnalyticsStartPage'; | ||
import AnalyticsToolbar from './components/AnalyticsToolbar'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import ListSubheader from '@material-ui/core/ListSubheader'; | ||
import List from '@material-ui/core/List'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemAvatar from '@material-ui/core/ListItemAvatar'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
|
||
import CloseIcon from '@material-ui/icons/Close'; | ||
|
||
import { groupBy } from 'lodash'; | ||
|
||
import LumixAPIViewer from './components/AnalyticsTable'; | ||
|
||
import { actions, IState } from '../state'; | ||
|
||
export default function Analytics() { | ||
const dispatch = useDispatch(); | ||
const users = useSelector((state: IState) => state.analytics.users); | ||
const interactions = useSelector( | ||
(state: IState) => state.analytics.interactions | ||
); | ||
const classes = useStyles(); | ||
const { t } = useTranslation(); | ||
|
||
const files = useSelector((state: IState) => state.analytics.files); | ||
const [searchText, setSearchText] = useState(''); | ||
|
||
const f = files.filter((file) => !file.error); | ||
const d = groupBy(f, (o) => o.contentHash); | ||
|
||
let e = []; | ||
for (const key in d) { | ||
e.push( | ||
<Paper className={classes.paper}> | ||
<LumixAPIViewer | ||
key={key} | ||
interactions={d[key][0].interactions} | ||
users={d[key] | ||
.filter( | ||
(v) => | ||
v.name | ||
.toLowerCase() | ||
.indexOf(searchText.toLowerCase()) > -1 | ||
) | ||
.map((v) => { | ||
return { | ||
id: v.file, | ||
name: v.name, | ||
results: v.results, | ||
error: v.error | ||
}; | ||
})} | ||
/> | ||
</Paper> | ||
); | ||
} | ||
|
||
const brokenFiles = files.filter((file) => file.error); | ||
|
||
return ( | ||
<div style={{ marginTop: '64px' }}> | ||
{users.length === 0 ? ( | ||
{files.length === 0 ? ( | ||
<AnalyticsStartPage | ||
primaryButtonClick={() => | ||
dispatch(actions.analytics.importAnalytics()) | ||
} | ||
/> | ||
) : null} | ||
|
||
{users.length > 0 ? ( | ||
{files.length > 0 ? ( | ||
<div> | ||
<AnalyticsToolbar | ||
openFolder={() => | ||
dispatch(actions.analytics.importAnalytics()) | ||
} | ||
search={(text: string) => setSearchText(text)} | ||
/> | ||
|
||
<LumixAPIViewer | ||
interactions={interactions} | ||
users={users.filter( | ||
(user) => | ||
user.name | ||
.toLocaleLowerCase() | ||
.indexOf(searchText.toLocaleLowerCase()) > | ||
-1 | ||
)} | ||
/> | ||
{e} | ||
</div> | ||
) : null} | ||
{brokenFiles.length > 0 ? ( | ||
<Paper className={classes.paper}> | ||
<List | ||
component="nav" | ||
aria-labelledby="nested-list-subheader" | ||
subheader={ | ||
<ListSubheader | ||
component="div" | ||
id="nested-list-subheader" | ||
> | ||
{t('analytics.brokenFiles')} | ||
</ListSubheader> | ||
} | ||
> | ||
{brokenFiles.map((brokenFile) => ( | ||
<ListItem key={brokenFile.file}> | ||
<ListItemAvatar> | ||
<Avatar className={classes.icon}> | ||
<CloseIcon /> | ||
</Avatar> | ||
</ListItemAvatar> | ||
<ListItemText | ||
primary={brokenFile.file} | ||
secondary={t( | ||
`analytics.errors.${brokenFile.code}` | ||
)} | ||
/> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Paper> | ||
) : null} | ||
</div> | ||
); | ||
} | ||
|
||
const useStyles = makeStyles((theme: Theme) => { | ||
return { | ||
paper: { | ||
margin: '20px' | ||
}, | ||
icon: { | ||
background: theme.palette.error.main | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.