-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add metrics for text2viz Signed-off-by: Yulong Ruan <[email protected]> * remove new line at the end of file Signed-off-by: Yulong Ruan <[email protected]> * fix imported types Signed-off-by: Yulong Ruan <[email protected]> * update changelogs Signed-off-by: Yulong Ruan <[email protected]> * fix UI flashing Signed-off-by: Yulong Ruan <[email protected]> * cleanup duplicate imports Signed-off-by: Yulong Ruan <[email protected]> --------- Signed-off-by: Yulong Ruan <[email protected]> (cherry picked from commit 519bb92) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
582922a
commit 8b45b36
Showing
6 changed files
with
196 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import { METRIC_TYPE } from '@osd/analytics'; | ||
|
||
import { FeedbackThumbs } from './feedback_thumbs'; | ||
|
||
describe('<FeedbackThumbs />', () => { | ||
it('should report thumbs up metric', () => { | ||
const usageCollectionMock = { | ||
reportUiStats: jest.fn(), | ||
METRIC_TYPE, | ||
}; | ||
|
||
render(<FeedbackThumbs usageCollection={usageCollectionMock} appName="test-app" />); | ||
fireEvent.click(screen.getByLabelText('ThumbsUp')); | ||
expect(usageCollectionMock.reportUiStats).toHaveBeenCalledWith( | ||
'test-app', | ||
METRIC_TYPE.CLICK, | ||
expect.stringMatching(/thumbs_up.*/) | ||
); | ||
}); | ||
|
||
it('should report thumbs down metric', () => { | ||
const usageCollectionMock = { | ||
reportUiStats: jest.fn(), | ||
METRIC_TYPE, | ||
}; | ||
|
||
render(<FeedbackThumbs usageCollection={usageCollectionMock} appName="test-app" />); | ||
fireEvent.click(screen.getByLabelText('ThumbsDown')); | ||
expect(usageCollectionMock.reportUiStats).toHaveBeenCalledWith( | ||
'test-app', | ||
METRIC_TYPE.CLICK, | ||
expect.stringMatching(/thumbs_down.*/) | ||
); | ||
}); | ||
|
||
it('should only report metric only once', () => { | ||
const usageCollectionMock = { | ||
reportUiStats: jest.fn(), | ||
METRIC_TYPE, | ||
}; | ||
|
||
render(<FeedbackThumbs usageCollection={usageCollectionMock} appName="test-app" />); | ||
// click the button two times | ||
fireEvent.click(screen.getByLabelText('ThumbsDown')); | ||
fireEvent.click(screen.getByLabelText('ThumbsDown')); | ||
expect(usageCollectionMock.reportUiStats).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should hide thumbs down button after thumbs up been clicked', () => { | ||
const usageCollectionMock = { | ||
reportUiStats: jest.fn(), | ||
METRIC_TYPE, | ||
}; | ||
|
||
render(<FeedbackThumbs usageCollection={usageCollectionMock} appName="test-app" />); | ||
|
||
fireEvent.click(screen.getByLabelText('ThumbsUp')); | ||
expect(screen.queryByLabelText('ThumbsDown')).toBeNull(); | ||
}); | ||
|
||
it('should hide thumbs up button after thumbs down been clicked', () => { | ||
const usageCollectionMock = { | ||
reportUiStats: jest.fn(), | ||
METRIC_TYPE, | ||
}; | ||
|
||
render(<FeedbackThumbs usageCollection={usageCollectionMock} appName="test-app" />); | ||
|
||
fireEvent.click(screen.getByLabelText('ThumbsDown')); | ||
expect(screen.queryByLabelText('ThumbsUp')).toBeNull(); | ||
}); | ||
}); |
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,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
import React, { useState } from 'react'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import { UsageCollectionStart } from '../../../../src/plugins/usage_collection/public'; | ||
|
||
interface Props { | ||
appName: string; | ||
usageCollection: UsageCollectionStart; | ||
className?: string; | ||
} | ||
|
||
export const FeedbackThumbs = ({ usageCollection, appName, className }: Props) => { | ||
const [feedback, setFeedback] = useState<'thumbs_up' | 'thumbs_down' | undefined>(); | ||
|
||
const onFeedback = (eventName: 'thumbs_up' | 'thumbs_down') => { | ||
// Only send metric if no current feedback set | ||
if (!feedback) { | ||
usageCollection.reportUiStats( | ||
appName, | ||
usageCollection.METRIC_TYPE.CLICK, | ||
`${eventName}-${uuidv4()}` | ||
); | ||
setFeedback(eventName); | ||
} | ||
}; | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="none" className={className}> | ||
{(!feedback || feedback === 'thumbs_up') && ( | ||
<EuiFlexItem> | ||
<EuiButtonIcon | ||
size="xs" | ||
color={feedback === 'thumbs_up' ? 'primary' : 'text'} | ||
iconType="thumbsUp" | ||
aria-label="ThumbsUp" | ||
onClick={() => onFeedback('thumbs_up')} | ||
/> | ||
</EuiFlexItem> | ||
)} | ||
{(!feedback || feedback === 'thumbs_down') && ( | ||
<EuiFlexItem> | ||
<EuiButtonIcon | ||
size="xs" | ||
color={feedback === 'thumbs_down' ? 'primary' : 'text'} | ||
iconType="thumbsDown" | ||
aria-label="ThumbsDown" | ||
onClick={() => onFeedback('thumbs_down')} | ||
/> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
}; |
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