File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111 StandardTitle ,
1212} from "../templates/headingtitles" ;
1313import { queryConcatenator } from "../utils/data" ;
14+ import { getHeadingLabel } from "../utils/getHeadingLabel" ;
1415
1516const Heading = ( {
1617 localization,
@@ -179,26 +180,6 @@ const sliceText = (text, maxLength) => {
179180 return `${ text . slice ( 0 , maxLength - 3 ) } ...` ;
180181} ;
181182
182- /**
183- * Refactored helper function for getting the heading label.
184- */
185- export const getHeadingLabel = ( labelType , localization ) => {
186- switch ( labelType ) {
187- case "authorview-streamgraph" :
188- return localization . streamgraph_authors_label ;
189- case "authorview-knowledgemap" :
190- return localization . overview_authors_label ;
191- case "keywordview-streamgraph" :
192- return localization . streamgraph_label ;
193- case "keywordview-knowledgemap" :
194- return localization . overview_label ;
195- case "geomap" :
196- return localization . geomap_label ;
197- default :
198- throw new Error ( `Label of type '${ labelType } ' not supported.` ) ;
199- }
200- } ;
201-
202183const unescapeHTML = ( string ) => {
203184 const entityMap = {
204185 "&" : "&" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { queryConcatenator } from "@/js/utils/data" ;
2+ import { getHeadingLabel } from "@/js/utils/getHeadingLabel" ;
3+ import { unescapeHTML } from "@/js/utils/unescapeHTMLentities" ;
4+
5+ const MAX_LENGTH_CUSTOM = 100 ;
6+
7+ const sliceText = ( text : string , maxLength : number ) => {
8+ if ( text . length <= maxLength ) {
9+ return text ;
10+ }
11+
12+ return `${ text . slice ( 0 , maxLength - 3 ) } ...` ;
13+ } ;
14+
15+ type Params = {
16+ titleLabelType : Parameters < typeof getHeadingLabel > [ 0 ] ;
17+ localization : Parameters < typeof getHeadingLabel > [ 1 ] ;
18+ query : string ;
19+ advancedQuery : string | null ;
20+ customTitle : unknown ;
21+ titleStyle : string | null ;
22+ } ;
23+
24+ export const getAriaLabel = ( {
25+ titleLabelType,
26+ localization,
27+ query,
28+ advancedQuery,
29+ customTitle,
30+ titleStyle,
31+ } : Params ) => {
32+ const headingLabel = getHeadingLabel ( titleLabelType , localization ) ;
33+ const queryString = queryConcatenator ( [ query , advancedQuery ] ) ;
34+
35+ const effectiveTitle =
36+ titleStyle === "custom" &&
37+ typeof customTitle !== "undefined" &&
38+ customTitle !== null
39+ ? unescapeHTML ( sliceText ( String ( customTitle ) , MAX_LENGTH_CUSTOM ) )
40+ : queryString ;
41+
42+ return effectiveTitle ? `${ headingLabel } ${ effectiveTitle } ` : headingLabel ;
43+ } ;
Original file line number Diff line number Diff line change 11import { FC , PropsWithChildren } from "react" ;
22import { useSelector } from "react-redux" ;
33
4- import { getMapHeight } from "./selectors" ;
5- import { ACCESSABILITY_ATTRIBUTES } from "./config" ;
4+ import { getAriaLabel } from "./getAriaLabel" ;
5+ import {
6+ getCustomTitle ,
7+ getLocalization ,
8+ getMapHeight ,
9+ getQuery ,
10+ getQueryAdvanced ,
11+ getTitleLabelType ,
12+ getTitleStyle ,
13+ } from "./selectors" ;
614
715export const HeightContainer : FC < PropsWithChildren > = ( { children } ) => {
816 const height = useSelector ( getMapHeight ) ;
17+ const localization = useSelector ( getLocalization ) ;
18+ const titleLabelType = useSelector ( getTitleLabelType ) ;
19+ const query = useSelector ( getQuery ) ;
20+ const advancedQuery = useSelector ( getQueryAdvanced ) ;
21+ const customTitle = useSelector ( getCustomTitle ) ;
22+ const titleStyle = useSelector ( getTitleStyle ) ;
23+
24+ const ariaLabel = getAriaLabel ( {
25+ titleLabelType,
26+ localization,
27+ query,
28+ advancedQuery,
29+ customTitle,
30+ titleStyle,
31+ } ) ;
932
1033 return (
11- < div style = { { height } } { ... ACCESSABILITY_ATTRIBUTES } >
34+ < div role = "region" aria-label = { ariaLabel } style = { { height } } >
1235 { children }
1336 </ div >
1437 ) ;
Original file line number Diff line number Diff line change 11import { State } from "@/js/types" ;
22
33export const getMapHeight = ( state : State ) => state . chart . height ;
4+ export const getLocalization = ( state : State ) => state . localization ;
5+ export const getTitleLabelType = ( state : State ) => state . heading . titleLabelType ;
6+ export const getQuery = ( state : State ) => state . query . text ;
7+ export const getQueryAdvanced = ( state : State ) => state . q_advanced . text ;
8+ export const getCustomTitle = ( state : State ) => state . heading . customTitle ;
9+ export const getTitleStyle = ( state : State ) => state . heading . titleStyle ;
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import { MapContainer } from "react-leaflet";
55
66import { CONFIG } from "./config" ;
77import { HeightContainer } from "./HeightContainer" ;
8+ import { KeyboardZoomController } from "./KeyboardZoomController" ;
89import { Layer } from "./Layer" ;
910import { Pins } from "./Pins" ;
1011import { SelectionResetHandler } from "./SelectionResetHandler" ;
1112import { ZoomControls } from "./ZoomControls" ;
12- import { KeyboardZoomController } from "./KeyboardZoomController" ;
1313
1414export const Geomap : FC = ( ) => (
1515 < HeightContainer >
Original file line number Diff line number Diff line change 1+ import { Localization } from "../i18n/localization" ;
2+
3+ type TitleLabelType =
4+ | "authorview-streamgraph"
5+ | "authorview-knowledgemap"
6+ | "keywordview-streamgraph"
7+ | "keywordview-knowledgemap"
8+ | "geomap" ;
9+
10+ export const getHeadingLabel = (
11+ labelType : TitleLabelType ,
12+ localization : Localization ,
13+ ) => {
14+ switch ( labelType ) {
15+ case "authorview-streamgraph" :
16+ return localization . streamgraph_authors_label ;
17+ case "authorview-knowledgemap" :
18+ return localization . overview_authors_label ;
19+ case "keywordview-streamgraph" :
20+ return localization . streamgraph_label ;
21+ case "keywordview-knowledgemap" :
22+ return localization . overview_label ;
23+ case "geomap" :
24+ return localization . geomap_label ;
25+ default :
26+ throw new Error ( `Label of type '${ labelType } ' not supported.` ) ;
27+ }
28+ } ;
You can’t perform that action at this time.
0 commit comments