<commit_before>import React, { Component, PropTypes } from "react";
import { connect } from "react-redux";
import PersonaBarPageHeader from "dnn-persona-bar-page-header";
import {
    visiblePanel as VisiblePanelActions
} from "../actions";
import Body from "./body";
import PersonaBarPage from "dnn-persona-bar-page";
import HtmlEditorManager from "./moreSettings/htmlEditorManager";
import LanguageVerifier from "./languageSettings/languageVerifier";
import LanguagePack from "./languageSettings/languagePack";
import LocalizedContent from "./languageSettings/localizedContent";
import TranslatePageContent from "./translatePageContent/translatePageContent";
import EditLanguagePanel from "./editLanguagePanel";
import SiteLanguageSelector from "./siteLanguageSelector";
import utilities from "utils";
import resx from "../resources";

const Pages = {
    Default: 0,
    HtmlEditorManager: 1,
    LanguageVerifier: 2,
    LanguageEditor: 3,
    LanguagePack: 4,
    LocalizedContent: 5,
    TranslatePageContent: 6
};

class App extends Component {
    constructor() {
        super();
        this.state = {
            portalId: utilities.settings.portalId,
            cultureCode: utilities.settings.cultureCode,
            referrer: utilities.settings.referrer,
            referrerText: utilities.settings.referrerText,
            backToReferrerFunc: this.backToReferrer.bind(this, utilities.settings.backToReferrerFunc),
            bodyShowing: true
        };
        this.changePortalId = this.changePortalId.bind(this);
        this.changeCultureCode = this.changeCultureCode.bind(this);
        this.changePortalIdCultureCode = this.changePortalIdCultureCode.bind(this);
    }

    backToReferrer(callback) {
        if (typeof callback === "function") {
            callback();
        }
        setTimeout(() => {
            this.setState({
                referrer: "",
                referrerText: "",
                backToReferrerFunc: null
            });
        }, 750);
    }

    changePortalId(portalId) {
        this.setState({
            bodyShowing: false
        }, () => {
            this.setState({
                bodyShowing: true,
                portalId
            });
        });
    }

    changeCultureCode(cultureCode) {
        this.setState({
            bodyShowing: false
        }, () => {
            this.setState({
                bodyShowing: true,
                cultureCode
            });
        });
    }

    changePortalIdCultureCode(portalId, cultureCode) {
        this.setState({
            bodyShowing: false
        }, () => {
            this.setState({
                bodyShowing: true,
                portalId,
                cultureCode
            });
        });
    }

    updateReferrerInfo(event) {
        this.setState({
            referrer: event.referrer,
            referrerText: event.referrerText,
            backToReferrerFunc: this.backToReferrer.bind(this, event.backToReferrerFunc)
        });
    }

    componentWillMount() {
        const {state, props} = this;

        // // Listen for the event.
        document.addEventListener("portalIdChanged", (e) => {
            if (state.portalId !== e.portalId) {
                this.changePortalId(e.portalId);
            }
            this.updateReferrerInfo(e);
        }, false);

        document.addEventListener("cultureCodeChanged", (e) => {
            if (state.cultureCode !== e.cultureCode) {
                this.changeCultureCode(e.cultureCode);
            }
            this.updateReferrerInfo(e);
        }, false);

        document.addEventListener("portalIdCultureCodeChanged", (e) => {
            if (state.cultureCode !== e.cultureCode && this.state.portalId !== e.portalId) {
                this.changePortalIdCultureCode(e.portalId, e.cultureCode);
            }
            this.updateReferrerInfo(e);
        }, false);

        if (state.portalId !== props.portalId && state.cultureCode !== props.cultureCode) {
            this.changePortalIdCultureCode(props.portalId, props.cultureCode);
        }
        else if (state.portalId !== props.portalId) {
            this.changePortalId(props.portalId);
        }
        else if (state.cultureCode !== props.cultureCode) {
            this.changeCultureCode(props.cultureCode);
        }
    }

