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

#1237 - updated implementation to use API instead of internals #1247

Merged
merged 32 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
608c776
#1237 - updated implemenation to use API instead of internals
justinwilaby Jan 22, 2019
e405afa
Removed unneeded dependency
justinwilaby Jan 22, 2019
5a61d1a
Addressed PR feedback
justinwilaby Jan 23, 2019
63692f1
Removing misplaced single quotes
justinwilaby Jan 23, 2019
8a5842d
lint
justinwilaby Jan 23, 2019
eed43a6
Fix build
justinwilaby Jan 23, 2019
8ca54b7
Fix build
justinwilaby Jan 23, 2019
1cb9fb9
Fix build
justinwilaby Jan 23, 2019
5c4f2d1
Fix build
justinwilaby Jan 23, 2019
ab9f108
Fix build
justinwilaby Jan 23, 2019
292db66
Merge branch 'jwilaby/#1237-bot-url-revision' of github.com:Microsoft…
justinwilaby Jan 23, 2019
85b9860
Merge branch 'jwilaby/#1237-bot-url-revision' of github.com:Microsoft…
justinwilaby Jan 23, 2019
75aa593
Merge branch 'jwilaby/#1237-bot-url-revision' of github.com:Microsoft…
justinwilaby Jan 23, 2019
5a74aba
Fixed bad import
justinwilaby Jan 23, 2019
38543a1
Updated import
justinwilaby Jan 23, 2019
5e71657
fixed bad import
justinwilaby Jan 23, 2019
74d9acf
unit test restitution
justinwilaby Jan 23, 2019
65c12fa
unit test restitution
justinwilaby Jan 23, 2019
2a8693a
unit test restitution
justinwilaby Jan 23, 2019
ff9cd78
Merge branch 'jwilaby/#1237-bot-url-revision' of github.com:Microsoft…
justinwilaby Jan 23, 2019
7ef6060
Removed default exports
justinwilaby Jan 23, 2019
96a24bb
Added coverage ignore pattern
justinwilaby Jan 24, 2019
06a4965
Attempting to fix coverage analysis
justinwilaby Jan 24, 2019
bef30c6
Attempting to fix coverage analysis
justinwilaby Jan 24, 2019
b4154c2
Merge branch 'jwilaby/#1237-bot-url-revision' of github.com:Microsoft…
justinwilaby Jan 24, 2019
001c89c
Attempt to filter .d.ts from coverage report
justinwilaby Jan 24, 2019
9c41bcf
Attempt to filter .d.ts from coverage report #2
justinwilaby Jan 24, 2019
54f34f5
attempt to fix export statements to make coveralls happy
justinwilaby Jan 24, 2019
aa00387
attempt to fix export statements to make coveralls happy
justinwilaby Jan 24, 2019
82f3092
Merge branch 'jwilaby/#1237-bot-url-revision' of github.com:Microsoft…
justinwilaby Jan 24, 2019
eca4b8f
Fixed out of place imports
justinwilaby Jan 24, 2019
5736e2b
Prettier
justinwilaby Jan 24, 2019
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
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lint:fix": "lerna run lint:fix --no-bail",
"start": "cd packages\\app\\client && npm run start",
"test": "jest --no-cache",
"test:coveralls": "jest --runInBand --bail --coverage --coverageReporters=text-lcov | coveralls"
"test:coveralls": "jest --runInBand --coverage --coverageReporters=text-lcov | coveralls"
},
"devDependencies": {
"@babel/cli": "^7.1.0",
Expand All @@ -27,6 +27,14 @@
"transform": {
"^.+\\.(tsx|ts|js)$": "./babel-jest-config"
},
"collectCoverageFrom": [
"<rootDir>/packages/**/src/**/?(*.)(ts)?(x)",
"!<rootDir>/packages/**/src/**/?(*.)(d).(ts)",
"!<rootDir>/packages/**/src/**/?(*.)(spec|test).(ts)?(x)",
"!**/node_modules/**",
"!**/lib/**",
"!**/build/**"
],
"testURL": "http://localhost",
"testMatch": [
"<rootDir>/packages/**/src/**/?(*.)(spec|test).(ts)?(x)"
Expand Down
2 changes: 1 addition & 1 deletion packages/app/client/src/commands/botCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('The bot commands', () => {
);
handler([{}]);

expect(dispatchSpy).toHaveBeenCalledWith(BotActions.load([{}]));
expect(dispatchSpy).toHaveBeenCalledWith(BotActions.loadBotInfos([{}]));
expect(remoteCallSpy).toHaveBeenCalledWith(
SharedConstants.Commands.Electron.UpdateFileMenu
);
Expand Down
4 changes: 2 additions & 2 deletions packages/app/client/src/commands/botCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) {
commandRegistry.registerCommand(
Commands.Bot.SyncBotList,
async (bots: BotInfo[]): Promise<void> => {
store.dispatch(BotActions.load(bots));
store.dispatch(BotActions.loadBotInfos(bots));
await CommandServiceImpl.remoteCall(Commands.Electron.UpdateFileMenu);
}
);
Expand All @@ -104,7 +104,7 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) {
commandRegistry.registerCommand(
Commands.Bot.SetActive,
async (bot: BotConfigWithPath, botDirectory: string) => {
store.dispatch(BotActions.setActive(bot));
store.dispatch(BotActions.setActiveBot(bot));
store.dispatch(FileActions.setRoot(botDirectory));
await Promise.all([
CommandServiceImpl.remoteCall(Commands.Electron.UpdateFileMenu),
Expand Down
19 changes: 11 additions & 8 deletions packages/app/client/src/commands/notificationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { SharedConstants } from '@bfemulator/app-shared';
import { Notification } from '@bfemulator/app-shared';
import { Notification, SharedConstants } from '@bfemulator/app-shared';
import { CommandRegistryImpl } from '@bfemulator/sdk-shared';

import * as NotificationActions from '../data/action/notificationActions';
Expand All @@ -44,12 +43,16 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) {
const Commands = SharedConstants.Commands.Notifications;
// ---------------------------------------------------------------------------
// Adds a notification from the main side to the store / notification manager
commandRegistry.registerCommand(Commands.Add, () => {
const notification: Notification = getGlobal(
SharedConstants.NOTIFICATION_FROM_MAIN
);
store.dispatch(NotificationActions.beginAdd(notification));
});
commandRegistry.registerCommand(
Commands.Add,
(notification: Notification) => {
if (!notification) {
notification = getGlobal(SharedConstants.NOTIFICATION_FROM_MAIN);
}

store.dispatch(NotificationActions.beginAdd(notification));
}
);

// ---------------------------------------------------------------------------
// Removes a notification from the store / notification manager
Expand Down
107 changes: 54 additions & 53 deletions packages/app/client/src/data/action/botActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,94 +32,95 @@
//

import { BotInfo } from '@bfemulator/app-shared';
import { BotConfigWithPath } from '@bfemulator/sdk-shared';
import {
BotConfigWithPath,
StartConversationParams,
} from '@bfemulator/sdk-shared';

export enum BotActions {
load = 'BOT/LOAD',
setActive = 'BOT/SET_ACTIVE',
export enum BotActionType {
close = 'BOT/CLOSE',
browse = 'BOT/BROWSE',
hashGenerated = 'BOT/HASH_GENERATED',
load = 'BOT/LOAD',
open = 'BOT/OPEN',
openViaUrl = 'BOT/OPEN_VIA_URL',
openViaFilePath = 'BOT/OPEN_VIA_FILE_PATH',
setActive = 'BOT/SET_ACTIVE',
}

export interface LoadBotAction {
type: BotActions.load;
payload: {
bots: BotInfo[];
};
export interface BotAction<T = any> {
readonly type: BotActionType;
payload: T;
}

export interface SetActiveBotAction {
type: BotActions.setActive;
payload: {
bot: BotConfigWithPath;
};
export interface BotConfigWithPathPayload {
bot: BotConfigWithPath;
}

export interface CloseBotAction {
type: BotActions.close;
payload: {};
export interface BotInfosPayload {
bots: BotInfo[];
}

export interface BrowseBotAction {
type: BotActions.browse;
payload: {};
export interface HashPayload {
hash: string;
}

export interface BotHashAction {
type: BotActions.hashGenerated;
payload: { hash: string };
export function botHashGenerated(hash: string): BotAction<HashPayload> {
return {
type: BotActionType.hashGenerated,
payload: { hash },
};
}

export type BotAction =
| LoadBotAction
| SetActiveBotAction
| CloseBotAction
| BrowseBotAction
| BotHashAction;

export function load(bots: BotInfo[]): LoadBotAction {
// prune bad bots
bots = bots.filter(bot => !!bot);
export function browse(): BotAction<{}> {
return {
type: BotActionType.browse,
payload: {},
};
}

export function closeBot(): BotAction<{}> {
return {
type: BotActions.load,
payload: {
bots,
},
type: BotActionType.close,
payload: {},
};
}

/**
*
* @param bot The new active bot
*/
export function setActive(bot: BotConfigWithPath): SetActiveBotAction {
export function loadBotInfos(bots: BotInfo[]): BotAction<BotInfosPayload> {
// prune bad bots
bots = bots.filter(bot => !!bot);

return {
type: BotActions.setActive,
type: BotActionType.load,
payload: {
bot,
bots,
},
};
}

export function close(): CloseBotAction {
export function openBotViaFilePathAction(path: string): BotAction<string> {
return {
type: BotActions.close,
payload: {},
type: BotActionType.openViaFilePath,
payload: path,
};
}

export function browse(): BrowseBotAction {
export function openBotViaUrlAction(
params: Partial<StartConversationParams>
): BotAction<Partial<StartConversationParams>> {
return {
type: BotActions.browse,
payload: {},
type: BotActionType.openViaUrl,
payload: params,
};
}

export function botHashGenerated(hash: string): BotHashAction {
export function setActiveBot(
bot: BotConfigWithPath
): BotAction<BotConfigWithPathPayload> {
return {
type: BotActions.hashGenerated,
payload: { hash },
type: BotActionType.setActive,
payload: {
bot,
},
};
}
2 changes: 1 addition & 1 deletion packages/app/client/src/data/action/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import LogEntry from '@bfemulator/emulator-core/lib/types/log/entry';
import { LogEntry } from '@bfemulator/sdk-shared';
import { Action } from 'redux';

export enum ChatActions {
Expand Down
19 changes: 12 additions & 7 deletions packages/app/client/src/data/reducer/bot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
import { BotInfo } from '@bfemulator/app-shared';
import { BotConfigWithPath } from '@bfemulator/sdk-shared';

import { BotAction, close, load, setActive } from '../action/botActions';
import {
BotAction,
closeBot,
loadBotInfos,
setActiveBot,
} from '../action/botActions';

import { bot, BotState } from './bot';

Expand Down Expand Up @@ -63,7 +68,7 @@ describe('Bot reducer tests', () => {
};

it('should set a bot as active', () => {
const action = setActive(testbot);
const action = setActiveBot(testbot);
const state = bot(DEFAULT_STATE, action);
expect(state.activeBot).toEqual(testbot);
});
Expand Down Expand Up @@ -92,7 +97,7 @@ describe('Bot reducer tests', () => {
botFiles: testbots,
};

const action = setActive(testbot);
const action = setActiveBot(testbot);
const endingState = bot(startingState, action);
expect(endingState.botFiles[0].path).toBe('somePath');
});
Expand All @@ -117,7 +122,7 @@ describe('Bot reducer tests', () => {
} as any,
};

const action = setActive(testbot);
const action = setActiveBot(testbot);
const endingState = bot(startingState, action);
const activeBot = endingState.activeBot;

Expand Down Expand Up @@ -151,7 +156,7 @@ describe('Bot reducer tests', () => {
} as any,
};

const action = setActive(testbot);
const action = setActiveBot(testbot);
const endingState = bot(startingState, action);
const activeBot = endingState.activeBot;

Expand Down Expand Up @@ -179,7 +184,7 @@ describe('Bot reducer tests', () => {
},
null,
];
const action = load(bots);
const action = loadBotInfos(bots);
const state = bot(DEFAULT_STATE, action);
expect(state.botFiles).not.toEqual(bots);
expect(state.botFiles.length).toBe(3);
Expand Down Expand Up @@ -212,7 +217,7 @@ describe('Bot reducer tests', () => {
services: [],
} as any,
};
const action = close();
const action = closeBot();
const endingState = bot(startingState, action);
expect(endingState.activeBot).toBe(null);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/app/client/src/data/reducer/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
botsAreTheSame,
} from '@bfemulator/sdk-shared';

import { BotAction, BotActions } from '../action/botActions';
import { BotAction, BotActionType } from '../action/botActions';

export interface BotState {
activeBot: BotConfigWithPath;
Expand All @@ -54,12 +54,12 @@ const DEFAULT_STATE: BotState = {

export function bot(state: BotState = DEFAULT_STATE, action: BotAction) {
switch (action.type) {
case BotActions.load: {
case BotActionType.load: {
state = setBotFilesState(action.payload.bots, state);
break;
}

case BotActions.setActive: {
case BotActionType.setActive: {
// move active bot up to the top of the recent bots list
const mostRecentBot = state.botFiles.find(
botArg => botArg && botArg.path === action.payload.bot.path
Expand All @@ -82,13 +82,13 @@ export function bot(state: BotState = DEFAULT_STATE, action: BotAction) {
break;
}

case BotActions.close: {
case BotActionType.close: {
// close the active bot
state = setActiveBot(null, state);
break;
}

case BotActions.hashGenerated:
case BotActionType.hashGenerated:
return { ...state, activeBotDigest: action.payload.hash };

default:
Expand Down
2 changes: 1 addition & 1 deletion packages/app/client/src/data/reducer/chat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import LogEntry from '@bfemulator/emulator-core/lib/types/log/entry';
import { LogEntry } from '@bfemulator/sdk-shared';

import {
addTranscript,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import { ClientAwareSettings } from '@bfemulator/app-shared/built';
import { ClientAwareSettings } from '@bfemulator/app-shared';

import {
CLIENT_AWARE_SETTINGS_CHANGED,
Expand Down
Loading