Skip to content

Commit

Permalink
feat: Remove input LU when deconstructing prompts (#2180)
Browse files Browse the repository at this point in the history
* feat: Remove input LU when deconstructing prompts

* Fixed lint issue

Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
tdurnford and cwhitten authored Mar 6, 2020
1 parent c17b59e commit ae6111e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const ObiEditor: FC<ObiEditorProps> = ({
}): JSX.Element | null => {
let divRef;

const { focusedId, focusedEvent, clipboardActions, copyLgTemplate, removeLgTemplates } = useContext(
const { focusedId, focusedEvent, clipboardActions, copyLgTemplate, removeLgTemplates, removeLuIntent } = useContext(
NodeRendererContext
);

Expand All @@ -59,6 +59,10 @@ export const ObiEditor: FC<ObiEditorProps> = ({
return removeLgTemplates(lgFileId, normalizedLgTemplates);
};

const deleteLuIntents = (luIntents: string[]) => {
return Promise.all(luIntents.map(intent => removeLuIntent(path, intent)));
};

const dispatchEvent = (eventName: NodeEventTypes, eventData: any): any => {
let handler;
switch (eventName) {
Expand All @@ -80,7 +84,7 @@ export const ObiEditor: FC<ObiEditorProps> = ({
break;
case NodeEventTypes.Delete:
handler = e => {
onChange(deleteNode(data, e.id, node => deleteAction(node, deleteLgTemplates)));
onChange(deleteNode(data, e.id, node => deleteAction(node, deleteLgTemplates, deleteLuIntents)));
onFocusSteps([]);
};
break;
Expand Down Expand Up @@ -138,7 +142,9 @@ export const ObiEditor: FC<ObiEditorProps> = ({
break;
case NodeEventTypes.DeleteSelection:
handler = e => {
const dialog = deleteNodes(data, e.actionIds, nodes => deleteActions(nodes, deleteLgTemplates));
const dialog = deleteNodes(data, e.actionIds, nodes =>
deleteActions(nodes, deleteLgTemplates, deleteLuIntents)
);
onChange(dialog);
onFocusSteps([]);
};
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/extensions/visual-designer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
copyLgTemplate,
removeLgTemplate,
removeLgTemplates,
removeLuIntent,
undo,
redo,
} = shellApi;
Expand All @@ -78,6 +79,7 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
copyLgTemplate,
removeLgTemplate,
removeLgTemplates,
removeLuIntent,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type ShellApiFuncs =
| 'copyLgTemplate'
| 'removeLgTemplate'
| 'removeLgTemplates'
| 'updateLgTemplate';
| 'updateLgTemplate'
| 'removeLuIntent';

interface NodeRendererContextValue extends Pick<ShellApi, ShellApiFuncs> {
focusedId?: string;
Expand All @@ -28,4 +29,5 @@ export const NodeRendererContext = React.createContext<NodeRendererContextValue>
removeLgTemplate: () => Promise.resolve(),
removeLgTemplates: () => Promise.resolve(),
updateLgTemplate: () => Promise.resolve(),
removeLuIntent: () => Promise.resolve(),
});
36 changes: 34 additions & 2 deletions Composer/packages/lib/shared/src/deleteUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,51 @@ const collectLgTemplates = (action: any, outputTemplates: string[]) => {
}
};

export const deleteAdaptiveAction = (data: MicrosoftIDialog, deleteLgTemplates: (lgTemplates: string[]) => any) => {
const collectLuIntents = (action: any, outputTemplates: string[]) => {
if (typeof action === 'string') return;
if (!action || !action.$type) return;

switch (action.$type) {
case SDKTypes.AttachmentInput:
case SDKTypes.ChoiceInput:
case SDKTypes.ConfirmInput:
case SDKTypes.DateTimeInput:
case SDKTypes.NumberInput:
case SDKTypes.TextInput: {
const [, promptType] = action.$type.split('.');
const intentName = `${promptType}.response-${action?.$designer?.id}`;
promptType && intentName && outputTemplates.push(intentName);
break;
}
}
};

export const deleteAdaptiveAction = (
data: MicrosoftIDialog,
deleteLgTemplates: (lgTemplates: string[]) => any,
deleteLuIntents: (luIntents: string[]) => any
) => {
const lgTemplates: string[] = [];
const luIntents: string[] = [];

walkAdaptiveAction(data, action => collectLgTemplates(action, lgTemplates));
walkAdaptiveAction(data, action => collectLuIntents(action, luIntents));

deleteLgTemplates(lgTemplates.filter(activity => !!activity));
deleteLuIntents(luIntents);
};

export const deleteAdaptiveActionList = (
data: MicrosoftIDialog[],
deleteLgTemplates: (lgTemplates: string[]) => any
deleteLgTemplates: (lgTemplates: string[]) => any,
deleteLuIntents: (luIntents: string[]) => any
) => {
const lgTemplates: string[] = [];
const luIntents: string[] = [];

walkAdaptiveActionList(data, action => collectLgTemplates(action, lgTemplates));
walkAdaptiveAction(data, action => collectLuIntents(action, luIntents));

deleteLgTemplates(lgTemplates.filter(activity => !!activity));
deleteLuIntents(luIntents);
};
16 changes: 12 additions & 4 deletions Composer/packages/lib/shared/src/dialogFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,20 @@ export const deepCopyAction = async (
});
};

export const deleteAction = (data: MicrosoftIDialog, deleteLgTemplates: (templates: string[]) => any) => {
return deleteAdaptiveAction(data, deleteLgTemplates);
export const deleteAction = (
data: MicrosoftIDialog,
deleteLgTemplates: (templates: string[]) => any,
deleteLuIntents: (luIntents: string[]) => any
) => {
return deleteAdaptiveAction(data, deleteLgTemplates, deleteLuIntents);
};

export const deleteActions = (inputs: MicrosoftIDialog[], deleteLgTemplates: (templates: string[]) => any) => {
return deleteAdaptiveActionList(inputs, deleteLgTemplates);
export const deleteActions = (
inputs: MicrosoftIDialog[],
deleteLgTemplates: (templates: string[]) => any,
deleteLuIntents: (luIntents: string[]) => any
) => {
return deleteAdaptiveActionList(inputs, deleteLgTemplates, deleteLuIntents);
};

export const seedNewDialog = (
Expand Down

0 comments on commit ae6111e

Please sign in to comment.