-
Notifications
You must be signed in to change notification settings - Fork 367
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
feature: add new survey notification to design page #8155
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a23eebb
add custom style
beyackle 95d2677
Update Publish.tsx
beyackle de094b9
display card on Home page
beyackle 611ff7f
Update constants.tsx
beyackle 1bef946
Update shell.ts
beyackle 21aaba2
Merge branch 'feature/hats-survey' into beyackle/hatsUsage
beyackle 5f51dab
Update Home.tsx
beyackle 397a746
move survey into separate component
beyackle 0fe5ebd
get more info automatically
beyackle 518ed0e
move URL into constant
beyackle 150ec25
move more props around
beyackle 6a160b2
Update constants.tsx
beyackle 43beda7
turn non-rendering component into hook
beyackle ecf2e2d
move card to design page
beyackle dadb925
start adding ipcRenderer stuff
beyackle a9babdd
update card design
beyackle 7ea55db
get machineID and stash in Recoil
beyackle 7b4d460
read OS and place in URL
beyackle 27037dc
add spacer to notification card
beyackle 854cffc
better notification styling
beyackle 7d8f8ae
fix constants and typercheck error
beyackle f7c1459
Merge branch 'feature/hats-survey' into beyackle/hatsUsage
beyackle 24d9f06
fixes from PR
beyackle 80f7464
fix card alignment and make aka.ms URL
beyackle e727353
remove redundant prop
beyackle fbeff10
use query-string package to generate link
beyackle c6416d5
move MAC truncation to electron server
beyackle ac6853a
add fixes from CR and machineID truncation
beyackle d0cd394
fix typechecking
beyackle 7121967
Update ToolbarButtonMenu.test.tsx
beyackle 0dd4982
Update App.tsx
beyackle f062b3f
Merge branch 'feature/hats-survey' into beyackle/hatsUsage
beyackle 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 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 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
85 changes: 85 additions & 0 deletions
85
Composer/packages/client/src/components/Notifications/useSurveyNotification.ts
This file contains 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,85 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { useEffect } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import formatMessage from 'format-message'; | ||
import querystring from 'query-string'; | ||
|
||
import { ClientStorage } from '../../utils/storage'; | ||
import { surveyEligibilityState, dispatcherState, machineInfoState } from '../../recoilModel/atoms/appState'; | ||
import { MachineInfo } from '../../recoilModel/types'; | ||
import { SURVEY_URL_BASE } from '../../constants'; | ||
import TelemetryClient from '../../telemetry/TelemetryClient'; | ||
|
||
const buildUrl = (info: MachineInfo) => { | ||
// User OS | ||
// hashed machineId | ||
// composer version | ||
// maybe include subscription ID; wait for global sign-in feature | ||
// session ID (global telemetry GUID) | ||
const version = process.env.COMPOSER_VERSION; | ||
|
||
const parameters = { | ||
Source: 'Composer', | ||
os: info?.os || 'Unknown', | ||
machineId: info?.id, | ||
version, | ||
}; | ||
|
||
return `${SURVEY_URL_BASE}?${querystring.stringify(parameters)}`; | ||
}; | ||
|
||
export const useSurveyNotification = () => { | ||
const { addNotification, deleteNotification } = useRecoilValue(dispatcherState); | ||
const surveyEligible = useRecoilValue(surveyEligibilityState); | ||
const machineInfo = useRecoilValue(machineInfoState); | ||
|
||
useEffect(() => { | ||
const url = buildUrl(machineInfo); | ||
deleteNotification('survey'); | ||
|
||
if (surveyEligible) { | ||
const surveyStorage = new ClientStorage(window.localStorage, 'survey'); | ||
TelemetryClient.track('HATSSurveyOffered'); | ||
|
||
addNotification({ | ||
id: 'survey', | ||
type: 'question', | ||
title: formatMessage('Would you mind taking a quick survey?'), | ||
description: formatMessage('We read every response and will use your feedback to improve Composer.'), | ||
leftLinks: [ | ||
{ | ||
label: formatMessage('Take survey'), | ||
onClick: () => { | ||
// This is safe; we control what the URL that gets built is | ||
// eslint-disable-next-line security/detect-non-literal-fs-filename | ||
window.open(url, '_blank'); | ||
TelemetryClient.track('HATSSurveyAccepted'); | ||
deleteNotification('survey'); | ||
}, | ||
}, | ||
|
||
{ | ||
// this is functionally identical to clicking the close box | ||
label: formatMessage('Remind me later'), | ||
onClick: () => { | ||
TelemetryClient.track('HATSSurveyDismissed'); | ||
deleteNotification('survey'); | ||
}, | ||
}, | ||
], | ||
rightLinks: [ | ||
{ | ||
label: formatMessage('No thanks'), | ||
onClick: () => { | ||
TelemetryClient.track('HATSSurveyRejected'); | ||
deleteNotification('survey'); | ||
surveyStorage.set('optedOut', true); | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
}, []); | ||
}; |
This file contains 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 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 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 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 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you are using the machine info only inside the useSurveyNotification hook. If so, why do we need to create a recoil state for it. You can just use the
ipcRenderer.on
inside the hook. ExuseInitializeLoger.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to make this work last week, but it runs into annoying race conditions where the message handler isn't initialized before the message gets sent and so nothing gets through. Using the Recoil store lets us put the machine info down somewhere whenever we receive it and then count on it being available when we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to usethe recoil state unless the hook can be registered in app.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the race condition a bit more. I'm also confused why we can't just initialize the survey here when the event is received? If the message handler doesn't get initialized before the message is sent, we would never get the message, right?