Skip to content

Commit

Permalink
lots of UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisclark committed Sep 7, 2024
1 parent 248a7f0 commit afb4922
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 20 deletions.
1 change: 0 additions & 1 deletion explorer/ee/db_connections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def post(self, request): # noqa

class DatabaseConnectionsListView(PermissionRequiredMixin, ExplorerContextMixin, ListView):

context_object_name = "sqlite_uploads"
permission_required = "connections_permission"
template_name = "connections/connections.html"
model = DatabaseConnection
Expand Down
21 changes: 16 additions & 5 deletions explorer/src/js/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function setupTableList() {
removeItemButton: true,
searchEnabled: true,
shouldSort: false,
position: 'bottom'
position: 'bottom',
placeholderValue: "Click to search for relevant tables"
});

// TODO - nasty. Should be refactored. Used by submitAssistantAsk to get relevant tables.
Expand All @@ -66,6 +67,16 @@ function setupTableList() {
});
});

const refreshTables = document.getElementById('refresh_tables_button');
refreshTables.addEventListener('click', (e) => {
e.preventDefault();
keys.forEach(k => {
choices.removeActiveItemsByValue(k);
});
selectRelevantTablesSql(choices, keys)
selectRelevantTablesRequest(choices, keys)
});

selectRelevantTablesSql(choices, keys);

