Skip to content

Commit

Permalink
chore: '$type' -> '$kind' (#2333)
Browse files Browse the repository at this point in the history
* refactor🦄(Visual Editor):'$type' to '$kind'

* update extension packages to use $kind

* update client to use $kind

* update server to use $kind

* update other packages to use $kind

* rename SDKTypes to SDKKinds

* update tests to use $kind

* update template bots to use $kind

Co-authored-by: Andy Brown <asbrown002@gmail.com>
  • Loading branch information
yeze322 and a-b-r-o-w-n authored Mar 31, 2020
1 parent 2c5efb6 commit dc8be58
Show file tree
Hide file tree
Showing 165 changed files with 1,411 additions and 1,434 deletions.
34 changes: 17 additions & 17 deletions Composer/packages/client/__tests__/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"isRoot": false,
"displayName": "addtodo",
"content": {
"$type": "Microsoft.AdaptiveDialog",
"$kind": "Microsoft.AdaptiveDialog",
"$designer": {
"id": "808722"
},
"rules": [
{
"$type": "Microsoft.OnEvent",
"$kind": "Microsoft.OnEvent",
"$designer": {
"id": "335456"
},
Expand All @@ -32,13 +32,13 @@
"isRoot": false,
"displayName": "cleartodo",
"content": {
"$type": "Microsoft.AdaptiveDialog",
"$kind": "Microsoft.AdaptiveDialog",
"$designer": {
"id": "316336"
},
"rules": [
{
"$type": "Microsoft.OnEvent",
"$kind": "Microsoft.OnEvent",
"$designer": {
"id": "480162"
},
Expand All @@ -63,15 +63,15 @@
"isRoot": false,
"displayName": "deletetodo",
"content": {
"$type": "Microsoft.AdaptiveDialog",
"$kind": "Microsoft.AdaptiveDialog",
"$designer": {
"id": "114909"
},
"autoEndDialog": true,
"$schema": "../../app.schema",
"rules": [
{
"$type": "Microsoft.OnEvent",
"$kind": "Microsoft.OnEvent",
"$designer": {
"id": "768658"
},
Expand All @@ -93,69 +93,69 @@
"isRoot": true,
"displayName": "ToDoBot.Main",
"content": {
"$type": "Microsoft.AdaptiveDialog",
"$kind": "Microsoft.AdaptiveDialog",
"$designer": {
"id": "288769",
"description": "This is a bot that demonstrates how to manage a ToDo list using Regular Expressions."
},
"rules": [
{
"$type": "Microsoft.OnConversationUpdateActivity",
"$kind": "Microsoft.OnConversationUpdateActivity",
"$designer": {
"id": "376720"
},
"steps": []
},
{
"$type": "Microsoft.OnIntent",
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "064505"
},
"steps": [],
"intent": "AddIntent"
},
{
"$type": "Microsoft.OnIntent",
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "114961"
},
"steps": [],
"intent": "DeleteIntent"
},
{
"$type": "Microsoft.OnIntent",
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "088050"
},
"steps": [],
"intent": "ClearIntent"
},
{
"$type": "Microsoft.OnIntent",
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "633942"
},
"steps": [],
"intent": "HelpIntent"
},
{
"$type": "Microsoft.OnIntent",
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "794124"
},
"steps": [],
"intent": "ShowIntent"
},
{
"$type": "Microsoft.OnIntent",
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "179728"
},
"steps": [],
"intent": "CancelIntent"
},
{
"$type": "Microsoft.OnUnknownIntent",
"$kind": "Microsoft.OnUnknownIntent",
"$designer": {
"id": "677447"
},
Expand Down Expand Up @@ -220,13 +220,13 @@
"isRoot": false,
"displayName": "showtodos",
"content": {
"$type": "Microsoft.AdaptiveDialog",
"$kind": "Microsoft.AdaptiveDialog",
"$designer": {
"id": "709692"
},
"rules": [
{
"$type": "Microsoft.OnEvent",
"$kind": "Microsoft.OnEvent",
"$designer": {
"id": "783343"
},
Expand Down
10 changes: 5 additions & 5 deletions Composer/packages/client/__tests__/utils/dialogUtil.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ const dialogsMap = {
Dialog1: {
steps: [
{
$type: 'Step1',
$kind: 'Step1',
},
{
$type: 'Step2',
$kind: 'Step2',
},
],
},
'Dialog2.main': {
steps: [
{
$type: 'Step3',
$kind: 'Step3',
},
{
$type: 'Step4',
$kind: 'Step4',
},
],
},
Expand Down Expand Up @@ -56,6 +56,6 @@ describe('setDialogData', () => {

it('returns updated dialog data at a path', () => {
const result = setDialogData(dialogsMap, 'Dialog2.main', 'steps[1]', { new: 'data' });
expect(result).toEqual({ steps: [{ $type: 'Step3' }, { new: 'data' }] });
expect(result).toEqual({ steps: [{ $kind: 'Step3' }, { new: 'data' }] });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,39 @@ const validateForm = (
regExIntents: [{ intent: string; pattern: string }]
): TriggerFormDataErrors => {
const errors: TriggerFormDataErrors = {};
const { $type, specifiedType, intent, triggerPhrases, regexEx } = data;
const { $kind, specifiedType, intent, triggerPhrases, regexEx } = data;

if ($type === eventTypeKey && !specifiedType) {
if ($kind === eventTypeKey && !specifiedType) {
errors.specifiedType = formatMessage('Please select a event type');
}

if ($type === activityTypeKey && !specifiedType) {
if ($kind === activityTypeKey && !specifiedType) {
errors.specifiedType = formatMessage('Please select an activity type');
}

if ($type === messageTypeKey && !specifiedType) {
if ($kind === messageTypeKey && !specifiedType) {
errors.specifiedType = formatMessage('Please select a message type');
}

if (!$type) {
errors.$type = formatMessage('Please select a trigger type');
if (!$kind) {
errors.$kind = formatMessage('Please select a trigger type');
}

if ($type === intentTypeKey && (!intent || !nameRegex.test(intent))) {
if ($kind === intentTypeKey && (!intent || !nameRegex.test(intent))) {
errors.intent = formatMessage(
'Spaces and special characters are not allowed. Use letters, numbers, -, or _., numbers, -, and _'
);
}

if ($type === intentTypeKey && isRegEx && regExIntents.find(ri => ri.intent === intent)) {
if ($kind === intentTypeKey && isRegEx && regExIntents.find(ri => ri.intent === intent)) {
errors.intent = `regEx ${intent} is already defined`;
}

if ($type === intentTypeKey && isRegEx && !regexEx) {
if ($kind === intentTypeKey && isRegEx && !regexEx) {
errors.regexEx = formatMessage('Please input regEx pattern');
}

if ($type === intentTypeKey && !isRegEx && !triggerPhrases) {
if ($kind === intentTypeKey && !isRegEx && !triggerPhrases) {
errors.triggerPhrases = formatMessage('Please input trigger phrases');
}
if (data.errors.triggerPhrases) {
Expand All @@ -102,12 +102,12 @@ export const TriggerCreationModal: React.FC<TriggerCreationModalProps> = props =
const { dialogs, luFiles, locale, projectId, schemas } = state;
const luFile = luFiles.find(({ id }) => id === `${dialogId}.${locale}`);
const dialogFile = dialogs.find(dialog => dialog.id === dialogId);
const isRegEx = get(dialogFile, 'content.recognizer.$type', '') === regexRecognizerKey;
const isRegEx = get(dialogFile, 'content.recognizer.$kind', '') === regexRecognizerKey;
const regexIntents = get(dialogFile, 'content.recognizer.intents', []);
const isNone = !get(dialogFile, 'content.recognizer');
const initialFormData: TriggerFormData = {
errors: {},
$type: isNone ? '' : intentTypeKey,
$kind: isNone ? '' : intentTypeKey,
specifiedType: '',
intent: '',
triggerPhrases: '',
Expand All @@ -130,7 +130,7 @@ export const TriggerCreationModal: React.FC<TriggerCreationModalProps> = props =
const content = get(luFile, 'content', '');
const luFileId = luFile?.id || `${dialogId}.${locale}`;
const newDialog = generateNewDialog(dialogs, dialogId, formData, schemas.sdk?.content);
if (formData.$type === intentTypeKey && !isRegEx) {
if (formData.$kind === intentTypeKey && !isRegEx) {
const newContent = addIntent(content, { Name: formData.intent, Body: formData.triggerPhrases });
const updateLuFile = {
id: luFileId,
Expand All @@ -144,7 +144,7 @@ export const TriggerCreationModal: React.FC<TriggerCreationModalProps> = props =
};

const onSelectTriggerType = (e, option) => {
setFormData({ ...initialFormData, $type: option.key });
setFormData({ ...initialFormData, $kind: option.key });
};

const onSelectSpecifiedTypeType = (e, option) => {
Expand Down Expand Up @@ -174,12 +174,12 @@ export const TriggerCreationModal: React.FC<TriggerCreationModalProps> = props =
if (isNone) {
triggerTypeOptions = triggerTypeOptions.filter(t => t.key !== intentTypeKey);
}
const showIntentName = formData.$type === intentTypeKey;
const showRegExDropDown = formData.$type === intentTypeKey && isRegEx;
const showTriggerPhrase = formData.$type === intentTypeKey && !isRegEx;
const showEventDropDown = formData.$type === eventTypeKey;
const showActivityDropDown = formData.$type === activityTypeKey;
const showMessageDropDown = formData.$type === messageTypeKey;
const showIntentName = formData.$kind === intentTypeKey;
const showRegExDropDown = formData.$kind === intentTypeKey && isRegEx;
const showTriggerPhrase = formData.$kind === intentTypeKey && !isRegEx;
const showEventDropDown = formData.$kind === eventTypeKey;
const showActivityDropDown = formData.$kind === activityTypeKey;
const showMessageDropDown = formData.$kind === messageTypeKey;

return (
<Dialog
Expand All @@ -202,9 +202,9 @@ export const TriggerCreationModal: React.FC<TriggerCreationModalProps> = props =
options={triggerTypeOptions}
styles={dropdownStyles}
onChange={onSelectTriggerType}
errorMessage={formData.errors.$type}
errorMessage={formData.errors.$kind}
data-testid={'triggerTypeDropDown'}
defaultSelectedKey={formData.$type}
defaultSelectedKey={formData.$kind}
/>
{showEventDropDown && (
<Dropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function createItem(trigger: ITrigger, index: number) {
return {
...trigger,
index,
displayName: trigger.displayName || getFriendlyName({ $type: trigger.type }),
displayName: trigger.displayName || getFriendlyName({ $kind: trigger.type }),
};
}

Expand Down
4 changes: 2 additions & 2 deletions Composer/packages/client/src/pages/design/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import formatMessage from 'format-message';
import { globalHistory } from '@reach/router';
import get from 'lodash/get';
import { PromptTab } from '@bfc/shared';
import { DialogFactory, SDKTypes, DialogInfo } from '@bfc/shared';
import { DialogFactory, SDKKinds, DialogInfo } from '@bfc/shared';

import { VisualEditorAPI } from '../../messenger/FrameAPI';
import { TestController } from '../../TestController';
Expand Down Expand Up @@ -288,7 +288,7 @@ function DesignPage(props) {
}, [dialogs, breadcrumb]);

async function onSubmit(data: { name: string; description: string }) {
const seededContent = new DialogFactory(schemas.sdk?.content).create(SDKTypes.AdaptiveDialog, {
const seededContent = new DialogFactory(schemas.sdk?.content).create(SDKKinds.AdaptiveDialog, {
$designer: { name: data.name, description: data.description },
generator: `${data.name}.lg`,
});
Expand Down
Loading

0 comments on commit dc8be58

Please sign in to comment.