-
Notifications
You must be signed in to change notification settings - Fork 2
Automatic Hit Selection #1649
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
Merged
Merged
Automatic Hit Selection #1649
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
4b668b5
Fix unique key warnings in domain designer
labkey-alan c026642
CLean up filter panel styles
labkey-alan 07bc2b0
Add HitCriteriaRenderer
labkey-alan 27275cc
Add HitCriteriaModal and useLoadableState
labkey-alan 2db3dd8
Render HitCriteria
labkey-alan 34a69e1
Update release notes
labkey-alan 6cbdf4d
FilterExpressionView: memoize callbacks
labkey-alan 12c29dd
AssayDesignerPanels: Fix issue with appDomainHeaders, fix tests
labkey-alan 8a36111
Cleanup
labkey-alan 477abce
Prevent serialization of "hitCriteria" (stop gap)
labkey-nicka ec826a8
Bump @labkey/api
labkey-alan 27f15a3
Add request util
labkey-alan db6e8cc
Add getFilterCriteriaColumns to assay API wrapper
labkey-alan 3673d93
Update AssayDesigner to assume filterCriteria is on DomainFields
labkey-alan 51cde56
Remove protocolModel from FilterCriteriaContext
labkey-alan c5525a5
Remove hack
labkey-alan 647dc82
FilterCriteriaModal - use propertyIds
labkey-alan fa55e1b
request: Add RequesstHandler
labkey-alan 50474a1
Fix styling for FilterCriteriaRenderer
labkey-alan fcbae9b
Update filter criteria when field name changes
labkey-alan 86f32c9
FilterCriteriaModal: make FilterCriteriaMap a JS map
labkey-alan 00f0d30
Export FilterCriteriaRenderer
labkey-alan 289cc78
FilterCriteriaRenderer: optionally render empty message
labkey-alan 4523a5b
Fix styling for hit-criteria-renderer
labkey-alan 1ea2733
Fix styling for FilterCriteriaRenderer
labkey-alan 639e6ed
Fix class names
labkey-alan 8c31f1f
FilterCriteriaModal: Add empty messages
labkey-alan da1d015
AssayDesignerPanels: Fix issue with saveFilterCriteria
labkey-alan 2eb323b
FilterCriteriaModal: Give reference properties stable propertyId values
labkey-alan b25223c
FilterCriteriaModal: filter fields to openTo and related
labkey-alan e661f82
DomainField.serialize - Don't change propertyId or referencePropertyI…
labkey-alan e592956
AssayPropertiesInput: Disable Edit Criteria button when plate metadat…
labkey-alan b6c08fa
AssayDesignerPanels: Hide field "edit criteria" buttons when plate me…
labkey-alan b31be71
FilterCriteriaModal.tsx: Fix issue with empty fields
labkey-alan 3fe7883
Bump api-js
labkey-alan f064bab
request.ts - Fix types
labkey-alan ccc8319
models.test.ts - Fix tests
labkey-alan 60291fa
Address PR feedback
labkey-alan 6371595
DomainForm: Move toolbar code to separate component
labkey-alan a835870
Add filterCriteriaToStr
labkey-alan aa8152a
DomainPropertiesGrid: optionally render Filter Criteria
labkey-alan dfa689b
AssayDesignerPanels.tsx: fix issue with header prefix
labkey-alan fedfed0
PlateMetadataInput - Only render filter criteria for valid fields
labkey-alan b761f5d
FilterCriteriaModal: fix issues
labkey-alan 6d59d93
Bump api-js
labkey-alan 3885d59
Prep for release
labkey-alan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
packages/components/src/internal/FilterCriteriaModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| import React, { FC, memo, useCallback, useMemo, useState } from 'react'; | ||
|
|
||
| import { Filter } from '@labkey/api'; | ||
|
|
||
| import { isLoading } from '../public/LoadingState'; | ||
|
|
||
| import { QueryColumn } from '../public/QueryColumn'; | ||
|
|
||
| import { Modal } from './Modal'; | ||
| import { DomainDesign, FilterCriteria, FilterCriteriaMap } from './components/domainproperties/models'; | ||
| import { useLoadableState } from './useLoadableState'; | ||
| import { LoadingSpinner } from './components/base/LoadingSpinner'; | ||
| import { ChoicesListItem } from './components/base/ChoicesListItem'; | ||
| import { FilterExpressionView } from './components/search/FilterExpressionView'; | ||
| import { useAppContext } from './AppContext'; | ||
| import { FilterCriteriaColumns } from './components/assay/models'; | ||
| import { AssayProtocolModel } from './components/domainproperties/assay/models'; | ||
| import { Alert } from './components/base/Alert'; | ||
|
|
||
| type BaseFilterCriteriaField = Omit<FilterCriteria, 'op' | 'value'>; | ||
| interface FilterCriteriaField extends BaseFilterCriteriaField { | ||
| isKeyField: boolean; | ||
| jsonType: string; | ||
| } | ||
| type FieldLoader = () => Promise<FilterCriteriaField[]>; | ||
| type ReferenceFieldLoader = ( | ||
| protocolId: number, | ||
| columnNames: string[], | ||
| containerPath: string | ||
| ) => Promise<FilterCriteriaColumns>; | ||
|
|
||
| function fieldLoaderFactory( | ||
| protocolId: number, | ||
| container: string, | ||
| domain: DomainDesign, | ||
| load: ReferenceFieldLoader | ||
| ): FieldLoader { | ||
| return async () => { | ||
| const sourceFields = domain.fields | ||
| .filter(field => field.isFilterCriteriaField()) | ||
| .map(field => field.name) | ||
| .toArray(); | ||
| // The API returns an error if you don't pass any fields, so we can skip the API request | ||
| if (sourceFields.length === 0) return []; | ||
| const referenceFields = await load(protocolId, sourceFields, container); | ||
|
|
||
| return Object.keys(referenceFields).reduce<FilterCriteriaField[]>((result, sourceName) => { | ||
| const sourceField = domain.fields.find(field => field.name === sourceName); | ||
| result.push({ | ||
| propertyId: sourceField.propertyId, | ||
| isKeyField: sourceField.isPrimaryKey || sourceField.isUniqueIdField(), | ||
| jsonType: sourceField.dataType.getJsonType(), | ||
| name: sourceField.name, | ||
| }); | ||
| return result.concat( | ||
| referenceFields[sourceName].map((field, index) => ({ | ||
| isKeyField: false, | ||
| jsonType: field.dataType.getJsonType(), | ||
| name: field.name, | ||
| propertyId: field.propertyId === 0 ? sourceField.propertyId * 100 + index : field.propertyId, | ||
| referencePropertyId: sourceField.propertyId, | ||
| })) | ||
| ); | ||
| }, []); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * openTo: The propertyId of the domain field you want to open the modal to | ||
| */ | ||
| interface Props { | ||
| onClose: () => void; | ||
| onSave: (filterCriteria: FilterCriteriaMap) => void; | ||
| openTo?: number; | ||
| protocolModel: AssayProtocolModel; | ||
| } | ||
|
|
||
| export const FilterCriteriaModal: FC<Props> = memo(({ onClose, onSave, openTo, protocolModel }) => { | ||
| const { api } = useAppContext(); | ||
| const { protocolId, container } = protocolModel; | ||
| const domain = useMemo(() => protocolModel.getDomainByNameSuffix('Data'), [protocolModel]); | ||
| const [filterCriteria, setFilterCriteria] = useState<FilterCriteriaMap>(() => { | ||
| return domain.fields.reduce((result, field) => { | ||
| if (field.filterCriteria) result.set(field.propertyId, [...field.filterCriteria]); | ||
| return result; | ||
| }, new Map<number, FilterCriteria[]>()); | ||
| }); | ||
| const loader = useMemo( | ||
| () => fieldLoaderFactory(protocolId, container, domain, api.assay.getFilterCriteriaColumns), | ||
| [api.assay.getFilterCriteriaColumns, container, domain, protocolId] | ||
| ); | ||
| const { error, loadingState, value: filterCriteriaFields } = useLoadableState<FilterCriteriaField[]>(loader); | ||
| // If we're opening the modal to a specific field we only want to show that field and any related fields | ||
| const fieldsToRender = useMemo( | ||
| () => | ||
| filterCriteriaFields?.filter( | ||
| field => openTo === undefined || field.propertyId === openTo || field.referencePropertyId === openTo | ||
| ), | ||
| [filterCriteriaFields, openTo] | ||
| ); | ||
| const [selectedFieldId, setSelectedFieldId] = useState<number>(openTo); | ||
|
|
||
| const onSelect = useCallback((idx: number) => setSelectedFieldId(fieldsToRender[idx].propertyId), [fieldsToRender]); | ||
|
|
||
| const onFieldFilterUpdate = useCallback( | ||
| (newFilters: Filter.IFilter[]) => { | ||
| setFilterCriteria(current => { | ||
| const filterCriteriaField = filterCriteriaFields.find(field => field.propertyId === selectedFieldId); | ||
| // Use the referencePropertyId if it exists, because all filterCriteria are stored on the parent field | ||
| const sourcePropertyId = filterCriteriaField.referencePropertyId ?? filterCriteriaField.propertyId; | ||
| // Remove the existing filter criteria for the filterCriteriaField | ||
| const existingValues = current | ||
| .get(sourcePropertyId) | ||
| .filter(value => value.propertyId !== filterCriteriaField.propertyId); | ||
| const newValues = newFilters.map(filter => ({ | ||
| name: filterCriteriaField.name, | ||
| op: filter.getFilterType().getURLSuffix(), | ||
| propertyId: filterCriteriaField.propertyId, | ||
| referencePropertyId: filterCriteriaField.referencePropertyId, | ||
| value: filter.getValue(), | ||
| })); | ||
| const updated = new Map(current); | ||
| updated.set(sourcePropertyId, existingValues.concat(newValues)); | ||
| return updated; | ||
| }); | ||
| }, | ||
| [filterCriteriaFields, selectedFieldId] | ||
| ); | ||
|
|
||
| const onConfirm = useCallback(() => onSave(filterCriteria), [filterCriteria, onSave]); | ||
|
|
||
| const fieldFilters = useMemo(() => { | ||
| const filterCriteriaField = filterCriteriaFields?.find(field => field.propertyId === selectedFieldId); | ||
|
|
||
| if (!filterCriteriaField) return undefined; | ||
|
|
||
| const sourcePropertyId = filterCriteriaField.referencePropertyId ?? filterCriteriaField.propertyId; | ||
| return filterCriteria | ||
| .get(sourcePropertyId) | ||
| .filter(value => value.propertyId === filterCriteriaField.propertyId) | ||
| .map(fc => Filter.create(fc.name, fc.value, Filter.Types[fc.op.toUpperCase()])); | ||
| }, [filterCriteriaFields, filterCriteria, selectedFieldId]); | ||
|
|
||
| const currentColumn: QueryColumn = useMemo(() => { | ||
| const currentField = filterCriteriaFields?.find(field => field.propertyId === selectedFieldId); | ||
| if (currentField === undefined) return undefined; | ||
|
|
||
| return new QueryColumn({ | ||
| caption: currentField.name, | ||
| fieldKey: currentField.name, | ||
| isKeyField: currentField.isKeyField, | ||
| jsonType: currentField.jsonType, | ||
| }); | ||
| }, [filterCriteriaFields, selectedFieldId]); | ||
|
|
||
| const loading = isLoading(loadingState); | ||
| const hasFields = fieldsToRender !== undefined && fieldsToRender.length > 0; | ||
|
|
||
| return ( | ||
| <Modal bsSize="lg" title="Hit Selection Criteria" onCancel={onClose} onConfirm={onConfirm} confirmText="Apply"> | ||
| {loading && <LoadingSpinner />} | ||
| {!loading && !error && ( | ||
| <div className="filter-criteria-modal-body field-modal__container row"> | ||
| <div className="col-sm-4 field-modal__col"> | ||
| <div className="field-modal__col-title">Fields</div> | ||
| <div className="field-modal__col-content"> | ||
| <div className="list-group"> | ||
| {!hasFields && ( | ||
| <div className="field-modal__empty-msg padding">No fields defined yet.</div> | ||
| )} | ||
| {fieldsToRender?.map((field, index) => ( | ||
| <ChoicesListItem | ||
| active={fieldsToRender[index].propertyId === selectedFieldId} | ||
| index={index} | ||
| key={field.name} | ||
| label={field.name} | ||
| onSelect={onSelect} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div className="col-sm-8 field-modal__col"> | ||
| <div className="field-modal__col-title">Filter Criteria</div> | ||
| <div className="field-modal__col-content field-modal__values"> | ||
| {!currentColumn && <div className="field-modal__empty-msg">Select a field.</div>} | ||
| {currentColumn && ( | ||
| <FilterExpressionView | ||
| field={currentColumn} | ||
| fieldFilters={fieldFilters} | ||
| onFieldFilterUpdate={onFieldFilterUpdate} | ||
| /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| )} | ||
| <Alert>{error}</Alert> | ||
| </Modal> | ||
| ); | ||
| }); |
49 changes: 49 additions & 0 deletions
49
packages/components/src/internal/FilterCriteriaRenderer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import React, { FC, memo, useMemo } from 'react'; | ||
|
|
||
| import { DomainField, filterCriteriaToStr } from './components/domainproperties/models'; | ||
|
|
||
| interface FieldWithCriteria { | ||
| field: DomainField; | ||
| } | ||
|
|
||
| const FilterCriteriaField: FC<FieldWithCriteria> = memo(({ field }) => { | ||
| return ( | ||
| <> | ||
| {field.filterCriteria.map(criteria => ( | ||
| <li className="hit-criteria-renderer__field-value" key={criteria.name + criteria.op + criteria.value}> | ||
| {filterCriteriaToStr(criteria)} | ||
| </li> | ||
| ))} | ||
| </> | ||
| ); | ||
| }); | ||
| FilterCriteriaField.displayName = 'FilterCriteriaField'; | ||
|
|
||
| interface Props { | ||
| fields: DomainField[]; | ||
| renderEmptyMessage?: boolean; | ||
| } | ||
|
|
||
| export const FilterCriteriaRenderer: FC<Props> = memo(({ fields, renderEmptyMessage = true }) => { | ||
| const fieldsWithCriteria = useMemo( | ||
| () => fields.filter(field => field.filterCriteria && field.filterCriteria.length > 0), | ||
| [fields] | ||
| ); | ||
| const showEmptyMessage = fieldsWithCriteria.length === 0 && renderEmptyMessage; | ||
|
|
||
| return ( | ||
| <div className="filter-criteria-renderer"> | ||
| {showEmptyMessage && ( | ||
| <div className="gray-text"> | ||
| <em>No Hit Selection Criteria</em> | ||
| </div> | ||
| )} | ||
| <ul> | ||
| {fieldsWithCriteria.map(field => ( | ||
| <FilterCriteriaField field={field} key={field.propertyId} /> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| }); | ||
| FilterCriteriaRenderer.displayName = 'FilterCriteriaRenderer'; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.