    componentWillReceiveProps(props) {
        const {state} = this;
        if (state.portalId !== props.portalId && props.portalId !== undefined) {
            this.changePortalId(props.portalId);
        }
        if (state.cultureCode !== props.cultureCode && props.cultureCode !== undefined) {
            this.changeCultureCode(props.cultureCode);
        }
    }

    openPersonaBarPage(pageNumber) {
        const {props} = this;
        props.dispatch(VisiblePanelActions.selectPanel(pageNumber));
    }

    closePersonaBarPage() {
        const {props} = this;
        props.dispatch(VisiblePanelActions.selectPanel(Pages.Default));
    }

    render() {
        const {props, state} = this;
        return (
            <div className="siteSettings-app">
                <SiteLanguageSelector
                    portalId={state.portalId}
                    cultureCode={state.cultureCode}
                    referrer={state.referrer}
                    referrerText={state.referrerText}
                    backToReferrerFunc={state.backToReferrerFunc}
                    />
                <PersonaBarPage isOpen={props.selectedPage === 0}>
                    <PersonaBarPageHeader title={resx.get("nav_SiteSettings")}>
                    </PersonaBarPageHeader>
                    <Body
                        portalId={state.portalId}
                        showing={state.bodyShowing}
                        referrer={state.referrer}
                        referrerText={state.referrerText}
                        backToReferrerFunc={state.backToReferrerFunc}
                        openLanguagePack={this.openPersonaBarPage.bind(this, Pages.LanguagePack)}
                        openLanguageVerifier={this.openPersonaBarPage.bind(this, Pages.LanguageVerifier)}
                        openHtmlEditorManager={this.openPersonaBarPage.bind(this, Pages.HtmlEditorManager)}
                        openLocalizedContent={this.openPersonaBarPage.bind(this, Pages.LocalizedContent)}
                        cultureCode={state.cultureCode}
                        />
                </PersonaBarPage>

                <PersonaBarPage isOpen={props.selectedPage === Pages.HtmlEditorManager}>
                    <PersonaBarPageHeader title={resx.get("nav_SiteSettings")}>
                    </PersonaBarPageHeader>
                    {props.selectedPage === Pages.HtmlEditorManager &&
                        <HtmlEditorManager portalId={state.portalId} closeHtmlEditorManager={this.closePersonaBarPage.bind(this)} />
                    }
                </PersonaBarPage>

                <PersonaBarPage isOpen={props.selectedPage === Pages.LanguageVerifier}>
                    <PersonaBarPageHeader title={resx.get("ResourceFileVerifier")}>
                    </PersonaBarPageHeader>
                    <LanguageVerifier portalId={state.portalId} closeLanguageVerifier={this.closePersonaBarPage.bind(this)} />
                </PersonaBarPage>

                {props.selectedPage === Pages.LanguageEditor && <PersonaBarPage isOpen={props.selectedPage === Pages.LanguageEditor}>
                    <PersonaBarPageHeader title={resx.get("LanguageEditor.Header")} />
                    <EditLanguagePanel portalId={state.portalId} backToSiteSettings={this.closePersonaBarPage.bind(this)} />
                </PersonaBarPage>}

                <PersonaBarPage isOpen={props.selectedPage === Pages.LanguagePack}>
                    <PersonaBarPageHeader title={resx.get("CreateLanguagePack")} />
                    <LanguagePack closeLanguagePack={this.closePersonaBarPage.bind(this)} />
                </PersonaBarPage>

                <PersonaBarPage isOpen={props.selectedPage === Pages.LocalizedContent}>
                    <PersonaBarPageHeader title={resx.get("EnableLocalizedContent")} />
                    <LocalizedContent portalId={state.portalId} closePersonaBarPage={this.closePersonaBarPage.bind(this)} isOpen={props.selectedPage === Pages.LocalizedContent} />
                </PersonaBarPage>
<commit_msg>DNN-9493: Fixed site settings state issues<commit_after>import React, { Component, PropTypes } from "react";
import { connect } from "react-redux";
import PersonaBarPageHeader from "dnn-persona-bar-page-header";
import {
    visiblePanel as VisiblePanelActions
} from "../actions";
import Body from "./body";
import PersonaBarPage from "dnn-persona-bar-page";
import HtmlEditorManager from "./moreSettings/htmlEditorManager";
import LanguageVerifier from "./languageSettings/languageVerifier";
import LanguagePack from "./languageSettings/languagePack";
import LocalizedContent from "./languageSettings/localizedContent";
import TranslatePageContent from "./translatePageContent/translatePageContent";
import EditLanguagePanel from "./editLanguagePanel";
import SiteLanguageSelector from "./siteLanguageSelector";
import utilities from "utils";
import resx from "../resources";

const Pages = {
    Default: 0,
    HtmlEditorManager: 1,
    LanguageVerifier: 2,
    LanguageEditor: 3,
    LanguagePack: 4,
    LocalizedContent: 5,
    TranslatePageContent: 6
};

class App extends Component {
    constructor() {
        super();
        this.state = {
            portalId: utilities.settings.portalId,
            cultureCode: utilities.settings.cultureCode,
            referrer: utilities.settings.referrer,
            referrerText: utilities.settings.referrerText,
            backToReferrerFunc: this.backToReferrer.bind(this, utilities.settings.backToReferrerFunc),
            bodyShowing: true
        };
        this.changePortalId = this.changePortalId.bind(this);
        this.changeCultureCode = this.changeCultureCode.bind(this);
        this.changePortalIdCultureCode = this.changePortalIdCultureCode.bind(this);
    }

    backToReferrer(callback) {
        if (typeof callback === "function") {
            callback();
        }
        setTimeout(() => {
            this.setState({
                referrer: "",
                referrerText: "",
                backToReferrerFunc: null
            });
        }, 750);
    }

    changePortalId(portalId) {
        if (portalId === undefined) return;
        this.setState({
            bodyShowing: false
        }, () => {
            this.setState({
                bodyShowing: true,
                portalId
            });
        });
    }

    changeCultureCode(cultureCode) {
        if (cultureCode === undefined) return;
        this.setState({
            bodyShowing: false
        }, () => {
            this.setState({
                bodyShowing: true,
                cultureCode
            });
        });
    }

    changePortalIdCultureCode(portalId, cultureCode) {
        if (portalId === undefined && cultureCode === undefined) return;
        else if (portalId === undefined) {
            this.changeCultureCode(cultureCode);
        }
        else if (cultureCode === undefined) {
            this.changePortalId(portalId);
        }
        else {
            this.setState({
                bodyShowing: false
            }, () => {
                this.setState({
                    bodyShowing: true,
                    portalId,
                    cultureCode
                });
            });
        }
    }

    updateReferrerInfo(event) {
        this.setState({
            referrer: event.referrer,
            referrerText: event.referrerText,
            backToReferrerFunc: this.backToReferrer.bind(this, event.backToReferrerFunc)
        });
    }

    componentWillMount() {
        const {state, props} = this;

        // // Listen for the event.
        document.addEventListener("portalIdChanged", (e) => {
            this.changePortalId(e.portalId);
            this.updateReferrerInfo(e);
        }, false);

        document.addEventListener("cultureCodeChanged", (e) => {
            this.changeCultureCode(e.cultureCode);
            this.updateReferrerInfo(e);
        }, false);

        document.addEventListener("portalIdCultureCodeChanged", (e) => {
            this.changePortalIdCultureCode(e.portalId, e.cultureCode);
            this.updateReferrerInfo(e);
        }, false);

        if (state.portalId !== props.portalId && state.cultureCode !== props.cultureCode) {
            this.changePortalIdCultureCode(props.portalId, props.cultureCode);
        }
        else if (state.portalId !== props.portalId) {
            this.changePortalId(props.portalId);
        }
        else if (state.cultureCode !== props.cultureCode) {
            this.changeCultureCode(props.cultureCode);
        }
    }

    componentWillReceiveProps(props) {
        const {state} = this;
        if (state.portalId !== props.portalId && state.cultureCode !== props.cultureCode) {
            this.changePortalIdCultureCode(props.portalId, props.cultureCode);
        }
        else if (state.portalId !== props.portalId) {
            this.changePortalId(props.portalId);
        }
        else if (state.cultureCode !== props.cultureCode) {
            this.changeCultureCode(props.cultureCode);
        }
    }

    openPersonaBarPage(pageNumber) {
        const {props} = this;
        props.dispatch(VisiblePanelActions.selectPanel(pageNumber));
    }

    closePersonaBarPage() {
        const {props} = this;
        props.dispatch(VisiblePanelActions.selectPanel(Pages.Default));
    }

    render() {
        const {props, state} = this;
        return (
            <div className="siteSettings-app">
                <SiteLanguageSelector
                    portalId={state.portalId}
                    cultureCode={state.cultureCode}
                    referrer={state.referrer}
                    referrerText={state.referrerText}
                    backToReferrerFunc={state.backToReferrerFunc}
                />
                <PersonaBarPage isOpen={props.selectedPage === 0}>
                    <PersonaBarPageHeader title={resx.get("nav_SiteSettings")}>
                    </PersonaBarPageHeader>
                    <Body
                        portalId={state.portalId}
                        showing={state.bodyShowing}
                        referrer={state.referrer}
                        referrerText={state.referrerText}
                        backToReferrerFunc={state.backToReferrerFunc}
                        openLanguagePack={this.openPersonaBarPage.bind(this, Pages.LanguagePack)}
                        openLanguageVerifier={this.openPersonaBarPage.bind(this, Pages.LanguageVerifier)}
                        openHtmlEditorManager={this.openPersonaBarPage.bind(this, Pages.HtmlEditorManager)}
                        openLocalizedContent={this.openPersonaBarPage.bind(this, Pages.LocalizedContent)}
                        cultureCode={state.cultureCode}
                    />
                </PersonaBarPage>

                <PersonaBarPage isOpen={props.selectedPage === Pages.HtmlEditorManager}>
                    <PersonaBarPageHeader title={resx.get("nav_SiteSettings")}>
                    </PersonaBarPageHeader>
                    {props.selectedPage === Pages.HtmlEditorManager &&
                        <HtmlEditorManager portalId={state.portalId} closeHtmlEditorManager={this.closePersonaBarPage.bind(this)} />
                    }
                </PersonaBarPage>

                <PersonaBarPage isOpen={props.selectedPage === Pages.LanguageVerifier}>
                    <PersonaBarPageHeader title={resx.get("ResourceFileVerifier")}>
                    </PersonaBarPageHeader>
                    <LanguageVerifier portalId={state.portalId} closeLanguageVerifier={this.closePersonaBarPage.bind(this)} />
                </PersonaBarPage>

                {props.selectedPage === Pages.LanguageEditor && <PersonaBarPage isOpen={props.selectedPage === Pages.LanguageEditor}>
                    <PersonaBarPageHeader title={resx.get("LanguageEditor.Header")} />
                    <EditLanguagePanel portalId={state.portalId} backToSiteSettings={this.closePersonaBarPage.bind(this)} />
                </PersonaBarPage>}

                <PersonaBarPage isOpen={props.selectedPage === Pages.LanguagePack}>
                    <PersonaBarPageHeader title={resx.get("CreateLanguagePack")} />
                    <LanguagePack closeLanguagePack={this.closePersonaBarPage.bind(this)} />
                </PersonaBarPage>

                <PersonaBarPage isOpen={props.selectedPage === Pages.LocalizedContent}>
                    <PersonaBarPageHeader title={resx.get("EnableLocalizedContent")} />
                    <LocalizedContent portalId={state.portalId} closePersonaBarPage={this.closePersonaBarPage.bind(this)} isOpen={props.selectedPage === Pages.LocalizedContent} />
                </PersonaBarPage>

{'fraction_non_alphanumeric': 0.10741044251931632, 'fraction_numerical': 0.0015218918286115663, 'mean_word_length': 2.057991766601038, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 75, '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': '380841', 'n_tokens_mistral': 4546, 'n_tokens_neox': 4401, 'n_words': 666}