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

fix: Filter property names, not trigger #4540

Merged
merged 3 commits into from
Oct 27, 2020
Merged
Changes from 1 commit
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
12 changes: 5 additions & 7 deletions Composer/packages/lib/indexers/src/groupTriggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const getPropertyReferences = (content: any) => {
return uniq(foundProperties);
};

const getTriggerPropertyReferences = (trigger: ITrigger) => {
const getTriggerPropertyReferences = (trigger: ITrigger, isValidProperty: (name: string) => boolean) => {
const content = trigger.content;

// inspect trigger
Expand All @@ -52,7 +52,7 @@ const getTriggerPropertyReferences = (trigger: ITrigger) => {
}
}

const result = uniq(foundProperties);
const result = uniq(foundProperties).filter(isValidProperty);

if (result.length === 0) {
return [NoGroupingTriggerGroupName];
Expand All @@ -76,18 +76,16 @@ export const groupTriggersByPropertyReference = (
): Record<string, ITrigger[]> => {
const result = {} as Record<string, ITrigger[]>;

const validProperties = options?.validProperties;
const isValidProperty = validProperties
? (x: string | undefined) => x && (x === NoGroupingTriggerGroupName || validProperties.includes(x))
: () => true;
const isValidProperty = (name: string) =>
!options?.validProperties || name === NoGroupingTriggerGroupName || options?.validProperties.includes(name);

const addResult = (property: string, trigger: ITrigger) => {
result[property] ? result[property].push(trigger) : (result[property] = [trigger]);
};

if (dialog?.triggers) {
dialog.triggers.forEach((t) => {
const properties = getTriggerPropertyReferences(t).filter(isValidProperty);
const properties = getTriggerPropertyReferences(t, isValidProperty);
if (properties.length > 1 && options?.allowMultiParent) {
properties.forEach((p) => {
addResult(p, t);
Expand Down