Merge branch 'feature/relations-main-view' into feature/relations-main-view-reducer

This commit is contained in:
Gustav Hansen 2022-08-10 15:49:27 +02:00 committed by GitHub
commit 69f44aded3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 30 deletions

View File

@ -404,15 +404,6 @@ const EditViewDataManagerProvider = ({
}); });
}, []); }, []);
const moveRelation = useCallback((dragIndex, overIndex, name) => {
dispatch({
type: 'MOVE_FIELD',
dragIndex,
overIndex,
keys: name.split('.'),
});
}, []);
const removeRelation = useCallback(({ target: { name, value } }) => { const removeRelation = useCallback(({ target: { name, value } }) => {
dispatch({ dispatch({
type: 'REMOVE_RELATION', type: 'REMOVE_RELATION',
@ -488,7 +479,6 @@ const EditViewDataManagerProvider = ({
moveComponentDown, moveComponentDown,
moveComponentField, moveComponentField,
moveComponentUp, moveComponentUp,
moveRelation,
onChange: handleChange, onChange: handleChange,
onPublish: handlePublish, onPublish: handlePublish,
onUnpublish, onUnpublish,

View File

@ -64,13 +64,8 @@ function SelectWrapper({
const [{ query }] = useQueryParams(); const [{ query }] = useQueryParams();
// Disable the input in case of a polymorphic relation // Disable the input in case of a polymorphic relation
const isMorph = useMemo(() => relationType.toLowerCase().includes('morph'), [relationType]); const isMorph = useMemo(() => relationType.toLowerCase().includes('morph'), [relationType]);
const {
addRelation, const { addRelation, modifiedData, onChange, removeRelation } = useCMEditViewDataManager();
modifiedData,
moveRelation,
onChange,
removeRelation,
} = useCMEditViewDataManager();
const { pathname } = useLocation(); const { pathname } = useLocation();
const value = get(modifiedData, name, null); const value = get(modifiedData, name, null);
@ -295,7 +290,6 @@ function SelectWrapper({
isLoading={isLoading} isLoading={isLoading}
isClearable isClearable
mainField={mainField} mainField={mainField}
move={moveRelation}
name={name} name={name}
options={filteredOptions} options={filteredOptions}
onChange={handleChange} onChange={handleChange}

View File

@ -0,0 +1,41 @@
import PropTypes from 'prop-types';
import React from 'react';
import SelectAsync from 'react-select/async';
import { useTheme } from 'styled-components';
import ClearIndicator from '../components/ClearIndicator';
import DropdownIndicator from '../components/DropdownIndicator';
import IndicatorSeparator from '../components/IndicatorSeparator';
import getSelectStyles from '../utils/getSelectStyles';
const ReactSelectAsync = ({ components, styles, error, ariaErrorMessage, ...props }) => {
const theme = useTheme();
const customStyles = getSelectStyles(theme, error);
return (
<SelectAsync
{...props}
components={{ ClearIndicator, DropdownIndicator, IndicatorSeparator, ...components }}
aria-errormessage={error && ariaErrorMessage}
aria-invalid={!!error}
styles={{ ...customStyles, ...styles }}
/>
);
};
export default ReactSelectAsync;
ReactSelectAsync.defaultProps = {
ariaErrorMessage: undefined,
components: undefined,
error: undefined,
styles: undefined,
};
ReactSelectAsync.propTypes = {
ariaErrorMessage: PropTypes.string,
components: PropTypes.object,
error: PropTypes.string,
styles: PropTypes.object,
};

View File

@ -0,0 +1 @@
export default from './Async';

View File

@ -1,3 +1 @@
import ReactSelect from './ReactSelect'; export default from './ReactSelect';
export default ReactSelect;

View File

@ -7,16 +7,16 @@ const getSelectStyles = (theme, error) => {
lineHeight: 'normal', lineHeight: 'normal',
}), }),
control: (base, state) => { control: (base, state) => {
let border = `1px solid ${theme.colors.neutral200} !important`; let borderColor = theme.colors.neutral200;
let boxShadow = 0; let boxShadowColor;
let backgroundColor; let backgroundColor;
if (state.isFocused) { if (state.isFocused) {
border = `1px solid ${theme.colors.primary600} !important`; borderColor = theme.colors.primary600;
boxShadow = `${theme.colors.primary600} 0px 0px 0px 2px`; boxShadowColor = theme.colors.primary600;
} else if (error) { } else if (error) {
border = `1px solid ${theme.colors.danger600} !important`; borderColor = theme.colors.danger600;
boxShadow = `${theme.colors.danger600} 0px 0px 0px 2px`; boxShadowColor = theme.colors.danger600;
} }
if (state.isDisabled) { if (state.isDisabled) {
@ -27,7 +27,7 @@ const getSelectStyles = (theme, error) => {
...base, ...base,
fontSize: 14, fontSize: 14,
height: 40, height: 40,
border, border: `1px solid ${borderColor} !important`,
outline: 0, outline: 0,
borderRadius: '2px !important', borderRadius: '2px !important',
backgroundColor, backgroundColor,
@ -35,7 +35,7 @@ const getSelectStyles = (theme, error) => {
borderTopRightRadius: '4px !important', borderTopRightRadius: '4px !important',
borderBottomLeftRadius: '4px !important', borderBottomLeftRadius: '4px !important',
borderBottomRightRadius: '4px !important', borderBottomRightRadius: '4px !important',
boxShadow, boxShadow: boxShadowColor ? `${boxShadowColor} 0px 0px 0px 2px` : 0,
}; };
}, },
indicatorContainer: base => ({ ...base, padding: 0, paddingRight: theme.spaces[3] }), indicatorContainer: base => ({ ...base, padding: 0, paddingRight: theme.spaces[3] }),

View File

@ -41,7 +41,6 @@ const MyCompo = () => {
moveComponentDown: () => {}, moveComponentDown: () => {},
moveComponentField: () => {}, moveComponentField: () => {},
moveComponentUp: () => {}, moveComponentUp: () => {},
moveRelation: () => {},
onChange: () => {}, onChange: () => {},
onRemoveRelation: () => {}, onRemoveRelation: () => {},
removeComponentFromDynamicZone: () => {}, removeComponentFromDynamicZone: () => {},

View File

@ -64,6 +64,7 @@ export { default as PageSizeURLQuery } from './components/PageSizeURLQuery';
export { default as RelativeTime } from './components/RelativeTime'; export { default as RelativeTime } from './components/RelativeTime';
export { default as DateTimePicker } from './components/DateTimePicker'; export { default as DateTimePicker } from './components/DateTimePicker';
export { default as ReactSelect } from './components/ReactSelect'; export { default as ReactSelect } from './components/ReactSelect';
export { default as ReactSelectAsync } from './components/ReactSelect/Async';
export { default as Link } from './components/Link'; export { default as Link } from './components/Link';
export { default as LinkButton } from './components/LinkButton'; export { default as LinkButton } from './components/LinkButton';