Skip to content
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

WRQ-30515: Added handler to display colors state in actions log when favorite color is removed #1660

Merged
merged 14 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions ColorPickerPOC/ColorPickerPOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,22 @@

const SpottableButton = Spottable(ButtonBase);

const FavoriteColors = ({colorHandler, colors = [], selectedColor = '#3455eb', selectedColorHandler}) => {
const FavoriteColors = ({favoriteColors = [], favoriteColorsHandler, selectedColor = '#3455eb', selectedColorHandler}) => {
const [clickEnabled, setClickEnabled] = useState(true);
const [editEnabled, setEditEnabled] = useState(false);
const [favoriteColors, setFavoriteColors] = useState(colors);

const shakeEffectRef = useRef(null);
const timerRef = useRef(null);

const addNewFavoriteColor = useCallback(() => {
if (favoriteColors.includes(selectedColor)) return;
setFavoriteColors(prevState => {
const colorsState = [...prevState, selectedColor];
favoriteColorsHandler(() => {
const colorsState = [...favoriteColors, selectedColor];

Check warning on line 33 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L32-L33

Added lines #L32 - L33 were not covered by tests
if (colorsState.length > 8) colorsState.shift();
colorHandler({selectedColor, favoriteColors: colorsState});

return colorsState;
});
}, [colorHandler, favoriteColors, selectedColor]);
}, [favoriteColors, favoriteColorsHandler, selectedColor]);

const onAddNewFavoriteColor = useCallback(() => {
if (editEnabled) {
Expand All @@ -51,32 +49,40 @@
if (!clickEnabled) return;
const targetId = ev.target.offsetParent.id || ev.target.id;
const [buttonColor, buttonIndex] = targetId.split('-');

if (editEnabled && clickEnabled) {
setFavoriteColors(prevState =>
prevState.filter((stateColor, index) => {
return !(stateColor === buttonColor && index === Number(buttonIndex));
}));
const filteredColors = favoriteColors.filter((color, index) => {

Check warning on line 54 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L54

Added line #L54 was not covered by tests
return !(color === buttonColor && index === Number(buttonIndex));
});

favoriteColorsHandler(filteredColors);
selectedColorHandler(selectedColor);

Check warning on line 59 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L58-L59

Added lines #L58 - L59 were not covered by tests
return;
}

favoriteColorsHandler(favoriteColors);

Check warning on line 63 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L63

Added line #L63 was not covered by tests
selectedColorHandler(buttonColor);
colorHandler({currentColor: buttonColor, favoriteColors});
}, [clickEnabled, colorHandler, editEnabled, favoriteColors, selectedColorHandler]);
}, [clickEnabled, editEnabled, favoriteColors, favoriteColorsHandler, selectedColor, selectedColorHandler]);

const onMouseDown = useCallback((ev) => {
const onPressHandler = useCallback((ev) => {

Check warning on line 67 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L67

Added line #L67 was not covered by tests
if (editEnabled) return;
const target = ev.target.id ? ev.target : ev.target.offsetParent;

shakeEffectRef.current = setTimeout(() => {
target.classList.add(componentsCss.shakeFavoriteColor);
}, 300);

timerRef.current = setTimeout(() => {
setEditEnabled(true);
setClickEnabled(false);
target.classList.remove(componentsCss.shakeFavoriteColor);

Check warning on line 78 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L78

Added line #L78 was not covered by tests
}, 1000);
}, [editEnabled]);

const onMouseUp = useCallback((ev) => {
const onReleaseHandler = useCallback((ev) => {

Check warning on line 82 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L82

Added line #L82 was not covered by tests
const target = ev.target.id ? ev.target : ev.target.offsetParent;
target.classList.remove(componentsCss.shakeFavoriteColor);

clearTimeout(shakeEffectRef.current);
clearTimeout(timerRef.current);
setTimeout(() => {
Expand All @@ -87,7 +93,7 @@
return (
<div>
<Row className={componentsCss.favoriteColorsRow}>
<Cell align={'end'}>
<Cell align="end">
{favoriteColors.slice(4, 8).map((color, index) => {
return (
<SpottableButton
Expand All @@ -96,9 +102,11 @@
key={`${color}_${index + 4}`}
minWidth={false}
onClick={onSelectFavoriteColor}
onMouseDown={onMouseDown}
onMouseUp={onMouseUp}
size={'small'}
onMouseDown={onPressHandler}
onMouseUp={onReleaseHandler}
onPointerDown={onPressHandler}
onPointerUp={onReleaseHandler}
size="small"
style={{
backgroundColor: color,
borderColor: generateOppositeColor(color),
Expand All @@ -110,7 +118,7 @@
);
})}
</Cell>
<Cell align={'end'}>
<Cell align="end">
{favoriteColors.slice(0, 4).map((color, index) => {
return (
<SpottableButton
Expand All @@ -119,9 +127,11 @@
key={`${color}_${index}`}
minWidth={false}
onClick={onSelectFavoriteColor}
onMouseDown={onMouseDown}
onMouseUp={onMouseUp}
size={'small'}
onMouseDown={onPressHandler}
onMouseUp={onReleaseHandler}
onPointerDown={onPressHandler}
onPointerUp={onReleaseHandler}
size="small"
style={{
backgroundColor: color,
borderColor: generateOppositeColor(color),
Expand All @@ -134,9 +144,9 @@
})}
</Cell>
</Row>
<Column align={'center'}>
<Column align="center" className={componentsCss.selectedColorColumn}>
<SpottableButton
className={componentsCss.currentColor}
className={componentsCss.selectedColor}
minWidth={false}
onClick={onAddNewFavoriteColor}
style={{
Expand All @@ -145,7 +155,7 @@
color: generateOppositeColor(selectedColor)
}}
>
<Icon className={componentsCss.currentColorIcon} size={'large'}>{editEnabled ? 'check' : 'plus'}</Icon>
<Icon className={componentsCss.selectedColorIcon} size="large">{editEnabled ? 'check' : 'plus'}</Icon>

Check warning on line 158 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L158

Added line #L158 was not covered by tests
</SpottableButton>
</Column>
</div>
Expand All @@ -156,19 +166,22 @@
colorHandler: PropTypes.func,
colors: PropTypes.array,
css: PropTypes.object,
favoriteColors: PropTypes.array,
favoriteColorsHandler: PropTypes.func,
selectedColor: PropTypes.string,
selectedColorHandler: PropTypes.func
};


const ColorPickerPOCBase = ({color = '#eb4034', colors = [], css, onChangeColor, open, ...rest}) => {
const [favoriteColors, setFavoriteColors] = useState(colors);

Check warning on line 177 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L177

Added line #L177 was not covered by tests
const [selectedColor, setSelectedColor] = useState(color);

useEffect(() => {
if (selectedColor) {
onChangeColor({currentColor: selectedColor});
if (selectedColor || favoriteColors) {
onChangeColor({selectedColor, favoriteColors});

Check warning on line 182 in ColorPickerPOC/ColorPickerPOC.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerPOC.js#L182

Added line #L182 was not covered by tests
}
}, [onChangeColor, selectedColor]);
}, [favoriteColors, onChangeColor, selectedColor]);

return (
<Popup open={open} position={'center'} {...rest}>
Expand Down Expand Up @@ -198,6 +211,8 @@
colorHandler={onChangeColor}
colors={colors}
css={css}
favoriteColors={favoriteColors}
favoriteColorsHandler={setFavoriteColors}
selectedColor={selectedColor}
selectedColorHandler={setSelectedColor}
/>
Expand Down
35 changes: 20 additions & 15 deletions ColorPickerPOC/ColorPickerPOC.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
min-width: 800px;
}

.currentColor {
border-radius: 24px;
border: 9px solid;
height: 240px;
transition: transform .2s;
width: 100%;

.currentColorIcon {
transition: transform .2s;
}
.selectedColorColumn {
margin-top: 15px;

.focus({
box-shadow: 0 0 12px 6px inset;
.selectedColor {
border-radius: 24px;
border: 9px solid;
height: 240px;
margin-inline: 0;
transition: transform .2s;
width: 95%;

.currentColorIcon {
transform: scale(1.2);
.selectedColorIcon {
transition: transform .2s;
}
});

.focus({
box-shadow: 0 0 12px 6px inset;

.selectedColorIcon {
transform: scale(1.2);
}
});
}
}

.favoriteColorsRow {
Expand Down