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

docs(components): documents mutation filter component #201 #222

Merged
merged 1 commit into from
May 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@ import { expect, fn, userEvent, waitFor } from '@storybook/test';
import type { Meta, StoryObj } from '@storybook/web-components';
import { html } from 'lit';

import { withComponentDocs } from '../../../.storybook/ComponentDocsBlock';
import { LAPIS_URL } from '../../constants';
import '../app';
import { type MutationFilterProps } from '../../preact/mutationFilter/mutation-filter';
import { withinShadowRoot } from '../withinShadowRoot.story';
import './mutation-filter-component';

const meta: Meta = {
const codeExample = String.raw`<gs-mutation-filter initialValue='["A123T"]'></gs-mutation-filter>`;

const meta: Meta<MutationFilterProps> = {
title: 'Input/Mutation filter',
component: 'gs-mutation-filter',
parameters: {
parameters: withComponentDocs({
actions: {
handles: ['gs-mutation-filter-changed', 'gs-mutation-filter-on-blur'],
},
fetchMock: {},
},
componentDocs: {
tag: 'gs-mutation-filter',
opensShadowDom: true,
expectsChildren: false,
codeExample,
},
}),
decorators: [withActions],
tags: ['autodocs'],
};

export default meta;
Expand Down
52 changes: 50 additions & 2 deletions components/src/web-components/input/mutation-filter-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,59 @@ import { MutationFilter, type SelectedMutationFilterStrings } from '../../preact
import { PreactLitAdapter } from '../PreactLitAdapter';

/**
* @fires {CustomEvent<SelectedMutationFilterStrings>} gs-mutation-filter-changed - When the mutation filter values have changed
* @fires {CustomEvent<SelectedMutationFilterStrings>} gs-mutation-filter-on-blur - When the mutation filter has lost focus
* ## Context
* This component provides an input field to specify filters for nucleotide and amino acid mutations and insertions.
*
* Input values have to be provided one at a time and submitted by pressing the Enter key or by clicking the '+' button.
* After submission, the component validates the input and fires an event with the selected mutations.
* All previously selected mutations are displayed at the input field and added to the event.
* Users can remove a mutation by clicking the 'x' button next to the mutation.
*
* Validation of the input is performed according to the following rules:
*
* Mutations have to conform to the following format: `<gene/segment>:<symbol at reference><position><Substituted symbol/Deletion>`
* - Gene/segment: The gene or segment where the mutation occurs. Must be contained in the reference genome
* (Optional for elements with only one gene/segment)
* - Symbol at reference: The symbol at the reference position. (Optional)
* - Position: The position of the mutation. (Required)
* - Substituted symbol/Deletion: The substituted symbol or '-' for a deletion. (Required)
* Example: S:614G, 614G, 614- or 614G
*
* Insertions have to conform to the following format: `ins_<gene/segment>:<position>:<Inserted symbols>`
* - Gene/segment: The gene or segment where the insertion occurs. Must be contained in the reference genome
* (Optional for elements with only one gene/segment)
* - Position: The position of the insertion. (Required)
* - Inserted symbols: The symbols that are inserted. (Required)
* Example: ins_S:614:G, ins_614:G
*
* @fires {CustomEvent<{
* nucleotideMutations: string[],
* aminoAcidMutations: string[],
* nucleotideInsertions: string[],
* aminoAcidInsertions: string[]
* }>} gs-mutation-filter-changed
* Fired when:
* - The user has submitted a valid mutation or insertion
* - The user has removed a mutation or insertion
*
* @fires {CustomEvent<{
* nucleotideMutations: string[],
* aminoAcidMutations: string[],
* nucleotideInsertions: string[],
* aminoAcidInsertions: string[]
* }>} gs-mutation-filter-on-blur
* Fired when:
* - the mutation filter has lost focus
* Contains the selected mutations in the format
*/
@customElement('gs-mutation-filter')
export class MutationFilterComponent extends PreactLitAdapter {
/**
* The initial value to use for this mutation filter.
* Must be either
* - an array of strings of valid mutations.
* - an object with the keys `nucleotideMutations`, `aminoAcidMutations`, `nucleotideInsertions` and `aminoAcidInsertions` and corresponding string arrays.
*/
@property()
initialValue: SelectedMutationFilterStrings | string[] | undefined = undefined;

Expand Down