11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- import React , { useState } from 'react' ;
4+ import React , { useMemo , useState } from 'react' ;
55import { Text , useTheme , Stack , Checkbox , Pivot , PivotItem } from '@fluentui/react' ;
66import { _formatString , _pxToRem } from '@internal/acs-ui-common' ;
77import { checkboxClassName , questionTextStyle , helperTextStyle } from './TagsSurvey.styles' ;
@@ -13,7 +13,7 @@ import {
1313 _ScreenshareIssue ,
1414 _VideoIssue
1515} from '../SurveyTypes' ;
16- import { SurveyCategories , SurveyIssues } from '../../../types' ;
16+ import { SurveyIssuesHeadingStrings , SurveyIssues } from '../../../types' ;
1717/**
1818 * Strings of {@link TagsSurvey} that can be overridden.
1919 *
@@ -25,7 +25,7 @@ export interface _TagsSurveyStrings {
2525 */
2626 tagsSurveyQuestion ?: string ;
2727 /**
28- * Confirm Button Label
28+ * Helper text for tag survey explaining what the survey is for
2929 */
3030 tagsSurveyHelperText ?: string ;
3131}
@@ -60,7 +60,7 @@ export interface _TagsSurveyProps {
6060 /** Mappings from call issues to tags displayed on the survey*/
6161 callIssuesToTag : SurveyIssues ;
6262 /** Mappings from issue category to categories displayed on survey*/
63- categoriesToHeader : SurveyCategories ;
63+ categoryHeadings : SurveyIssuesHeadingStrings ;
6464 /** Function to send TagsSurvey results*/
6565 onConfirm ?: ( selectedTags : _CallSurvey ) => void ;
6666 /** Tags survey strings */
@@ -73,32 +73,35 @@ export interface _TagsSurveyProps {
7373 * @internal
7474 */
7575export const _TagsSurvey = ( props : _TagsSurveyProps ) : JSX . Element => {
76- const { issues, callIssuesToTag, categoriesToHeader , onConfirm, strings } = props ;
76+ const { issues, callIssuesToTag, categoryHeadings , onConfirm, strings } = props ;
7777
7878 const [ selectedTags , setSelectedTags ] = useState ( { } ) ;
7979
80- const tags : _SurveyTag [ ] = [ ] ;
81- issues . map ( ( issue ) => {
82- const issueCamelCase = issue ?. charAt ( 0 ) . toLowerCase ( ) + issue ?. slice ( 1 ) ;
83- const issueCategory = Object . keys ( callIssuesToTag ) . find (
84- ( key ) => callIssuesToTag [ key ] [ issueCamelCase ] !== undefined
85- ) ;
86- if ( issueCategory ) {
87- if ( tags [ issueCategory ] ) {
88- tags [ issueCategory ] . push ( {
89- message : callIssuesToTag [ issueCategory ] [ issueCamelCase ] ,
90- issue : issue
91- } ) ;
92- } else {
93- tags [ issueCategory ] = [
94- {
80+ const tags : _SurveyTag [ ] = useMemo ( ( ) => {
81+ const tags : _SurveyTag [ ] = [ ] ;
82+ issues . forEach ( ( issue ) => {
83+ const issueCamelCase = issue ?. charAt ( 0 ) . toLowerCase ( ) + issue ?. slice ( 1 ) ;
84+ const issueCategory = Object . keys ( callIssuesToTag ) . find (
85+ ( key ) => callIssuesToTag [ key ] [ issueCamelCase ] !== undefined
86+ ) ;
87+ if ( issueCategory ) {
88+ if ( tags [ issueCategory ] ) {
89+ tags [ issueCategory ] . push ( {
9590 message : callIssuesToTag [ issueCategory ] [ issueCamelCase ] ,
9691 issue : issue
97- }
98- ] ;
92+ } ) ;
93+ } else {
94+ tags [ issueCategory ] = [
95+ {
96+ message : callIssuesToTag [ issueCategory ] [ issueCamelCase ] ,
97+ issue : issue
98+ }
99+ ] ;
100+ }
99101 }
100- }
101- } ) ;
102+ } ) ;
103+ return tags ;
104+ } , [ issues , callIssuesToTag ] ) ;
102105
103106 const onChange = React . useCallback (
104107 ( issue : string , issueCategory : string , checked : boolean ) : void => {
@@ -146,7 +149,7 @@ export const _TagsSurvey = (props: _TagsSurveyProps): JSX.Element => {
146149 return (
147150 < PivotItem
148151 key = { `key-${ i } ` }
149- headerText = { categoriesToHeader [ key ] }
152+ headerText = { categoryHeadings [ key ] }
150153 headerButtonProps = { {
151154 'data-order' : i ,
152155 'data-title' : key
0 commit comments