Skip to content

Commit

Permalink
better initial experience
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisclark committed Sep 5, 2024
1 parent b79a9e5 commit 893c6e1
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 141 deletions.
2 changes: 2 additions & 0 deletions explorer/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
# 500mb default max
EXPLORER_MAX_UPLOAD_SIZE = getattr(settings, "EXPLORER_MAX_UPLOAD_SIZE", 500 * 1024 * 1024)

EXPLORER_HOSTED = getattr(settings, "EXPLORER_HOSTED", True)


def has_assistant():
return EXPLORER_AI_API_KEY is not None
Expand Down
1 change: 0 additions & 1 deletion explorer/ee/db_connections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def save(self, *args, **kwargs):
DatabaseConnection.objects.filter(default=True).update(default=False)
else:
# If there is no default set yet, make this newly created one the default.
# Effectively this is for first-time installations.
has_default = DatabaseConnection.objects.filter(default=True).exists()
if not has_default:
self.default = True
Expand Down
7 changes: 6 additions & 1 deletion explorer/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["database_connection"].widget.choices = self.connections
if not self.instance.database_connection:
self.initial["database_connection"] = default_db_connection().alias
default_db = default_db_connection()
self.initial["database_connection"] = default_db_connection().alias if default_db else None
self.fields["database_connection"].widget.attrs["class"] = "form-select"

def clean(self):
Expand All @@ -66,6 +67,10 @@ def created_at_time(self):

@property
def connections(self):
default_db = default_db_connection()
if default_db is None:
return []

# Ensure the default connection appears first in the dropdown in the form
result = DatabaseConnection.objects.annotate(
custom_order=Case(
Expand Down
6 changes: 6 additions & 0 deletions explorer/templates/explorer/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ <h2>This is easy to fix, I promise!</h2>
<a class="nav-link{% if not query and view_name == 'query_favorites' %} active{% endif %}"
href="{% url 'query_favorites' %}"><i class="small me-1 bi-heart"></i>{% translate "Favorites" %}</a>
</li>
{% if hosted %}
<li class="nav-item">
<a class="nav-link"
href="/"><i class="small me-1 bi-arrow-return-left"></i>Manage</a>
</li>
{% endif %}
</ul>
</div>
</nav>
Expand Down
3 changes: 1 addition & 2 deletions explorer/templates/explorer/play.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h2>{% translate "Playground" %}</h2>
<div class="alert alert-danger db-error">{{ error|escape }}</div>
{% endif %}
{{ form.non_field_errors }}
{% if form.connections|length > 1 and can_change %}
{% if can_change %}
<div class="mb-3 form-floating">
{{ form.database_connection }}
<label for="id_database_connection" class="form-label">{% translate "Connection" %}</label>
Expand All @@ -26,7 +26,6 @@ <h2>{% translate "Playground" %}</h2>
<div class="d-none">
{{ form.database_connection }}
</div>
<div>{{ form.database_connection.value }}</div>
{% endif %}
<div class="row">
<div class="col">
Expand Down
2 changes: 1 addition & 1 deletion explorer/templates/explorer/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2>
<div class="alert alert-danger">{{ error|escape }}</div>
{% endfor %}{% endif %}
</div>
{% if form.connections|length > 1 and can_change %}
{% if can_change %}
<div class="mb-3 form-floating">
{{ form.database_connection }}
<label for="id_database_connection" class="form-label">{% translate "Connection" %}</label>
Expand Down
283 changes: 147 additions & 136 deletions explorer/templates/explorer/query_list.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions explorer/views/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from explorer.utils import allowed_query_pks, url_get_query_id
from explorer.views.auth import PermissionRequiredMixin
from explorer.views.mixins import ExplorerContextMixin
from explorer.ee.db_connections.models import DatabaseConnection


class ListQueryView(PermissionRequiredMixin, ExplorerContextMixin, ListView):
Expand Down Expand Up @@ -36,6 +37,7 @@ def recently_viewed(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["object_list"] = self._build_queries_and_headers()
context["connection_count"] = DatabaseConnection.objects.count()
context["recent_queries"] = self.recently_viewed()
context["tasks_enabled"] = app_settings.ENABLE_TASKS
context["vite_dev_mode"] = app_settings.VITE_DEV_MODE
Expand Down
1 change: 1 addition & 0 deletions explorer/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def gen_ctx(self):
"csrf_cookie_name": settings.CSRF_COOKIE_NAME,
"csrf_token_in_dom": settings.CSRF_COOKIE_HTTPONLY or settings.CSRF_USE_SESSIONS,
"view_name": self.request.resolver_match.view_name,
"hosted": app_settings.EXPLORER_HOSTED
}

def get_context_data(self, **kwargs):
Expand Down

0 comments on commit 893c6e1

Please sign in to comment.