-
Notifications
You must be signed in to change notification settings - Fork 369
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
feat: Added trigger grouping methods to indexers #4413
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b5e6c2
Added trigger grouping methods to indexers
GeoffCoxMSFT 4dae372
Merge branch 'main' into gcox/groupTriggers
GeoffCoxMSFT 8d8ed7d
Merge branch 'main' into gcox/groupTriggers
GeoffCoxMSFT d60ec82
Fix bug and build issue
GeoffCoxMSFT 1af7cfd
Merge branch 'main' into gcox/groupTriggers
GeoffCoxMSFT 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
22 changes: 22 additions & 0 deletions
22
Composer/packages/lib/indexers/src/extractSchemaProperties.ts
This file contains 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,22 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { DialogInfo, JsonSchemaFile } from '@bfc/shared'; | ||
|
||
import { getBaseName } from './utils/help'; | ||
|
||
export const extractSchemaProperties = (dialog: DialogInfo, jsonSchemaFiles: JsonSchemaFile[]): string[] => { | ||
if (dialog.content?.schema) { | ||
const schema = jsonSchemaFiles.find( | ||
(file) => file.id === getBaseName(dialog.content.schema) || file.id === dialog.content.schema | ||
)?.content; | ||
if (schema?.$public && Array.isArray(schema.$public)) { | ||
return schema.$public; | ||
} | ||
if (schema?.properties) { | ||
return Object.keys(schema.properties) ?? []; | ||
} | ||
} | ||
|
||
return []; | ||
}; |
This file contains 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,80 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { DialogInfo, ITrigger } from '@bfc/shared'; | ||
import { ExpressionParser } from 'adaptive-expressions'; | ||
import uniq from 'lodash/uniq'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const getPropertyReferences = (content: any) => { | ||
const foundProperties: string[] = []; | ||
|
||
if (content) { | ||
// has $designer: { "propertyGroups": ["<name1>", "<name2", ... ] | ||
if (content.$designer?.propertyGroups && Array.isArray(content.$designer?.propertyGroups === 'array')) { | ||
foundProperties.push(...content.$designer.propertyGroups); | ||
} | ||
|
||
// has "property": "<name>" | ||
if (content.property && typeof content.property === 'string') { | ||
foundProperties.push(content.property); | ||
} | ||
|
||
// has condition : "<expresssion referencing properties>" | ||
if (content.condition) { | ||
const expressionParser = new ExpressionParser(); | ||
const expression = expressionParser.parse(content.condition); | ||
const references = expression.references().map((r) => (r.startsWith('$') ? r.substring(1) : r)); | ||
foundProperties.push(...references); | ||
} | ||
} | ||
|
||
return uniq(foundProperties); | ||
}; | ||
|
||
const getTriggerPropertyReferences = (trigger: ITrigger) => { | ||
const content = trigger.content; | ||
|
||
// inspect trigger | ||
const foundProperties: string[] = getPropertyReferences(trigger.content); | ||
|
||
// inspect actions | ||
if (content.actions && Array.isArray(content.actions)) { | ||
for (let i = 0; i < content.actions.length; i++) { | ||
foundProperties.push(...getPropertyReferences(content.actions[i])); | ||
} | ||
} | ||
|
||
return uniq(foundProperties); | ||
}; | ||
|
||
export const groupTriggersByPropertyReference = ( | ||
dialog: DialogInfo, | ||
options?: { allowMultiParent?: boolean; validProperties?: string[] } | ||
): Record<string, ITrigger[]> => { | ||
const result = {} as Record<string, ITrigger[]>; | ||
|
||
const validProperties = options?.validProperties; | ||
const isValidProperty = validProperties | ||
? (x: string | undefined) => x && validProperties.findIndex((p) => x === p) !== -1 | ||
: () => true; | ||
|
||
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); | ||
if (properties.length > 1 && options?.allowMultiParent) { | ||
properties.forEach((p) => { | ||
addResult(p, t); | ||
}); | ||
} else if (properties.length === 1) { | ||
addResult(properties[0], t); | ||
} | ||
}); | ||
} | ||
|
||
return result; | ||
}; |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a cast here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build caught that too :) Fortunately, it helped me find another missing case to handle.