This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 375
feat: Add data collection dialog and settings #4864
Merged
tdurnford
merged 8 commits into
microsoft:main
from
tdurnford:feature/data-collection-dialog
Nov 18, 2020
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ebe09c5
feat: Add data collection dialog and settings
tdurnford fc7f98e
Merge branch 'main' into feature/data-collection-dialog
tdurnford 5952bee
small changes
tdurnford d15100d
remove console.log
tdurnford 7300e71
Merge branch 'main' into feature/data-collection-dialog
tdurnford 09bcda5
Merge branch 'main' into feature/data-collection-dialog
tdurnford cb50de1
fix log message
tdurnford ca81332
fix type
tdurnford 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
This file contains hidden or 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 hidden or 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
57 changes: 57 additions & 0 deletions
57
Composer/packages/client/src/components/DataCollectionDialog.tsx
This file contains hidden or 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,57 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import formatMessage from 'format-message'; | ||
| import { DefaultButton, PrimaryButton } from 'office-ui-fabric-react/lib/Button'; | ||
| import { Dialog, DialogFooter } from 'office-ui-fabric-react/lib/Dialog'; | ||
| import { Link } from 'office-ui-fabric-react/lib/Link'; | ||
| import React from 'react'; | ||
| import { useRecoilValue } from 'recoil'; | ||
|
|
||
| import { dispatcherState } from '../recoilModel'; | ||
|
|
||
| const DataCollectionDialog: React.FC = () => { | ||
| const { setAllowDataCollection } = useRecoilValue(dispatcherState); | ||
|
|
||
| const handleDismiss = () => { | ||
| setAllowDataCollection(false); | ||
| }; | ||
|
|
||
| const handleAgree = () => { | ||
| setAllowDataCollection(true); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| hidden={false} | ||
| modalProps={{ | ||
| isBlocking: true, | ||
| }} | ||
| title={formatMessage('Help us improve?')} | ||
| onDismiss={handleDismiss} | ||
| > | ||
| <p> | ||
| {formatMessage( | ||
| 'Composer includes a telemetry feature that collects usage information. It is important that the Composer team understands how the tool is being used so that it can be improved.' | ||
| )} | ||
| </p> | ||
| <p>{formatMessage('You can turn data collection on or off at any time in the Application Settings.')}</p> | ||
| <p> | ||
| <Link | ||
| aria-label={formatMessage('Privacy statement')} | ||
| href={'https://privacy.microsoft.com/privacystatement'} | ||
| target={'_blank'} | ||
| > | ||
| {formatMessage('Privacy statement')} | ||
| </Link> | ||
| </p> | ||
| <DialogFooter> | ||
| <DefaultButton text={formatMessage('Not now')} onClick={handleDismiss} /> | ||
| <PrimaryButton text={formatMessage('Yes, collect data')} onClick={handleAgree} /> | ||
| </DialogFooter> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| export default DataCollectionDialog; | ||
| export { DataCollectionDialog }; |
This file contains hidden or 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 hidden or 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 hidden or 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
95 changes: 95 additions & 0 deletions
95
Composer/packages/client/src/recoilModel/dispatchers/__tests__/serverSettings.test.tsx
This file contains hidden or 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,95 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { useRecoilValue } from 'recoil'; | ||
| import { act } from '@botframework-composer/test-utils/lib/hooks'; | ||
|
|
||
| import { renderRecoilHook } from '../../../../__tests__/testUtils'; | ||
| import { ServerSettingsState } from '../../atoms'; | ||
| import { dispatcherState } from '../../../recoilModel/DispatcherWrapper'; | ||
| import { Dispatcher } from '..'; | ||
| import { serverSettingsDispatcher } from '../serverSettings'; | ||
| import httpClient from '../../../utils/httpUtil'; | ||
|
|
||
| jest.mock('../../../utils/httpUtil'); | ||
|
|
||
| describe('server setting dispatcher', () => { | ||
| let renderedComponent, dispatcher: Dispatcher; | ||
| beforeEach(() => { | ||
| const useRecoilTestHook = () => { | ||
| const serverSettings = useRecoilValue(ServerSettingsState); | ||
| const currentDispatcher = useRecoilValue(dispatcherState); | ||
|
|
||
| return { | ||
| serverSettings, | ||
| currentDispatcher, | ||
| }; | ||
| }; | ||
|
|
||
| const { result } = renderRecoilHook(useRecoilTestHook, { | ||
| states: [{ recoilState: ServerSettingsState, initialValue: {} }], | ||
| dispatcher: { | ||
| recoilState: dispatcherState, | ||
| initialValue: { | ||
| serverSettingsDispatcher, | ||
| }, | ||
| }, | ||
| }); | ||
| renderedComponent = result; | ||
| dispatcher = renderedComponent.current.currentDispatcher; | ||
| }); | ||
|
|
||
| it('should set allowDataCollection to false', async () => { | ||
| await act(async () => { | ||
| await dispatcher.setAllowDataCollection(false); | ||
| }); | ||
|
|
||
| expect(renderedComponent.current.serverSettings.telemetry.allowDataCollection).toBe(false); | ||
| expect(httpClient.post).toBeCalledWith( | ||
| '/settings', | ||
| expect.objectContaining({ | ||
| settings: { | ||
| telemetry: { | ||
| allowDataCollection: false, | ||
| }, | ||
| }, | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('should set allowDataCollection to true', async () => { | ||
| (httpClient.post as jest.Mock).mockResolvedValue({}); | ||
|
|
||
| await act(async () => { | ||
| await dispatcher.setAllowDataCollection(true); | ||
| }); | ||
|
|
||
| expect(renderedComponent.current.serverSettings.telemetry.allowDataCollection).toBe(true); | ||
| expect(httpClient.post).toBeCalledWith( | ||
| '/settings', | ||
| expect.objectContaining({ | ||
| settings: { | ||
| telemetry: { | ||
| allowDataCollection: true, | ||
| }, | ||
| }, | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('should fetch settings from server', async () => { | ||
| (httpClient.get as jest.Mock).mockResolvedValue({ | ||
| data: { | ||
| telemetry: { | ||
| allowDataCollection: null, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await act(async () => { | ||
| await dispatcher.fetchServerSettings(); | ||
| }); | ||
|
|
||
| expect(renderedComponent.current.serverSettings.telemetry.allowDataCollection).toBe(null); | ||
| }); | ||
| }); |
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
Composer/packages/client/src/recoilModel/dispatchers/serverSettings.tsx
This file contains hidden or 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,51 @@ | ||
| /* eslint-disable react-hooks/rules-of-hooks */ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { CallbackInterface, useRecoilCallback } from 'recoil'; | ||
| import { produce } from 'immer'; | ||
|
|
||
| import httpClient from '../../utils/httpUtil'; | ||
| import { ServerSettingsState } from '../atoms/appState'; | ||
|
|
||
| import { logMessage } from './shared'; | ||
|
|
||
| export const serverSettingsDispatcher = () => { | ||
| const setAllowDataCollection = useRecoilCallback( | ||
| (callbackHelpers: CallbackInterface) => async (allowDataCollection: boolean) => { | ||
| const { set, snapshot } = callbackHelpers; | ||
| try { | ||
| const currentSettings = await snapshot.getPromise(ServerSettingsState); | ||
|
|
||
| const settings = produce(currentSettings, (current) => ({ | ||
|
tdurnford marked this conversation as resolved.
Outdated
|
||
| ...current, | ||
| telemetry: { | ||
| ...current.telemetry, | ||
| allowDataCollection, | ||
| }, | ||
| })); | ||
|
|
||
| await httpClient.post('/settings', { settings }); | ||
| set(ServerSettingsState, settings); | ||
| } catch (error) { | ||
| logMessage(callbackHelpers, `Error fetching data collection settings: ${error}`); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| const fetchServerSettings = useRecoilCallback((callbackHelpers: CallbackInterface) => async () => { | ||
| const { set } = callbackHelpers; | ||
| try { | ||
| const { data: settings } = await httpClient.get('/settings'); | ||
|
|
||
| set(ServerSettingsState, settings); | ||
| } catch (error) { | ||
| logMessage(callbackHelpers, `Error fetching data collection settings: ${error}`); | ||
| } | ||
| }); | ||
|
|
||
| return { | ||
| fetchServerSettings, | ||
| setAllowDataCollection, | ||
|
tdurnford marked this conversation as resolved.
Outdated
|
||
| }; | ||
| }; | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.