<commit_before>import * as React from 'react'

import { SideNav } from './SideNav'

import { ISideNavProp, INavSelectionArg } from "react-sidenav/types";
import { withRouter, RouteComponentProps } from 'react-router-dom'
import { PATH_SEPARATOR } from './constants'

type SideNavWithRR4Prop = ISideNavProp & RouteComponentProps<{}>
export const withRR4 = () => {
    class BaseSideNavWithRR4 extends React.Component<SideNavWithRR4Prop, { selectedPath: string }> {

        constructor(props: SideNavWithRR4Prop) {
            super(props)
            const path = this.props.location.pathname

            this.state = { selectedPath: this.props.selectedPath }
        }

        public onItemSelection = (arg: INavSelectionArg) => {
            const { match } = this.props
            const { payload } = arg
            const withToPayload = payload as { to: string }
            if ( payload && withToPayload.to ) {
                this.props.history.push(`${match.url}/${withToPayload.to}`)
            } else {
                const path = arg.path.split(PATH_SEPARATOR).join('/')
                this.props.history.push(`${match.url}/${path}`)

            }
            if ( this.props.onItemSelection ) {
                this.props.onItemSelection(arg)
            }
        }

        public componentDidUpdate(prevProps: SideNavWithRR4Prop) {
            if ( this.props.selectedPath !== prevProps.selectedPath ) {
                this.setState({ selectedPath: this.props.selectedPath })
            }
        }

        public render() {
            const {
                defaultSelectedPath,<commit_msg>will not append extra / and fixes #46<commit_after>import * as React from 'react'

import { SideNav } from './SideNav'

import { ISideNavProp, INavSelectionArg } from "react-sidenav/types";
import { withRouter, RouteComponentProps } from 'react-router-dom'
import { PATH_SEPARATOR } from './constants'

type SideNavWithRR4Prop = ISideNavProp & RouteComponentProps<{}> & { onHistoryChange?: (arg: INavSelectionArg) => void }
export const withRR4 = () => {
    class BaseSideNavWithRR4 extends React.Component<SideNavWithRR4Prop, { selectedPath: string }> {

        constructor(props: SideNavWithRR4Prop) {
            super(props)
            const path = this.props.location.pathname

            this.state = { selectedPath: this.props.selectedPath }
        }

        public onItemSelection = (arg: INavSelectionArg) => {
            const { match } = this.props
            const { payload } = arg
            const withToPayload = payload as { to: string }
            const slash = match.url.endsWith('/') ? '' : '/'
            if ( payload && withToPayload.to ) {
                this.props.history.push(`${match.url}${slash}${withToPayload.to}`)
            } else {
                const path = arg.path.split(PATH_SEPARATOR).join('/')
                this.props.history.push(`${match.url}${slash}${path}`)

            }
            if ( this.props.onItemSelection ) {
                this.props.onItemSelection(arg)
            }
            if ( this.props.onHistoryChange ) {
                this.props.onHistoryChange(arg)
            }
        }

        public componentDidUpdate(prevProps: SideNavWithRR4Prop) {
            if ( this.props.selectedPath !== prevProps.selectedPath ) {
                this.setState({ selectedPath: this.props.selectedPath })
            }
        }

        public render() {
            const {
                defaultSelectedPath,
{'fraction_non_alphanumeric': 0.11396743787489289, 'fraction_numerical': 0.003998857469294488, 'mean_word_length': 2.104609929078014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5582885', 'n_tokens_mistral': 974, 'n_tokens_neox': 947, 'n_words': 187}