Skip to content

Commit

Permalink
feat: use Switch instead of AutoCompleteRadioGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed May 24, 2024
1 parent dbeccaf commit 60efaa9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
10 changes: 3 additions & 7 deletions cypress/e2e/goalDependencies.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import '../support';
import { routes } from '../../src/hooks/router';
import {
goalDependenciesInput,
goalDependenciesRadios,
goalDependenciesSuggestionItemTitle,
goalDependenciesSwitch,
goalDependenciesTrigger,
goalDependencyGoalsListItem,
goalDependencyKindBlocks,
Expand Down Expand Up @@ -89,7 +89,7 @@ const checkList = (

const addDependency = (title: string, relationKind: keyof typeof dependencyKind) => {
cy.get(goalDependenciesInput.query).type(title);
cy.get(goalDependenciesRadios.query).get(`input[type="radio"][value="${relationKind}"]`).click();
cy.get(goalDependenciesSwitch.query).get(`button[value="${relationKind}"]`).click();

cy.get(goalDependenciesSuggestionItemTitle.query)
.filter(`:contains(${title})`)
Expand All @@ -107,12 +107,8 @@ const checkSelectingDependencies = () => {

it('dependencies kind should exist', () => {
Object.values(dependencyKind).forEach((kind) => {
cy.get(goalDependenciesRadios.query).get(`input[type="radio"][value="${kind}"]`).should('exist');
cy.get(goalDependenciesSwitch.query).get(`button[value="${kind}"]`).should('exist');
});

cy.get(goalDependenciesRadios.query)
.get(`input[type="radio"][value="${dependencyKind.blocks}"]`)
.should('be.checked');
});

it('add blocked dependency', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/components/GoalDependency/GoalDependency.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.GoalDependencyCheckbox {
margin: 0;
}

.DependencyKindSwitch {
margin: var(--gap-s) 0;
display: inline-flex;
}
27 changes: 12 additions & 15 deletions src/components/GoalDependency/GoalDependency.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FC, useCallback, useMemo, useState } from 'react';
import { AutoCompleteRadioGroup, CheckboxInput } from '@taskany/bricks';
import { UserGroup } from '@taskany/bricks/harmony';
import { UserGroup, Checkbox, Switch, SwitchControl } from '@taskany/bricks/harmony';
import { Goal } from '@prisma/client';

import { trpc } from '../../utils/trpcClient';
Expand All @@ -12,8 +11,8 @@ import { safeUserData } from '../../utils/getUserName';
import { GoalSelect } from '../GoalSelect/GoalSelect';
import {
goalDependenciesInput,
goalDependenciesRadios,
goalDependenciesSuggestionItemTitle,
goalDependenciesSwitch,
} from '../../utils/domObjects';

import { tr } from './GoalDependency.i18n';
Expand Down Expand Up @@ -77,11 +76,7 @@ export const GoalDependency: FC<GoalDependencyProps> = ({ id, items = [], onSubm
<GoalListItemCompact
icon
rawIcon={
<CheckboxInput
className={s.GoalDependencyCheckbox}
checked={props.active}
value={props.item.id}
/>
<Checkbox className={s.GoalDependencyCheckbox} checked={props.active} value={props.item.id} />
}
item={props.item}
columns={[
Expand Down Expand Up @@ -117,14 +112,16 @@ export const GoalDependency: FC<GoalDependencyProps> = ({ id, items = [], onSubm
)}
>
<FilterAutoCompleteInput onChange={setGoalQuery} autoFocus {...goalDependenciesInput.attr} />
<AutoCompleteRadioGroup
title={tr('Kind')}
items={radios}
name="Kind"
onChange={({ value }) => setKind(value)}
<Switch
className={s.DependencyKindSwitch}
value={kind}
{...goalDependenciesRadios.attr}
/>
onChange={(_, value) => setKind(value as dependencyKind)}
{...goalDependenciesSwitch.attr}
>
{radios.map((item) => (
<SwitchControl key={item.value} value={item.value} text={item.title} />
))}
</Switch>
</GoalSelect>
);
};
2 changes: 1 addition & 1 deletion src/utils/domObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const userSettingsLogoutButton = userSettings.add('logoutButton');

export const goalDependencies = DO('goalDependencies');
export const goalDependenciesTrigger = goalDependencies.add('trigger');
export const goalDependenciesRadios = goalDependencies.add('radios');
export const goalDependenciesSwitch = goalDependencies.add('switch');
export const goalDependenciesInput = goalDependencies.add('input');
export const goalDependenciesSuggestions = goalDependencies.add('suggestions');
export const goalDependenciesSuggestionItemTitle = goalDependencies.add('suggestionItemTitle');
Expand Down

0 comments on commit 60efaa9

Please sign in to comment.