Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { jsx } from '@emotion/core';
import { useContext, FC, useEffect, useState, useRef } from 'react';
import { MarqueeSelection, Selection } from 'office-ui-fabric-react/lib/MarqueeSelection';
import { has, get } from 'lodash';

import { NodeEventTypes } from '../constants/NodeEventTypes';
import { KeyboardCommandTypes, KeyboardPrimaryTypes } from '../constants/KeyboardCommandTypes';
import { AttrNames } from '../constants/ElementAttributes';
import { ObiTypes } from '../constants/ObiTypes';
import { NodeRendererContext } from '../store/NodeRendererContext';
import { SelectionContext, SelectionContextData } from '../store/SelectionContext';
import { ClipboardContext } from '../store/ClipboardContext';
Expand Down Expand Up @@ -69,11 +69,36 @@ export const ObiEditor: FC<ObiEditorProps> = ({
break;
case NodeEventTypes.Delete:
handler = e => {
const cleanLgTemplate = (removedData: any): void => {
if (removedData && removedData.$type === ObiTypes.SendActivity) {
if (removedData.activity && removedData.activity.indexOf('[bfdactivity-') !== -1) {
removeLgTemplate('common', removedData.activity.slice(1, removedData.activity.length - 1));
// TODO: move the shared logic into shared lib as a generic destruction process
const findLgTemplates = (value: any): string[] => {
const targetNames = ['prompt', 'unrecognizedPrompt', 'defaultValueResponse', 'invalidPrompt', 'activity'];
const targets: string[] = [];

targetNames.forEach(name => {
if (has(value, name)) {
targets.push(get(value, name));
}
});

const templates: string[] = [];
targets.forEach(target => {
// only match auto generated lg temapte name
const reg = /\[(bfd((?:activity)|(?:prompt)|(?:unrecognizedPrompt)|(?:defaultValueResponse)|(?:invalidPrompt))-\d{6})\]/g;
let matchResult;
while ((matchResult = reg.exec(target)) !== null) {
const templateName = matchResult[1];
templates.push(templateName);
}
});

return templates;
};

const cleanLgTemplate = async (removedData: any): Promise<void> => {
const templates: string[] = findLgTemplates(removedData);
const lgFileId = 'common';
for (const template of templates) {
await removeLgTemplate(lgFileId, template);
}
};
onChange(deleteNode(data, e.id, cleanLgTemplate));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import has from 'lodash.has';
import get from 'lodash.get';
import uniq from 'lodash.uniq';

import { JsonWalk, VisitorFunc } from '../../../utility/jsonWalk';
Expand Down Expand Up @@ -29,15 +30,15 @@ export class DialogIndexer {
const visitor: VisitorFunc = (path: string, value: any): boolean => {
// it's a valid schema dialog node.
if (has(value, '$type')) {
const targetNames = ['prompt', 'unrecognizedPrompt', 'defaultValueResponse', 'invalidPrompt'];
const targets: string[] = [];
// look for prompt field
if (has(value, 'prompt')) {
targets.push(value.prompt);
}
// look for unrecognizedPrompt field
if (has(value, 'unrecognizedPrompt')) {
targets.push(value.unrecognizedPrompt);
}

targetNames.forEach(name => {
if (has(value, name)) {
targets.push(get(value, name));
}
});

// look for other $type
switch (value.$type) {
case 'Microsoft.SendActivity':
Expand Down