def join_component_view(component, view):
    """
    Pack a ComponentID and optional view into single tuple.

    Returns an object compatible with ``data.__getitem__`` and related methods.
    Handles edge cases of when view is None, a scalar, a tuple, etc.

    Parameters
    ----------
    component : `~glue.core.component_id.ComponentID`
        The ComponentID to pack
    view
        The view into the data, or `None`

    """
    if view is None:
        return component
    result = [component]
    try:
        result.extend(view)
    except TypeError:  # view is a scalar
        result = [component, view]

    return tuple(result)