-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add translation menu button to default navigation bar
REDMINE-20592
- Loading branch information
Showing
16 changed files
with
223 additions
and
28 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
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
71 changes: 71 additions & 0 deletions
71
entry_types/scrolled/package/spec/widgets/defaultNavigation/TranslationsMenu-spec.js
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import {TranslationsMenu} from 'widgets/defaultNavigation/TranslationsMenu'; | ||
|
||
import '@testing-library/jest-dom/extend-expect'; | ||
import {renderInEntry} from 'support'; | ||
|
||
describe('TranslationsMenu', () => { | ||
it('marks current page in rendered list of translations', async () => { | ||
const {getByRole} = renderInEntry(<TranslationsMenu />, { | ||
seed: { | ||
entry: { | ||
id: 5, | ||
}, | ||
entryTranslations: [ | ||
{ | ||
id: 5, | ||
displayLocale: 'Deutsch', | ||
url: '/entry-de' | ||
}, | ||
{ | ||
id: 6, | ||
displayLocale: 'English', | ||
url: '/entry-en' | ||
} | ||
] | ||
} | ||
}); | ||
|
||
expect(getByRole('link', {name: 'English'})).toHaveAttribute('href', '/entry-en'); | ||
expect(getByRole('listitem', {current: 'page'})).toHaveTextContent('Deutsch'); | ||
}); | ||
|
||
it('includes shortend uppercased locale in button', async () => { | ||
const {getByRole} = renderInEntry(<TranslationsMenu />, { | ||
seed: { | ||
entry: { | ||
id: 5, | ||
locale: 'de-ch' | ||
}, | ||
entryTranslations: [ | ||
{ | ||
id: 5, | ||
displayLocale: 'Deutsch', | ||
url: '/entry-de' | ||
}, | ||
{ | ||
id: 6, | ||
displayLocale: 'English', | ||
url: '/entry-en' | ||
} | ||
] | ||
} | ||
}); | ||
|
||
expect(getByRole('button')).toHaveTextContent(/^DE$/); | ||
}); | ||
|
||
it('renders nothing if no translations are present', async () => { | ||
const {container} = renderInEntry(<TranslationsMenu />, { | ||
seed: { | ||
entry: { | ||
id: 5, | ||
locale: 'de-ch' | ||
}, | ||
entryTranslations: [] | ||
} | ||
}); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
entry_types/scrolled/package/src/entryState/entryTranslations.js
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {useEntryStateConfig} from "./EntryStateProvider"; | ||
|
||
export function useEntryTranslations() { | ||
const config = useEntryStateConfig(); | ||
return config.entryTranslations; | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
60 changes: 60 additions & 0 deletions
60
entry_types/scrolled/package/src/widgets/defaultNavigation/TranslationsMenu.js
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import headerStyles from "./DefaultNavigation.module.css"; | ||
import styles from "./TranslationsMenu.module.css"; | ||
|
||
import { | ||
ThemeIcon, | ||
Tooltip, | ||
useI18n, | ||
useEntryMetadata, | ||
useEntryTranslations | ||
} from 'pageflow-scrolled/frontend'; | ||
|
||
export function TranslationsMenu({tooltipOffset = 0}) { | ||
const {t} = useI18n(); | ||
const entry = useEntryMetadata(); | ||
const translations = useEntryTranslations(); | ||
|
||
if (translations.length < 2) { | ||
return null; | ||
} | ||
|
||
const content = ( | ||
<div className={styles.tooltip}> | ||
<ul className={styles.list}> | ||
{translations.map(({id, url, displayLocale}) => { | ||
if (entry.id === id) { | ||
return ( | ||
<li key={id} aria-current="page"> | ||
<strong>{displayLocale}</strong> | ||
</li> | ||
); | ||
} | ||
else { | ||
return ( | ||
<li key={id}> | ||
<a target="_top" href={url}>{displayLocale}</a> | ||
</li> | ||
); | ||
} | ||
})} | ||
</ul> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Tooltip horizontalOffset={tooltipOffset - 30} | ||
arrowPos={120 - tooltipOffset} | ||
content={content}> | ||
<button className={classNames(headerStyles.contextIcon)} | ||
aria-haspopup="true" | ||
title={t('pageflow_scrolled.public.navigation.language')}> | ||
<ThemeIcon name="world" /> | ||
<div className={styles.tag}> | ||
<span>{entry.locale.substring(0, 2).toUpperCase()}</span> | ||
</div> | ||
</button> | ||
</Tooltip> | ||
) | ||
} |
50 changes: 50 additions & 0 deletions
50
entry_types/scrolled/package/src/widgets/defaultNavigation/TranslationsMenu.module.css
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.tooltip { | ||
margin: -5px 0; | ||
} | ||
|
||
.list { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
.list > li { | ||
margin: 0; | ||
border-top: solid 1px var(--default-navigation-separator-color); | ||
} | ||
|
||
.list > li:first-child { | ||
border-top: none; | ||
} | ||
|
||
.list a, | ||
.list strong { | ||
display: block; | ||
font-size: 16px; | ||
font-weight: bold; | ||
text-decoration: none; | ||
line-height: 42px; | ||
} | ||
|
||
.list a { | ||
color: var(--theme-widget-primary-color); | ||
} | ||
|
||
.list strong { | ||
color: var(--theme-accent-color); | ||
} | ||
|
||
.tag { | ||
position: absolute; | ||
bottom: 10px; | ||
right: 5px; | ||
background: currentColor; | ||
border-radius: 3px; | ||
font-size: 11px; | ||
padding: 2px; | ||
font-weight: bold; | ||
} | ||
|
||
.tag > span { | ||
color: #fff; | ||
} |
Oops, something went wrong.