Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken tab navigation in secrets #4048

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

u1735067
Copy link
Contributor

@u1735067 u1735067 commented Jul 5, 2023

Closes: #4048

What's Changed

This add the parent javascript block in the secret template, to restore tab functionnality.

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@glennmatthews glennmatthews merged commit 65e9f2e into nautobot:develop Jul 5, 2023
16 of 17 checks passed
@JostLuebbe
Copy link

I believe this change may have introduced a new bug. When attempting to press the "Check Secret" button on a Secret's page an Uncaught ReferenceError: checkSecret is not defined error is thrown in the console for me:
image

I also get an Uncaught SyntaxError: expected expression, got '<' error upon loading a secret's page:
image

From looking at the source I think this is due to the nested <script> tags:

<script>
    
<script>
    var clipboard = new ClipboardJS('.btn');

    clipboard.on('success', function (e) {});

    clipboard.on('error', function (e) {});

    
    // Set initial history state
    if (location.pathname == "/extras/secrets/common-enable-secret/"){
        var tab_id = "main";
        var tab_url = location.origin + location.pathname
        var query_string = location.search.replace("?", "")

        if(query_string.includes("tab")){
            query_params = query_string.split("&")

            tab_query_string = query_params.find(params => params.startsWith("tab"))
            tab_id = tab_query_string.split("=")[1]

            query_string_excluding_tab = query_params.filter(params => !params.startsWith("tab"))
            query_string = query_string_excluding_tab.join("&")
        }

        final_query_string = query_string ? "&" + query_string : ""

        window.history.replaceState({id: tab_id}, document.title, `${tab_url}?tab=${tab_id}${final_query_string}`);
        $(`#tabs a[href="/extras/secrets/common-enable-secret/#${tab_id}"]`).tab('show');

    }


    function switch_tab(tab_href, reload=false) {

        let [tab_url, tab_id] = tab_href.split("#")

        if (location.pathname != "/extras/secrets/common-enable-secret/")
            window.location.href = `${tab_url}?tab=${tab_id}`;
        else if (window.history.state["id"] != tab_id){
            window.history.pushState({id: tab_id}, document.title, `${tab_url}?tab=${tab_id}`);
        }

        // If set, reload the page after asserting state.
        reload && window.location.reload();

    }

    window.onpopstate = function(event) {
        if(event)
            $(`#tabs a[href="/extras/secrets/common-enable-secret/#${event.state.id}"]`).tab('show');
    }
    // Toggle v -. >
    $("#accordion .accordion-toggle").click(function () {
        $(this).toggleClass("mdi-chevron-down mdi-chevron-right");
    });
    // Dynamically collapse/expand all when clicking the "Collapse All" button, and then update the button text.
    $('#accordion-toggle-all').click(function () {

        if ($(this).data("lastState") === null || $(this).data("lastState") === 1) {
            $('.collapse').collapse('show');
            $(this).data("lastState", 0);

            $("#accordion .accordion-toggle").addClass("mdi-chevron-down").removeClass("mdi-chevron-right");

            $(this).text("Collapse All");
        }
        else {
            $('[class^=collapseme]').removeData('bs.collapse').collapse({parent: false, toggle: false})
            .collapse('hide')
            .removeData('bs.collapse')
            .collapse({parent: '#accordion', toggle: false});

            $(this).data("lastState", 1);
            $("#accordion .accordion-toggle").addClass("mdi-chevron-right").removeClass("mdi-chevron-down");

            $(this).text("Expand All");
        }
    });
</script>

    function checkSecret() {
        ...
    }
</script>

Perhaps the change should add {{ block.super }} outside of the script tag?

@glennmatthews
Copy link
Contributor

I think you're absolutely right. Sorry we didn't catch this! Should be a simple enough fix. Would you like to file an issue and/or open a PR for the credit? :-)

@u1735067 u1735067 deleted the patch-3 branch July 17, 2023 14:18
@u1735067
Copy link
Contributor Author

Oww, sorry about that, I should test more!

@JostLuebbe
Copy link

All good! Just glad it wasn't a me problem honestly. I opened an issue for this but am not ready to do a PR at this time so if someone else would be able to I'd really appreciate it!

@glennmatthews glennmatthews mentioned this pull request Jul 18, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants