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

Support finding samples with multiple parent matches #1391

Merged
merged 12 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions packages/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@labkey/components",
"version": "3.5.3",
"version": "3.5.4-fb-multiAncestors.1",
"description": "Components, models, actions, and utility functions for LabKey applications and pages",
"sideEffects": false,
"files": [
Expand Down
5 changes: 5 additions & 0 deletions packages/components/releaseNotes/components.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# @labkey/components
Components, models, actions, and utility functions for LabKey applications and pages.

### version 3.X
*Released*: X January 2024
- Multi-Parent Matching in Sample Finder
- TODO

### version 3.5.3
*Released*: 11 January 2024
- Language Consistency: 'My' vs. 'Your' and 'Shared' vs. 'Public'
Expand Down
10 changes: 10 additions & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ import {
import {
COLUMN_IN_FILTER_TYPE,
COLUMN_NOT_IN_FILTER_TYPE,
ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE,
IN_EXP_DESCENDANTS_OF_FILTER_TYPE,
NOT_IN_EXP_DESCENDANTS_OF_FILTER_TYPE,
getFilterLabKeySql,
isNegativeFilterType,
getLegalIdentifier,
registerFilterType,
} from './internal/query/filter';
Expand Down Expand Up @@ -493,6 +497,7 @@ import {
getJobCreationHref,
getUniqueIdColumnMetadata,
isSampleEntity,
isDataClassEntity,
sampleDeleteDependencyText,
} from './internal/components/entities/utils';
import {
Expand Down Expand Up @@ -868,6 +873,7 @@ const App = {
isCrossProjectImportEnabled,
isAllProductFoldersFilteringEnabled,
isSampleEntity,
isDataClassEntity,
getPrimaryAppProperties,
getProjectDataExclusion,
getProjectAssayDesignExclusion,
Expand Down Expand Up @@ -1038,7 +1044,11 @@ export {
registerFilterType,
COLUMN_IN_FILTER_TYPE,
COLUMN_NOT_IN_FILTER_TYPE,
ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE,
IN_EXP_DESCENDANTS_OF_FILTER_TYPE,
NOT_IN_EXP_DESCENDANTS_OF_FILTER_TYPE,
getFilterLabKeySql,
isNegativeFilterType,
getLegalIdentifier,
loadQueries,
loadQueriesFromTable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ interface Props {
field: QueryColumn;
fieldFilters: Filter.IFilter[];
onFieldFilterUpdate?: (newFilters: Filter.IFilter[], index: number) => void;
includeAllAncestorFilter?: boolean;
}

export const FilterExpressionView: FC<Props> = memo(props => {
const { allowRelativeDateFilter, field, fieldFilters, onFieldFilterUpdate, disabled } = props;
const { allowRelativeDateFilter, field, fieldFilters, onFieldFilterUpdate, disabled, includeAllAncestorFilter } =
props;

const [fieldFilterOptions, setFieldFilterOptions] = useState<FieldFilterOption[]>(undefined);
const [activeFilters, setActiveFilters] = useState<FilterSelection[]>([]);
const [removeFilterCount, setRemoveFilterCount] = useState<number>(0);
const [expandedOntologyKey, setExpandedOntologyKey] = useState<string>(undefined);

useEffect(() => {
const filterOptions = getFilterOptionsForType(field);
const filterOptions = getFilterOptionsForType(field, includeAllAncestorFilter);
setFieldFilterOptions(filterOptions);
setActiveFilters(getFilterSelections(fieldFilters, filterOptions));
}, [field]); // leave fieldFilters out of deps list, fieldFilters is used to init once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { NOT_ANY_FILTER_TYPE } from '../../url/NotAnyFilterType';

import { ComponentsAPIWrapper, getDefaultAPIWrapper } from '../../APIWrapper';

import { ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE } from '../../query/filter';

import { FilterFacetedSelector } from './FilterFacetedSelector';
import { FilterExpressionView } from './FilterExpressionView';
import { FieldFilter } from './models';
Expand Down Expand Up @@ -51,6 +53,7 @@ interface Props {
skipDefaultViewCheck?: boolean;
validFilterField?: (field: QueryColumn, queryInfo: QueryInfo, exprColumnsWithSubSelect?: string[]) => boolean;
viewName?: string;
isAncestor?: boolean;
}

export const QueryFilterPanel: FC<Props> = memo(props => {
Expand All @@ -74,6 +77,7 @@ export const QueryFilterPanel: FC<Props> = memo(props => {
hasNotInQueryFilterLabel,
altQueryName,
fields,
isAncestor,
} = props;
const [queryFields, setQueryFields] = useState<List<QueryColumn>>(undefined);
const [activeField, setActiveField] = useState<QueryColumn>(undefined);
Expand Down Expand Up @@ -195,7 +199,13 @@ export const QueryFilterPanel: FC<Props> = memo(props => {

// use active filters to filter distinct values, but exclude filters on current field
filters?.[filterQueryKey]?.forEach(field => {
if (field.fieldKey !== activeFieldKey) valueFilters.push(field.filter);
if (field.fieldKey !== activeFieldKey) {
let filter = field.filter;
// convert ancestor matches all to IN filter type for distinct value selection
if (filter.getFilterType().getURLSuffix() === ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE.getURLSuffix())
filter = Filter.create(filter.getColumnName(), filter.getValue(), Filter.Types.IN);
valueFilters.push(filter);
}
});

return valueFilters;
Expand Down Expand Up @@ -307,6 +317,9 @@ export const QueryFilterPanel: FC<Props> = memo(props => {
onFilterUpdate(activeField, newFilters, index)
}
disabled={hasNotInQueryFilter}
includeAllAncestorFilter={
isAncestor && activeField?.fieldKey.toLowerCase() === 'name'
}
/>
)}
</Tab.Pane>
Expand Down
106 changes: 99 additions & 7 deletions packages/components/src/internal/components/search/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { NOT_ANY_FILTER_TYPE } from '../../url/NotAnyFilterType';

import { SampleTypeDataType } from '../entities/constants';

import { ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE } from '../../query/filter';

import {
ALL_VALUE_DISPLAY,
decodeErrorMessage,
Expand Down Expand Up @@ -48,6 +50,31 @@ const anyValueFilter = {
jsonType: 'string',
} as FieldFilter;

const matchesAllFilter = {
fieldKey: 'textField',
fieldCaption: 'textField',
filter: Filter.create('textField', ['a', 'b'], ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE),
jsonType: 'string',
} as FieldFilter;

const matchesAllBadFilter = {
fieldKey: 'textField',
fieldCaption: 'textField',
filter: Filter.create(
'textField',
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'],
ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE
),
jsonType: 'string',
} as FieldFilter;

const matchesAllEmptyFilter = {
fieldKey: 'textField',
fieldCaption: 'textField',
filter: Filter.create('textField', [], ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE),
jsonType: 'string',
} as FieldFilter;

const intEqFilter = {
fieldKey: 'intField',
fieldCaption: 'intField',
Expand Down Expand Up @@ -162,7 +189,7 @@ describe('getFieldFiltersValidationResult', () => {
test('no error', () => {
expect(
getFieldFiltersValidationResult({
sampleType1: [anyValueFilter, stringBetweenFilter],
sampleType1: [anyValueFilter, stringBetweenFilter, matchesAllFilter],
sampleType2: [intEqFilter, floatBetweenFilter],
})
).toBeNull();
Expand Down Expand Up @@ -212,6 +239,24 @@ describe('getFieldFiltersValidationResult', () => {
)
).toEqual('Missing filter values for: sampleType1: strField; sampleType2: strField.');
});

test('empty matches all filter', () => {
expect(
getFieldFiltersValidationResult({
sampleType1: [matchesAllEmptyFilter, stringBetweenFilter],
sampleType2: [intEqFilter],
})
).toEqual('Missing filter values for: textField.');
});

test('exceed max allowed', () => {
expect(
getFieldFiltersValidationResult({
sampleType1: [matchesAllBadFilter, stringBetweenFilter],
sampleType2: [intEqFilter],
})
).toEqual("A max of 10 values can be selected for 'Equals All Of' filter type for 'textField'.");
});
});

describe('getUpdateFilterExpressionFilter', () => {
Expand Down Expand Up @@ -312,6 +357,7 @@ describe('getUpdateFilterExpressionFilter', () => {

const distinctValues = ['[All]', '[blank]', 'ed', 'ned', 'ted', 'red', 'bed'];
const distinctValuesNoBlank = ['[All]', 'ed', 'ned', 'ted', 'red', 'bed'];
const distinctValuesExcludeAll = ['[blank]', 'ed', 'ned', 'ted', 'red', 'bed'];
const fieldKey = 'thing';

const checkedOne = Filter.create(fieldKey, 'ed');
Expand All @@ -324,6 +370,10 @@ const checkedZero = Filter.create(fieldKey, null, NOT_ANY_FILTER_TYPE);
const anyFilter = Filter.create(fieldKey, null, Filter.Types.HAS_ANY_VALUE);
const blankFilter = Filter.create(fieldKey, null, Filter.Types.ISBLANK);
const notblankFilter = Filter.create(fieldKey, null, Filter.Types.NONBLANK);
const matchAllFilter = Filter.create(fieldKey, 'ed;ned;ted', ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE);
const matchAll0Filter = Filter.create(fieldKey, [], ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE);
const matchAll1Filter = Filter.create(fieldKey, 'ed', ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE);
const matchAllEveryFilter = Filter.create(fieldKey, distinctValuesExcludeAll, ANCESTOR_MATCHES_ALL_OF_FILTER_TYPE);

describe('getCheckedFilterValues', () => {
test('no filter or values', () => {
Expand Down Expand Up @@ -373,6 +423,11 @@ describe('getCheckedFilterValues', () => {
test('not in values', () => {
expect(getCheckedFilterValues(uncheckedTwo, distinctValues)).toEqual(['[blank]', 'ted', 'red', 'bed']);
});

test('ancestor matches all', () => {
expect(getCheckedFilterValues(matchAllFilter, [])).toEqual(['ed', 'ned', 'ted']);
expect(getCheckedFilterValues(matchAllFilter, distinctValues)).toEqual(['ed', 'ned', 'ted']);
});
});

describe('getUpdatedCheckedValues', () => {
Expand Down Expand Up @@ -468,11 +523,26 @@ describe('getUpdatedChooseValuesFilter', () => {

test('check ALL, from eq one', () => {
expect(getUpdatedChooseValuesFilter(distinctValues, fieldKey, ALL_VALUE_DISPLAY, true, checkedOne)).toBeNull();
validate(
getUpdatedChooseValuesFilter(distinctValues, fieldKey, ALL_VALUE_DISPLAY, true, matchAll1Filter),
'ancestormatchesallof',
distinctValuesExcludeAll
);
});

test('check another, from eq one', () => {
validate(getUpdatedChooseValuesFilter(distinctValues, fieldKey, 'ned', true, checkedOne), 'in', ['ed', 'ned']);
validate(getUpdatedChooseValuesFilter(undefined, fieldKey, 'ned', true, checkedOne), 'in', ['ed', 'ned']);
validate(
getUpdatedChooseValuesFilter(distinctValues, fieldKey, 'ned', true, matchAll1Filter),
'ancestormatchesallof',
['ed', 'ned']
);
validate(
getUpdatedChooseValuesFilter(undefined, fieldKey, 'ned', true, matchAll1Filter),
'ancestormatchesallof',
['ed', 'ned']
);
});

test('check blank, from eq one', () => {
Expand All @@ -484,6 +554,11 @@ describe('getUpdatedChooseValuesFilter', () => {

test('all checked, then uncheck one', () => {
validate(getUpdatedChooseValuesFilter(distinctValues, fieldKey, 'red', false, null), 'neqornull', 'red');
validate(
getUpdatedChooseValuesFilter(distinctValues, fieldKey, 'red', false, matchAllEveryFilter),
'ancestormatchesallof',
['', 'ed', 'ned', 'ted', 'bed']
);
});

test('two checked, then uncheck one', () => {
Expand All @@ -495,6 +570,19 @@ describe('getUpdatedChooseValuesFilter', () => {
validate(getUpdatedChooseValuesFilter(distinctValues, fieldKey, 'ed', false, checkedTwoWithBlank), 'isblank');
});

test('uncheck all', () => {
validate(
getUpdatedChooseValuesFilter(distinctValues, fieldKey, ALL_VALUE_DISPLAY, false, checkedTwo),
'notany',
null
);
validate(
getUpdatedChooseValuesFilter(distinctValues, fieldKey, ALL_VALUE_DISPLAY, false, matchAllEveryFilter),
'ancestormatchesallof',
[]
);
});

test('all checked, then uncheck blank', () => {
validate(
getUpdatedChooseValuesFilter(distinctValues, fieldKey, EMPTY_VALUE_DISPLAY, false, null),
Expand All @@ -512,6 +600,11 @@ describe('getUpdatedChooseValuesFilter', () => {
test('none checked, then check one', () => {
validate(getUpdatedChooseValuesFilter(distinctValues, fieldKey, 'ed', true, checkedZero), 'eq', 'ed');
validate(getUpdatedChooseValuesFilter(undefined, fieldKey, 'ed', true, checkedZero), 'eq', 'ed');
validate(
getUpdatedChooseValuesFilter(distinctValues, fieldKey, 'ed', true, matchAll0Filter),
'ancestormatchesallof',
['ed']
);
});

test('all checked, then check blank and uncheck everything else', () => {
Expand Down Expand Up @@ -722,13 +815,12 @@ describe('getFilterSelections', () => {
isSoleFilter: false,
},
];
const filterSelections = getFilterSelections(
[Filter.create('strField', 'test')],
filterOptions
);
expect(filterSelections).toStrictEqual([{
const filterSelections = getFilterSelections([Filter.create('strField', 'test')], filterOptions);
expect(filterSelections).toStrictEqual([
{
filterType: filterOptions[0],
}]);
},
]);
});

test('single filter, single value', () => {
Expand Down
Loading