Skip to content

Commit

Permalink
Wire up a viewFilter for SRT
Browse files Browse the repository at this point in the history
  • Loading branch information
jernestmyers committed Sep 25, 2023
1 parent 6371ee4 commit cd4c3e9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import React from 'react';
import {
RadioList,
NumberSelector,
Checkbox,
} from '@veupathdb/wdk-client/lib/Components';
import { ComponentsList } from './SequenceFormElements';
import * as ComponentUtils from '@veupathdb/wdk-client/lib/Utils/ComponentUtils';
import * as ReporterUtils from '@veupathdb/wdk-client/lib/Views/ReporterForm/reporterUtils';
import './ReporterForms.scss';

const SINGLE_TRANSCRIPT_VIEW_FILTER_VALUE = {
name: 'representativeTranscriptOnly',
value: {},
};

const util = Object.assign({}, ComponentUtils, ReporterUtils);

const deflineFieldOptions = [
Expand Down Expand Up @@ -79,9 +85,27 @@ const createSequenceForm = (
reportType
) => {
const Form = (props) => {
const { formState, updateFormState, onSubmit, includeSubmit } = props;
const {
formState,
updateFormState,
onSubmit,
includeSubmit,
viewFilters,
updateViewFilters,
} = props;
const getUpdateHandler = (fieldName) =>
util.getChangeHandler(fieldName, updateFormState, formState);
const transcriptPerGeneChangeHandler = (isChecked) => {
const nextViewFilters =
viewFilters?.filter(
(filterValue) =>
filterValue.name !== SINGLE_TRANSCRIPT_VIEW_FILTER_VALUE.name
) ?? [];
if (isChecked) {
nextViewFilters.push(SINGLE_TRANSCRIPT_VIEW_FILTER_VALUE);
}
updateViewFilters(nextViewFilters);
};
return (
<div>
{formBeforeCommonOptions(props)}
Expand All @@ -95,6 +119,22 @@ const createSequenceForm = (
/>
</div>
{reportType === 'Sequences' && sequenceOptions(props)}
<h3>Additional options:</h3>
<div style={{ marginLeft: '1.5em' }}>
<label>
<Checkbox
value={
viewFilters?.some(
(f) => f.name === SINGLE_TRANSCRIPT_VIEW_FILTER_VALUE.name
) ?? false
}
onChange={transcriptPerGeneChangeHandler}
/>
<span style={{ marginLeft: '0.5em' }}>
Include only one transcript per gene (the longest)
</span>
</label>
</div>
{includeSubmit && (
<div style={{ margin: '0.8em' }}>
<button className="btn" type="submit" onClick={onSubmit}>
Expand All @@ -107,18 +147,20 @@ const createSequenceForm = (
);
};

Form.getInitialState = () => ({
formState: {
attachmentType: 'plain',
deflineType: 'full',
// QUESTION: should I remove this from formState when form is submitted or should backend expect this field?
deflineFields: ['gene_id'],
sequenceFormat: 'fixed_width',
basesPerLine: 60,
...getFormInitialState(),
},
formUiState: {},
});
Form.getInitialState = () => {
return {
formState: {
attachmentType: 'plain',
deflineType: 'full',
// QUESTION: should I remove this from formState when form is submitted or should backend expect this field?
deflineFields: ['gene_id'],
sequenceFormat: 'fixed_width',
basesPerLine: 60,
...getFormInitialState(),
},
formUiState: {},
};
};
return Form;
};
export default createSequenceForm;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { connect } from 'react-redux';
import { useWdkServiceWithRefresh } from '@veupathdb/wdk-client/lib/Hooks/WdkServiceHook';

import {
isTranscripFilterEnabled,
isTranscriptFilterEnabled,
requestTranscriptFilterUpdate,
isInBasketFilterEnabled,
} from '../../util/transcriptFilters';
Expand Down Expand Up @@ -137,7 +137,7 @@ function TranscriptViewFilter({

const ConnectedTranscriptViewFilter = connect(
(state, props) => ({
isEnabled: isTranscripFilterEnabled(state, { viewId: props.viewId }),
isEnabled: isTranscriptFilterEnabled(state, { viewId: props.viewId }),
inBasketFilterEnabled: isInBasketFilterEnabled(state, {
viewId: props.viewId,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const isFilter = (filter) =>
const isNotFilter = negate(isFilter);

// selector to determine if filter is enabled
export function isTranscripFilterEnabled(state, props) {
export function isTranscriptFilterEnabled(state, props) {
const viewFilters = get(
[
'resultTableSummaryView',
Expand Down

0 comments on commit cd4c3e9

Please sign in to comment.