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

Show warning when there's no available connection #11

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/assets/sql_cell/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ button {
border-bottom: 0;
}

.info-box {
.help-box {
padding: 16px;
white-space: pre-wrap;
font-weight: 500;
Expand Down Expand Up @@ -162,3 +162,27 @@ select.input {
background-size: 10px;
padding-right: 28px;
}

.info-box {
margin-bottom: 24px;
padding: 16px;
border-radius: 0.5rem;
font-weight: 500;
font-size: 0.875rem;
background-color: var(--gray-100);
color: var(--gray-500);
}

.info-box p {
margin: 0;
padding: 0.3em 0;
}

.info-box p:first-child {
padding-top: 0;
}

.strong {
color: var(--gray-600);
padding-left: 0;
}
14 changes: 11 additions & 3 deletions lib/assets/sql_cell/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export function init(ctx, payload) {
ctx.root.innerHTML = `
<div class="app">
<div>
<div id="conn-info-box" class="info-box">
<p>To successfully query, you need at least one database connection available.</p>
<p>To create a database connection, you can add the <span class="strong">Database connection</span> smart cell.</p>
</div>
<div class="header">
<div class="inline-field">
<label class="inline-input-label">Query</label>
Expand All @@ -24,7 +28,7 @@ export function init(ctx, payload) {
</button>
</div>
</div>
<div id="help-box" class="section info-box hidden">To dynamically inject values into the query use double curly braces, like {{name}}.</div>
<div id="help-box" class="section help-box hidden">To dynamically inject values into the query use double curly braces, like {{name}}.</div>
<div id="settings-box" class="section settings-box hidden">
<div class="field">
<label class="input-label">Timeout (s)</label>
Expand All @@ -38,6 +42,7 @@ export function init(ctx, payload) {
connections: payload.connections,
};

const noConnEl = ctx.root.querySelector("#conn-info-box");
const connectionEl = ctx.root.querySelector(`[name="connection_variable"]`);
renderConnectionSelect(payload.connections, payload.connection);

Expand All @@ -64,11 +69,11 @@ export function init(ctx, payload) {
ctx.pushEvent("update_timeout", event.target.value);
});

helpToggleButton.addEventListener("click", (event) => {
helpToggleButton.addEventListener("click", (_) => {
helpBoxEl.classList.toggle("hidden");
});

settingsToggleButton.addEventListener("click", (event) => {
settingsToggleButton.addEventListener("click", (_) => {
settingsBoxEl.classList.toggle("hidden");
});

Expand Down Expand Up @@ -101,16 +106,19 @@ export function init(ctx, payload) {
renderConnectionOptions([]);
connectionEl.classList.add("nonexistent");
connectionEl.disabled = true;
noConnEl.classList.remove("hidden");
} else if (connections.some((c) => c.variable === connection.variable)) {
renderConnectionOptions(connections);
connectionEl.value = connection.variable;
connectionEl.classList.remove("nonexistent");
connectionEl.disabled = false;
noConnEl.classList.add("hidden");
} else {
renderConnectionOptions([connection, ...connections]);
connectionEl.value = connection.variable;
connectionEl.classList.add("nonexistent");
connectionEl.disabled = false;
noConnEl.classList.add("hidden");
}
}

Expand Down