Style filter key in bold in filter and search bar (#86)

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Charles Bochet
2023-04-27 17:28:17 +02:00
committed by GitHub
parent 00f0a36457
commit 571cb6ed5c
5 changed files with 59 additions and 13 deletions

View File

@ -51,7 +51,7 @@ function SortAndFilterBar<SortField extends string>({
return ( return (
<SortOrFilterChip <SortOrFilterChip
key={sort.key} key={sort.key}
label={sort.label} labelValue={sort.label}
id={sort.key} id={sort.key}
icon={sort.order === 'asc' ? faArrowDown : faArrowUp} icon={sort.order === 'asc' ? faArrowDown : faArrowUp}
onRemove={() => onRemoveSort(sort.key)} onRemove={() => onRemoveSort(sort.key)}
@ -62,7 +62,8 @@ function SortAndFilterBar<SortField extends string>({
return ( return (
<SortOrFilterChip <SortOrFilterChip
key={filter.id} key={filter.id}
label={`${filter.label}: ${filter.operand.label} ${filter.value}`} labelKey={filter.label}
labelValue={`${filter.operand.label} ${filter.value}`}
id={filter.id} id={filter.id}
icon={filter.icon} icon={filter.icon}
onRemove={() => onRemoveFilter(filter.id)} onRemove={() => onRemoveFilter(filter.id)}

View File

@ -5,7 +5,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
type OwnProps = { type OwnProps = {
id: string; id: string;
label: string; labelKey?: string;
labelValue: string;
icon: IconProp; icon: IconProp;
onRemove: () => void; onRemove: () => void;
}; };
@ -30,13 +31,24 @@ const StyledDelete = styled.div`
cursor: pointer; cursor: pointer;
`; `;
function SortOrFilterChip({ id, label, icon, onRemove }: OwnProps) { const StyledLabelKey = styled.div`
font-weight: 500;
`;
function SortOrFilterChip({
id,
labelKey,
labelValue,
icon,
onRemove,
}: OwnProps) {
return ( return (
<StyledChip> <StyledChip>
<StyledIcon> <StyledIcon>
<FontAwesomeIcon icon={icon} /> <FontAwesomeIcon icon={icon} />
</StyledIcon> </StyledIcon>
{label} {labelKey && <StyledLabelKey>{labelKey}:&nbsp;</StyledLabelKey>}
{labelValue}
<StyledDelete onClick={onRemove} data-testid={'remove-icon-' + id}> <StyledDelete onClick={onRemove} data-testid={'remove-icon-' + id}>
<FontAwesomeIcon icon={faTimes} /> <FontAwesomeIcon icon={faTimes} />
</StyledDelete> </StyledDelete>

View File

@ -1,7 +1,7 @@
import SortOrFilterChip from '../SortOrFilterChip'; import SortOrFilterChip from '../SortOrFilterChip';
import { ThemeProvider } from '@emotion/react'; import { ThemeProvider } from '@emotion/react';
import { lightTheme } from '../../../../layout/styles/themes'; import { lightTheme } from '../../../../layout/styles/themes';
import { faArrowDown } from '@fortawesome/pro-regular-svg-icons'; import { faArrowDown, faPeople } from '@fortawesome/pro-regular-svg-icons';
const component = { const component = {
title: 'SortOrFilterChip', title: 'SortOrFilterChip',
@ -14,13 +14,27 @@ type OwnProps = {
removeFunction: () => void; removeFunction: () => void;
}; };
export const RegularSortOrFilterChip = ({ removeFunction }: OwnProps) => { export const RegularFilterChip = ({ removeFunction }: OwnProps) => {
return ( return (
<ThemeProvider theme={lightTheme}> <ThemeProvider theme={lightTheme}>
<SortOrFilterChip <SortOrFilterChip
id="test_sort" id="test_sort"
icon={faArrowDown} icon={faPeople}
label="Test sort" labelKey="Account owner"
labelValue="is Charles"
onRemove={removeFunction}
/>
</ThemeProvider>
);
};
export const RegularSortChip = ({ removeFunction }: OwnProps) => {
return (
<ThemeProvider theme={lightTheme}>
<SortOrFilterChip
id="test_sort"
icon={faArrowDown}
labelValue="Created at"
onRemove={removeFunction} onRemove={removeFunction}
/> />
</ThemeProvider> </ThemeProvider>

View File

@ -1,14 +1,29 @@
import { fireEvent, render } from '@testing-library/react'; import { fireEvent, render } from '@testing-library/react';
import { RegularSortOrFilterChip } from '../__stories__/SortOrFilterChip.stories'; import {
RegularFilterChip,
RegularSortChip,
} from '../__stories__/SortOrFilterChip.stories';
const removeFunction = jest.fn(); const removeFunction = jest.fn();
it('Checks the RegularSortOrFilterChip renders', async () => { it('Checks the filter chip renders', async () => {
const { getByText, getByTestId } = render( const { getByText, getByTestId } = render(
<RegularSortOrFilterChip removeFunction={removeFunction} />, <RegularFilterChip removeFunction={removeFunction} />,
); );
expect(getByText('Test sort')).toBeDefined(); expect(getByText('Account owner:')).toBeDefined();
const removeIcon = getByTestId('remove-icon-test_sort');
fireEvent.click(removeIcon);
expect(removeFunction).toHaveBeenCalled();
});
it('Checks the sort chip renders', async () => {
const { getByText, getByTestId } = render(
<RegularSortChip removeFunction={removeFunction} />,
);
expect(getByText('Created at')).toBeDefined();
const removeIcon = getByTestId('remove-icon-test_sort'); const removeIcon = getByTestId('remove-icon-test_sort');
fireEvent.click(removeIcon); fireEvent.click(removeIcon);

View File

@ -1,11 +1,15 @@
#!/bin/bash #!/bin/bash
graphql-engine serve & graphql-engine serve &
echo "Waiting for Hasura to be ready..."
while ! curl -s http://localhost:8080/healthz > /dev/null ; do while ! curl -s http://localhost:8080/healthz > /dev/null ; do
sleep 1 sleep 1
echo "Waiting for Hasura to be ready..."
done done
sleep 1
hasura deploy hasura deploy
socat TCP-LISTEN:9695,fork,reuseaddr,bind=twenty-hasura TCP:127.0.0.1:9695 & socat TCP-LISTEN:9695,fork,reuseaddr,bind=twenty-hasura TCP:127.0.0.1:9695 &