document.addEventListener('docChanged', debounce(
Expand All @@ -81,16 +92,16 @@ function setupTableList() {
}

function selectRelevantTablesSql(choices, keys) {
const textContent = window.editor.state.doc.toString();
const textContent = window.editor.state.doc.toString().toLowerCase();
const textWords = new Set(textContent.split(/\s+/));
const hasKeys = keys.filter(key => textWords.has(key));
const hasKeys = keys.filter(key => textWords.has(key.toLowerCase()));
choices.setChoiceByValue(hasKeys);
}

function selectRelevantTablesRequest(choices, keys) {
const textContent = document.getElementById("id_assistant_input").value
const textWords = new Set(textContent.split(/\s+/));
const hasKeys = keys.filter(key => textWords.has(key));
const textWords = new Set(textContent.toLowerCase().split(/\s+/));
const hasKeys = keys.filter(key => textWords.has(key.toLowerCase()));
choices.setChoiceByValue(hasKeys);
}

Expand Down
5 changes: 3 additions & 2 deletions explorer/templates/assistant/table_description_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
{% block sql_explorer_content %}
<div class="container">
<h3>Table Annotations</h3>
<p>These will be injected into any AI assistant prompts that reference the annotated table.</p>
<p>Write some notes about your tables to help the AI Assistant do its job. Relevant annotations will be automatically injected into AI assistant requests.</p>
<p>Good annotations may describe the purposes of columns that are not obvious from their name alone, common joins to other tables, or the semantic meaning of enum values.</p>
<div class="mt-3">
<a href="{% url 'table_description_create' %}" class="btn btn-primary mb-3">Create New</a>
<a href="{% url 'table_description_create' %}" class="btn btn-primary mb-3">Create Annotation</a>
<table class="table table-striped table-hover">
<thead>
<tr>
Expand Down
13 changes: 5 additions & 8 deletions explorer/templates/connections/connection_upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@
{% block sql_explorer_content %}
<div class="container mt-5">
<div class="pt-3">
<h4>Upload a file</h4>
<h4>Create a connection from an uploaded file</h4>
<p>Supports .csv, .json, .db, and .sqlite files. JSON files with one JSON document per line are also supported. CSV/JSON data will be parsed and converted to SQLite. SQLite databases must <i>not</i> be password protected.</p>
<p></p>

<p>Appending to an existing connection will add a new table to the SQLite database, named after the uploaded file. If a table with the filename already exists, it will be replaced with the uploaded data.</p>
<form id="upload-form">
<div class="form-floating mb-3">
<select id="append" name="append" class="form-select">
<option value="" selected>-- Create new connection --</option>
<option value="" selected></option>
{% for connection in valid_connections %}
<option value="{{ connection.id }}">{{ connection.alias }}</option>
{% endfor %}
</select>
<label for="append">Append to existing connection:</label>
<span class="form-text text-muted">When appending, if a table with the filename already exists, it will be replaced with the uploaded data.</span>
<label for="append">Optional: Append to existing connection:</label>
</div>

<div id="drop-area" class="p-3 mb-4 bg-light border rounded" style="cursor: pointer">
<p class="lead mb-0">Drag and drop, or click to upload .csv, .json, .db, .sqlite.</p>
<p class="lead mb-0"><span class="fw-bold">Upload: </span>Drag and drop, or click to upload .csv, .json, .db, .sqlite.</p>
<input type="file" id="fileElem" style="display:none" accept=".db,.csv,.sqlite,.json">
<div class="progress mt-3" style="height: 20px;">
<div id="progress-bar" class="progress-bar" role="progressbar" style="width: 0;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
Expand Down
11 changes: 9 additions & 2 deletions explorer/templates/connections/connections.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
<div class="container">
<h3>Connections</h3>
<div class="mt-3">
<a href="{% url 'explorer_connection_create' %}" class="btn btn-primary mb-3">Add New Connection</a>
<a href="{% url 'explorer_upload_create' %}" class="btn btn-primary mb-3">Upload File</a>
<div class="d-flex align-items-center gap-2 mb-3">
<a href="{% url 'explorer_connection_create' %}" class="btn btn-primary">Add New Connection</a>
<a href="{% url 'explorer_upload_create' %}" class="btn btn-primary">Upload File</a>
{% if object_list|length == 0 %}
<span class="text-secondary d-flex align-items-center fw-bold">
<i class="bi-arrow-left me-1"></i>Connect to an existing database, or upload a csv, json, or sqlite file.
</span>
{% endif %}
</div>
<table class="table table-striped" id="connections_table">
<thead>
<tr>
Expand Down
5 changes: 4 additions & 1 deletion explorer/templates/explorer/assistant.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
</div>
<div class="assistant-icons" style="">
<div>
<i class="bi-plus-circle" id="select_all_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Select all"></i>
<i class="bi-check-all" id="select_all_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Add all"></i>
</div>
<div>
<i class="bi-trash" id="deselect_all_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Remove all"></i>
</div>
<div>
<i class="bi-repeat" id="refresh_tables_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Refresh autodetect"></i>
</div>
<div>
<i class="bi-card-list" id="assistant_history" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="History"></i>
</div>
Expand Down
5 changes: 4 additions & 1 deletion explorer/templates/explorer/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ <h2>
{% if query %}
<div class="position-relative float-end">
<small>
<span class="pe-3">
{% if query and can_change and assistant_enabled %}{{ form.few_shot }} {% translate "Assistant Example" %}{% endif %}
<i class="bi-question-circle" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Queries marked as examples will be sent, when relevant, to the AI Assistant as few-shot examples of how certain tables are used."></i>
</span>
<a href="#" title="Open in playground" id="playground_button">
<i class="bi-arrow-up-right-square"></i>
</a>
Expand Down Expand Up @@ -150,6 +154,5 @@ <h2>
</div>
<div class="container mt-1 text-end small">
{% if query and can_change and tasks_enabled %}{{ form.snapshot }} {% translate "Snapshot" %}{% endif %}
{% if query and can_change and assistant_enabled %}{{ form.few_shot }} {% translate "Assistant Example" %}{% endif %}
</div>
{% endblock %}
17 changes: 17 additions & 0 deletions explorer/templates/explorer/query_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ <h1 class="display-4 text-primary mb-4">Welcome to SQL Explorer!</h1>
</div>
</div>
</div>
{% elif object_list|length == 0 %}
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-8 text-center">
<h1 class="display-4 text-primary mb-4">Time to create a query</h1>
<p class="lead text-muted">
You have {{ connection_count }} connection{% if connection_count > 1 %}s{% endif %} created, now get cracking!
</p>
<p class="mb-4">
<a href="{% url 'query_create' %}" class="btn btn-secondary btn-lg">Create a Query</a> or <a href="{% url 'explorer_playground' %}" class="btn btn-secondary btn-lg">Play Around</a>
</p>
<p class="text-muted">
Need help? Check out the <a href="https://django-sql-explorer.readthedocs.io/en/latest/" class="text-decoration-underline">documentation</a>{% if hosted %} or <a href="mailto:support@sqlexplorer.io" class="text-decoration-underline">contact support</a>{% endif %}.
</p>
</div>
</div>
</div>
{% else %}
{% if recent_queries|length > 0 %}
<div class="container">
Expand Down

0 comments on commit afb4922

Please sign in to comment.