🔍 Code Extractor

function controlled_docs_navigation

Maturity: 46

Navigation controller for a Streamlit-based controlled documents module that manages document and review dashboards with URL parameter-based routing.

File:
/tf/active/vicechatdev/datacapture_integrated.py
Lines:
4216 - 4275
Complexity:
moderate

Purpose

This function serves as the main navigation hub for a controlled documents management system built with Streamlit. It provides a sidebar navigation menu with four options: viewing document dashboard, viewing review dashboard, creating new documents, and returning to main menu. The function handles URL query parameters to enable deep linking to specific documents or reviews, and routes users to appropriate rendering functions based on their selection and URL parameters.

Source Code

def controlled_docs_navigation():
    """Navigation for the controlled documents module."""
    st.sidebar.title("Controlled Documents")
    
    # Sidebar navigation
    nav_option = st.sidebar.radio(
        "Navigation",
        options=[
            "Document Dashboard", 
            "Review Dashboard",
            "Create New Document",
            "Return to Main Menu"
        ]
    )
    
    # Process navigation selection
    if nav_option == "Document Dashboard":
        # Check URL parameters for document ID
        params = st.experimental_get_query_params()
        document_id = params.get("document_id", [None])[0]
        mode = params.get("mode", ["view"])[0]
        
        if document_id:
            # Render document form in requested mode
            render_document_form(document_id=document_id, mode=mode)
        else:
            # Render document dashboard
            render_document_dashboard()
    
    elif nav_option == "Review Dashboard":
        # Check URL parameters for review ID
        params = st.experimental_get_query_params()
        review_id = params.get("review_id", [None])[0]
        
        if review_id:
            # Handle specific review
            st.write(f"Viewing review: {review_id}")
            # This would call a specific review component
        else:
            # Render review dashboard
            render_review_dashboard()
    
    elif nav_option == "Create New Document":
        # Render document form in create mode
        params = st.experimental_get_query_params()
        template_id = params.get("template_id", [None])[0]
        department_id = params.get("department_id", [None])[0]
        doc_type = params.get("doc_type", [None])[0]
        
        render_document_form(
            mode="create",
            template_id=template_id,
            department_id=department_id,
            doc_type=doc_type
        )
    
    elif nav_option == "Return to Main Menu":
        # Clear module selection and return to main menu
        st.session_state['current_module'] = None
        st.experimental_rerun()

Return Value

This function does not return any value (implicitly returns None). It operates by side effects, rendering Streamlit UI components and managing navigation state through st.session_state and URL parameters.

Dependencies

  • streamlit
  • controlled_doc_system.ui.document_dashboard
  • controlled_doc_system.ui.review_dashboard
  • controlled_doc_system.ui.document_form

Required Imports

import streamlit as st
from controlled_doc_system.ui.document_dashboard import render_document_dashboard
from controlled_doc_system.ui.review_dashboard import render_review_dashboard
from controlled_doc_system.ui.document_form import render_document_form

Usage Example

import streamlit as st
from controlled_doc_system.ui.document_dashboard import render_document_dashboard
from controlled_doc_system.ui.review_dashboard import render_review_dashboard
from controlled_doc_system.ui.document_form import render_document_form

# Initialize session state if needed
if 'current_module' not in st.session_state:
    st.session_state['current_module'] = 'controlled_docs'

# Call the navigation function
controlled_docs_navigation()

# Example URL parameters for deep linking:
# ?document_id=123&mode=edit - Opens document 123 in edit mode
# ?review_id=456 - Opens review 456
# ?template_id=789&department_id=10&doc_type=SOP - Creates new document with template

Best Practices

  • Ensure st.session_state['current_module'] is initialized before calling this function to avoid KeyError
  • Use URL parameters for deep linking: document_id, mode, review_id, template_id, department_id, doc_type
  • The function uses st.experimental_get_query_params() which may be deprecated in newer Streamlit versions - consider using st.query_params instead
  • The function uses st.experimental_rerun() which may be deprecated - consider using st.rerun() in newer Streamlit versions
  • Implement proper error handling in the render_* functions to handle invalid IDs or missing data
  • Consider adding authentication/authorization checks before rendering sensitive document or review information
  • The navigation state is managed through both session state and URL parameters - ensure consistency between them
  • When creating new documents, validate that template_id, department_id, and doc_type are valid before passing to render_document_form

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_page 67.0% similar

    Renders the main navigation page for the FileCloud Data Processor application, providing authenticated users with access to various modules including document audit, controlled documents, settings, and reports.

    From: /tf/active/vicechatdev/datacapture_integrated.py
  • function main_v7 65.1% similar

    Main entry point for a Streamlit-based FileCloud Data Processor application that handles authentication, session state management, and navigation between multiple modules including document audit, controlled documents, settings, and reports.

    From: /tf/active/vicechatdev/datacapture_integrated.py
  • class ControlledDocApp 60.1% similar

    A standalone Panel web application class that provides a complete controlled document management system with user authentication, navigation, and document lifecycle management features.

    From: /tf/active/vicechatdev/panel_app.py
  • function create_document 57.1% similar

    Creates a new controlled document in a document management system with versioning, audit trails, and optional initial content.

    From: /tf/active/vicechatdev/document_controller_backup.py
  • class CDocsApp 50.4% similar

    Panel application for the CDocs Controlled Document System. This class provides a complete Panel application with navigation, user authentication, and all document management features.

    From: /tf/active/vicechatdev/cdocs_panel_app.py
← Back to Browse