Merge pull request #10006 from strapi/fix/sticky-header

Fix sticky header and select the first locale for copy
This commit is contained in:
cyril lopez 2021-04-09 10:38:55 +02:00 committed by GitHub
commit 6013e35aae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import styled from 'styled-components';
const Wrapper = styled.div` const Wrapper = styled.div`
display: flex; display: flex;
overflow-x: hidden; overflow-x: hidden;
height: 100vh;
p, p,
span { span {
font-family: Lato; font-family: Lato;

View File

@ -16,6 +16,8 @@ const HeaderWrapper = styled.div`
padding-top: 17px; padding-top: 17px;
padding-bottom: 22px; padding-bottom: 22px;
background-color: ${props => props.theme.main.colors.lightGrey}; background-color: ${props => props.theme.main.colors.lightGrey};
border-top-left-radius: ${({ theme }) => theme.main.sizes.borderRadius};
border-top-right-radius: ${({ theme }) => theme.main.sizes.borderRadius};
border: 0; border: 0;
`; `;
@ -41,6 +43,8 @@ const Footer = styled.div`
justify-content: space-between; justify-content: space-between;
background-color: ${props => props.theme.main.colors.strapi['gray-light']}; background-color: ${props => props.theme.main.colors.strapi['gray-light']};
padding: 15px 30px 17px 30px; padding: 15px 30px 17px 30px;
border-bottom-left-radius: ${({ theme }) => theme.main.sizes.borderRadius};
border-bottom-right-radius: ${({ theme }) => theme.main.sizes.borderRadius};
> button { > button {
padding: 0 30px; padding: 0 30px;
} }

View File

@ -17,13 +17,23 @@ import {
import { getTrad } from '../../utils'; import { getTrad } from '../../utils';
import { cleanData, generateOptions } from './utils'; import { cleanData, generateOptions } from './utils';
const CMEditViewCopyLocale = ({ appLocales, currentLocale, localizations, readPermissions }) => { const CMEditViewCopyLocale = props => {
if (!props.localizations.length) {
return null;
}
return <Content {...props} />;
};
const Content = ({ appLocales, currentLocale, localizations, readPermissions }) => {
const options = generateOptions(appLocales, currentLocale, localizations, readPermissions);
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const dispatch = useDispatch(); const dispatch = useDispatch();
const { allLayoutData, slug } = useContentManagerEditViewDataManager(); const { allLayoutData, slug } = useContentManagerEditViewDataManager();
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [value, setValue] = useState(null); const [value, setValue] = useState(options[0]);
const theme = useTheme(); const theme = useTheme();
const handleConfirmCopyLocale = async () => { const handleConfirmCopyLocale = async () => {
@ -73,12 +83,6 @@ const CMEditViewCopyLocale = ({ appLocales, currentLocale, localizations, readPe
setIsOpen(prev => !prev); setIsOpen(prev => !prev);
}; };
if (!localizations.length) {
return null;
}
const options = generateOptions(appLocales, currentLocale, localizations, readPermissions);
const styles = selectStyles(theme); const styles = selectStyles(theme);
return ( return (
@ -127,8 +131,8 @@ const CMEditViewCopyLocale = ({ appLocales, currentLocale, localizations, readPe
aria-labelledby="select-locale" aria-labelledby="select-locale"
components={{ DropdownIndicator }} components={{ DropdownIndicator }}
isSearchable={false} isSearchable={false}
defaultValue={options[0]}
onChange={handleChange} onChange={handleChange}
options={options}
styles={{ styles={{
...styles, ...styles,
control: (base, state) => ({ control: (base, state) => ({
@ -157,6 +161,10 @@ const CMEditViewCopyLocale = ({ appLocales, currentLocale, localizations, readPe
}; };
CMEditViewCopyLocale.propTypes = { CMEditViewCopyLocale.propTypes = {
localizations: PropTypes.array.isRequired,
};
Content.propTypes = {
appLocales: PropTypes.arrayOf( appLocales: PropTypes.arrayOf(
PropTypes.shape({ PropTypes.shape({
code: PropTypes.string.isRequired, code: PropTypes.string.isRequired,

View File

@ -4,7 +4,8 @@ const generateOptions = (appLocales, currentLocale, localizations, permissions)
return appLocales return appLocales
.filter(({ code }) => { .filter(({ code }) => {
return ( return (
code !== currentLocale && localizations.findIndex(({ locale }) => locale === code) !== -1 code !== currentLocale &&
(localizations || []).findIndex(({ locale }) => locale === code) !== -1
); );
}) })
.filter(({ code }) => { .filter(({ code }) => {