Skip to content

Commit

Permalink
Improve Frame Filtering UX (#352)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Skoufis <askoufis@users.noreply.github.com>
  • Loading branch information
felixhabib and askoufis committed May 24, 2024
1 parent 422a259 commit 7df36e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .changeset/itchy-bugs-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'playroom': minor
---

Improve frame filtering UX.

- Allow users to select all checkboxes in a frame filter section, rather than automatically unselecting all checkboxes when all are selected.
- Rename the "Show all" button to "Clear" to reinforce the filtering pattern.
4 changes: 4 additions & 0 deletions cypress/e2e/toolbar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
typeCode,
gotoPreview,
loadPlayroom,
getResetButton,
selectWidthPreference,
} from '../support/utils';

Expand All @@ -19,6 +20,9 @@ describe('Toolbar', () => {
assertFramesMatch(frames);
selectWidthPreference(frames[widthIndexToSelect]);
assertFramesMatch([frames[widthIndexToSelect]]);

getResetButton().click();
assertFramesMatch(frames);
});

it('preview', () => {
Expand Down
2 changes: 2 additions & 0 deletions cypress/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const selectWidthPreference = (width: number) => {
cy.findByRole('checkbox', { name: `${width}` }).click();
};

export const getResetButton = () => cy.findByRole('button', { name: 'Clear' });

export const togglePreviewPanel = () =>
cy.findByRole('button', { name: 'Preview playroom' }).click();

Expand Down
15 changes: 4 additions & 11 deletions src/Playroom/FramesPanel/FramesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,20 @@ interface FrameHeadingProps {
const FrameHeading = ({ showReset, onReset, children }: FrameHeadingProps) => (
<div className={styles.title}>
<Heading level="3">{children}</Heading>
{showReset && <ResetButton onClick={onReset}>Show all</ResetButton>}
{showReset && <ResetButton onClick={onReset}>Clear</ResetButton>}
</div>
);

interface FrameOptionProps<Option> {
option: Option;
selected: boolean;
visible: Option[];
available: Option[];
onChange: (options?: Option[]) => void;
}
function FrameOption<Option>({
option,
selected,
visible,
available,
onChange,
}: FrameOptionProps<Option>) {
return (
Expand All @@ -71,13 +69,10 @@ function FrameOption<Option>({
type="checkbox"
checked={selected}
className={styles.checkbox}
onChange={(ev) => {
if (ev.target.checked) {
onChange={(event) => {
if (event.target.checked) {
const newVisiblePreference = [...visible, option];
const isOriginalList =
JSON.stringify(newVisiblePreference.sort()) ===
JSON.stringify([...available].sort());
onChange(isOriginalList ? undefined : newVisiblePreference);
onChange(newVisiblePreference);
} else {
onChange(visible.filter((p) => p !== option));
}
Expand Down Expand Up @@ -146,7 +141,6 @@ export default ({ availableWidths, availableThemes }: FramesPanelProps) => {
option={option}
selected={hasFilteredWidths && visibleWidths.includes(option)}
visible={visibleWidths}
available={availableWidths}
onChange={(newWidths) => {
if (newWidths) {
dispatch({
Expand Down Expand Up @@ -175,7 +169,6 @@ export default ({ availableWidths, availableThemes }: FramesPanelProps) => {
option={option}
selected={hasFilteredThemes && visibleThemes.includes(option)}
visible={visibleThemes}
available={availableThemes}
onChange={(newThemes) => {
if (newThemes) {
dispatch({
Expand Down

0 comments on commit 7df36e3

Please sign in to comment.