-
Notifications
You must be signed in to change notification settings - Fork 1
feat(AF-66): Chapter progress overview #68
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
Open
kimbylr
wants to merge
7
commits into
master
Choose a base branch
from
feat/af-66-chapter-progress-overview
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
19b183a
feat(AF-66): Chapter progress overview
kimbylr 62bfd78
chapter components overview by state
kimbylr 3308a9f
add translation progress component
kimbylr b7f17b7
chapter states
kimbylr b32bf51
cleanup
kimbylr 02e076b
languages
kimbylr a9fcb0c
fix comments from CR
kimbylr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "trailingComma": "all", | ||
| "printWidth": 90, | ||
| "singleQuote": false | ||
| } | ||
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { Table, TableBody, TableCell, TableHead, TableRow } from "@material-ui/core"; | ||
| import { WithStyles, withStyles, withTheme } from "@material-ui/core/styles"; | ||
| import { getChapters_chapters_subChapters_components } from "queries/__generated__/getChapters"; | ||
| import * as React from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import styled from "styled-components"; | ||
| import { styles } from "styles"; | ||
| import { EditStates } from "types/editStates"; | ||
|
|
||
| type ChapterState = { | ||
| [key: string]: { | ||
| [key in keyof typeof EditStates]?: number; | ||
| }; | ||
| }; | ||
|
|
||
| interface Props extends WithStyles<typeof styles> { | ||
| components: getChapters_chapters_subChapters_components[]; | ||
| } | ||
| const ChapterComponents = ({ components }: Props) => { | ||
| const { t } = useTranslation("chapter"); | ||
| const chapterState: ChapterState = components.reduce( | ||
| (acc, { state, type: { name } }) => ({ | ||
| ...acc, | ||
| [name]: { [state]: (acc[name]?.[state as EditStates] || 0) + 1 }, | ||
| }), | ||
| {} as ChapterState, | ||
| ); | ||
|
|
||
| return ( | ||
| <Table size="small"> | ||
| <TableHead> | ||
| <TableRow> | ||
| <TableCell></TableCell> | ||
| <TableCell></TableCell> | ||
| </TableRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| {Object.entries(chapterState).map(([typeName, counts]) => ( | ||
| <TableRow key={typeName}> | ||
| <TableCell variant="head" padding="none"> | ||
| {typeName} | ||
| </TableCell> | ||
| <TableCell> | ||
| <StateList> | ||
| {Object.values(EditStates) | ||
| .filter((state) => !!counts[state]) | ||
| .map((state) => ( | ||
| <StateListItem | ||
| key={state} | ||
| state={state} | ||
| title={t(`chapters:editState${state}`)} | ||
| > | ||
| {counts[state]} | ||
| </StateListItem> | ||
| ))} | ||
| </StateList>{" "} | ||
| </TableCell> | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| ); | ||
| }; | ||
|
|
||
| export default withStyles(styles, { withTheme: true })(ChapterComponents); | ||
|
|
||
| const StateList = styled.ul` | ||
| list-style: none; | ||
| display: flex; | ||
| margin: 0; | ||
| padding: 0; | ||
| `; | ||
|
|
||
| const StateListItem = withTheme(styled.li<{ state: EditStates }>` | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| margin-right: 8px; | ||
| height: 24px; | ||
| width: 24px; | ||
| border-radius: 99px; | ||
| padding: 0; | ||
| background: ${({ state, theme: { editStateColors } }) => editStateColors[state]}; | ||
| `); |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { Typography } from "@material-ui/core"; | ||
| import { | ||
| makeStyles, | ||
| Theme, | ||
| WithStyles, | ||
| withStyles, | ||
| withTheme, | ||
| } from "@material-ui/core/styles"; | ||
| import { | ||
| getChapters_chapters_languages, | ||
| getChapters_chapters_subChapters_components, | ||
| } from "queries/__generated__/getChapters"; | ||
| import * as React from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import styled from "styled-components"; | ||
| import { styles } from "styles"; | ||
|
|
||
| interface Props extends WithStyles<typeof styles> { | ||
| components: getChapters_chapters_subChapters_components[]; | ||
| languages: getChapters_chapters_languages[]; | ||
| } | ||
| const ChapterLanguages = ({ components, languages }: Props) => { | ||
| const { t } = useTranslation("chapters"); | ||
| const { spacing } = useStyles(); | ||
|
|
||
| // e.g. { de: { translations: 5, valid: 3 }, … } | ||
| const state = languages.reduce( | ||
| (acc, { language: { id } }) => ({ ...acc, [id]: { translations: 0, valid: 0 } }), | ||
| {} as { [key: string]: { translations: number; valid: number } }, | ||
| ); | ||
| components | ||
| .filter(({ texts }) => texts.length > 0 && texts.some((text) => text.translatable)) | ||
| .flatMap(({ texts }) => texts) | ||
| .forEach(({ translations }) => | ||
| translations.forEach(({ language: { id }, valid }) => { | ||
| state[id].translations++; | ||
| valid && state[id].valid++; | ||
| }), | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <Typography variant="h6" component="h3" className={spacing}> | ||
| {t("translationProgress")} | ||
| </Typography> | ||
| <LanguageList> | ||
| {Object.entries(state).map(([language, { translations, valid }]) => ( | ||
| <LanguageListItem key={language}> | ||
| <span style={{ width: "32px" }}>{language.toUpperCase()}</span> | ||
| <ProgressBar filled={valid / translations} /> | ||
| <Count> | ||
| {valid} / {translations} | ||
| </Count> | ||
| </LanguageListItem> | ||
| ))} | ||
| </LanguageList> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default withStyles(styles, { withTheme: true })(ChapterLanguages); | ||
|
|
||
| const useStyles = makeStyles((theme: Theme) => ({ | ||
| spacing: { | ||
| marginTop: theme.spacing(2), | ||
| }, | ||
| })); | ||
|
|
||
| const LanguageList = styled.ul` | ||
| list-style: none; | ||
| margin: 0; | ||
| padding: 0; | ||
| text-align: left; | ||
| `; | ||
|
|
||
| const LanguageListItem = styled.li` | ||
| display: flex; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| const Count = withTheme(styled.span` | ||
| color: ${({ theme: { palette } }) => palette.grey[500]}; | ||
| font-size: 0.75em; | ||
| width: 32px; | ||
| text-align: right; | ||
| `); | ||
|
|
||
| const ProgressBar = withTheme(styled.span<{ filled: number }>` | ||
| margin: 0 4px; | ||
| border: 1px solid ${({ theme: { palette } }) => palette.grey[500]}; | ||
| flex-grow: 1; | ||
| background: linear-gradient( | ||
| to right, | ||
| ${({ theme: { palette } }) => palette.primary.main} ${({ filled }) => filled * 100}%, | ||
| transparent ${({ filled }) => filled * 100}% | ||
| ); | ||
| height: 10px; | ||
| `); |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.