@genspectrum/dashboard-components 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,57 +0,0 @@
1
- import { type StoryObj } from '@storybook/preact';
2
- import { expect, fn, userEvent, waitFor, within } from '@storybook/test';
3
- import { type Meta } from '@storybook/web-components';
4
- import { useState } from 'preact/hooks';
5
-
6
- import { MutationsOverTimeTextFilter, type TextFilterProps } from './mutations-over-time-text-filter';
7
-
8
- const meta: Meta = {
9
- title: 'Component/Mutations over time text filter',
10
- component: 'MutationsOverTimeTextFilter',
11
- parameters: { fetchMock: {} },
12
- };
13
-
14
- export default meta;
15
-
16
- const WrapperWithState = ({ setFilterValue, value }: { setFilterValue: (value: string) => void; value: string }) => {
17
- const [state, setState] = useState(value);
18
-
19
- return (
20
- <MutationsOverTimeTextFilter
21
- setFilterValue={(value) => {
22
- setFilterValue(value);
23
- setState(value);
24
- }}
25
- value={state}
26
- />
27
- );
28
- };
29
-
30
- export const MutationsOverTimeTextFilterStory: StoryObj<TextFilterProps> = {
31
- render: (args) => {
32
- return <WrapperWithState setFilterValue={args.setFilterValue} value={args.value} />;
33
- },
34
- args: {
35
- setFilterValue: fn(),
36
- value: 'Test',
37
- },
38
- play: async ({ canvasElement, step }) => {
39
- const canvas = within(canvasElement);
40
-
41
- await step('Expect initial value to show on the button', async () => {
42
- const button = canvas.getByRole('button');
43
- await expect(button).toHaveTextContent('Test');
44
- });
45
-
46
- await step('Change filter and expect it to show on the button', async () => {
47
- const button = canvas.getByRole('button');
48
- await userEvent.click(button);
49
-
50
- const inputField = canvas.getByRole('textbox');
51
- await userEvent.clear(inputField);
52
- await userEvent.type(inputField, 'OtherText');
53
-
54
- await waitFor(() => expect(button).toHaveTextContent('OtherText'));
55
- });
56
- },
57
- };
@@ -1,63 +0,0 @@
1
- import type { h } from 'preact';
2
- import { useCallback, useEffect, useState } from 'preact/hooks';
3
-
4
- import { Dropdown } from './dropdown';
5
- import { DeleteIcon } from '../shared/icons/DeleteIcon';
6
-
7
- export type TextFilterProps = { setFilterValue: (newValue: string) => void; value: string };
8
-
9
- export function MutationsOverTimeTextFilter({ setFilterValue, value }: TextFilterProps) {
10
- const onInput = (newValue: string) => {
11
- setFilterValue(newValue);
12
- };
13
-
14
- const onDeleteClick = () => setFilterValue('');
15
-
16
- return (
17
- <div className={'w-28 inline-flex'}>
18
- <Dropdown buttonTitle={value === '' ? `Filter mutations` : value} placement={'bottom-start'}>
19
- <div>
20
- <label className='flex gap-1 input input-xs'>
21
- <DebouncedInput placeholder={'Filter'} onInput={onInput} value={value} type='text' />
22
- {value !== undefined && value !== '' && (
23
- <button className={'cursor-pointer'} onClick={onDeleteClick}>
24
- <DeleteIcon />
25
- </button>
26
- )}
27
- </label>
28
- </div>
29
- </Dropdown>
30
- </div>
31
- );
32
- }
33
-
34
- function DebouncedInput({
35
- value: initialValue,
36
- onInput,
37
- debounce = 500,
38
- ...props
39
- }: {
40
- onInput: (value: string) => void;
41
- debounce?: number;
42
- value?: string;
43
- } & Omit<h.JSX.IntrinsicElements['input'], 'onInput'>) {
44
- const [value, setValue] = useState<string | undefined>(initialValue);
45
-
46
- useEffect(() => {
47
- setValue(initialValue);
48
- }, [initialValue]);
49
-
50
- useEffect(() => {
51
- const timeout = setTimeout(() => {
52
- onInput(value ?? '');
53
- }, debounce);
54
-
55
- return () => clearTimeout(timeout);
56
- }, [value, debounce, onInput]);
57
-
58
- const onChangeInput = useCallback((event: h.JSX.TargetedEvent<HTMLInputElement>) => {
59
- setValue(event.currentTarget.value);
60
- }, []);
61
-
62
- return <input {...props} value={value} onInput={onChangeInput} />;
63
- }