-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from feedzai/develop
Fixed an issue where series values having spaces and invalid characters would invalidate class names
- Loading branch information
Showing
16 changed files
with
81 additions
and
44 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* Other licensing options may be available, please reach out to [email protected] for more information. | ||
*/ | ||
import { getElements } from "../../utils/getElements"; | ||
import { toSafeClassName } from "../../utils/toSafeClassname"; | ||
|
||
type SelectorType = { | ||
element?: string; | ||
|
@@ -35,8 +36,8 @@ function setElementAttributes( | |
} | ||
|
||
function addSeriesClass(element: HTMLElement, seriesValue: string): void { | ||
const seriesClass = seriesValue.replace(/ /g, "-"); | ||
element.classList.add(`series:${seriesClass}`); | ||
const seriesClass = toSafeClassName(seriesValue); | ||
element.classList.add(`${seriesClass}`); | ||
} | ||
|
||
/** | ||
|
@@ -65,7 +66,8 @@ export function addAriaLabels({ | |
setElementAttributes(element, item, descriptor); | ||
|
||
if (multiSeries) { | ||
addSeriesClass(element, item[multiSeries] as string); | ||
const series = item[multiSeries] as string; | ||
addSeriesClass(element, series); | ||
} | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* Other licensing options may be available, please reach out to [email protected] for more information. | ||
*/ | ||
|
||
/** | ||
* Converts the name of the series into a version suitable for a class | ||
* | ||
* @export | ||
* @param {string} multiSeriesValues - One of the multiserie string values | ||
* @return {string} - The string value refactored to fit a className | ||
*/ | ||
export function toSafeClassName(multiSeriesValues: string): string { | ||
// Remove leading and trailing whitespace | ||
let safeClassName = multiSeriesValues.trim(); | ||
|
||
// Replace spaces and invalid characters with dashes | ||
safeClassName = safeClassName.replace(/[^a-zA-Z0-9_-]/g, "-"); | ||
|
||
// Replace multiple consecutive dashes with a single dash | ||
safeClassName = safeClassName.replace(/-+/g, "-"); | ||
|
||
return "series_" + safeClassName; | ||
} |