Skip to content

Commit

Permalink
feat: added checkbox behavior for children checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-cho committed Nov 6, 2024
1 parent 7d91ad3 commit af93a3f
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 237 deletions.
3 changes: 1 addition & 2 deletions resources/chat-view/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ <h1 class="text-3xl font-bold text-center text-zenml mb-8">ZenML Chat</h1>
<div class="flex flex-col w-full h-full">
<div
id="chatMessages"
class="space-y-4 mb-4 mt-4 overflow-y-auto flex-grow"
class="max-h-[calc(100vh-300px)] md:max-h-[calc(100vh-200px)]"
class="space-y-4 mb-4 mt-4 overflow-y-auto flex-grow max-h-[calc(100vh-300px)] md:max-h-[calc(100vh-200px)]"
>
${chatLogHtml}
</div>
Expand Down
39 changes: 34 additions & 5 deletions resources/chat-view/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,39 @@
vscode.postMessage({ command: 'updateProvider', provider: selectedProvider });
}

// Checkbox behavior for children checkboxes under pipeline runs
const pipelineRunsBox = document.querySelector('input[type="checkbox"][value="pipelineContext"]');
pipelineRunsBox.addEventListener('click', toggleTreeItemBoxes);

function toggleTreeItemBoxes() {
const pipelineRunsBox = document.querySelector(
'input[type="checkbox"][value="pipelineContext"]'
);

const pipelineRunBoxes = document.querySelectorAll(
'input[type="checkbox"][value*="Pipeline Run:"]'
);

// Condition: If the main checkbox is clicked, all children checkboxes should be checked.
if (pipelineRunsBox.checked) {
pipelineRunBoxes.forEach(checkbox => (checkbox.checked = true));
console.log('checked boxes: ', pipelineRunBoxes);
} else {
pipelineRunBoxes.forEach(checkbox => (checkbox.checked = false));
}

// Condition: If any of the children checkboxes are unchecked, then the main checkbox should be checked.
function updateMainCheckbox() {
const anyUnchecked = Array.from(pipelineRunBoxes).some(checkbox => !checkbox.checked);
pipelineRunsBox.checked = !anyUnchecked;
}

pipelineRunBoxes.forEach(checkbox => {
checkbox.addEventListener('change', updateMainCheckbox);
});
}

// Sends a message to the LLM
function sendMessage(event) {
event.preventDefault();
if (isInputDisabled) {
Expand Down Expand Up @@ -128,6 +161,7 @@

document.getElementById('clearChat').addEventListener('click', clearChatLog);

// Adds the message to the UI
function appendToChat(text, role) {
const chatMessages = document.getElementById('chatMessages');
let messageDiv;
Expand Down Expand Up @@ -430,18 +464,13 @@
});

const textarea = document.getElementById('messageInput');
const sendButton = document.getElementById('sendMessage');
const loader = document.getElementById('loader');
isInputDisabled = false;

function showLoader() {
loader.classList.add('loader');
}

function hideLoader() {
loader.classList.remove('loader');
}

textarea.addEventListener('keydown', e => {
if (e.key === 'Enter') {
if (e.shiftKey) {
Expand Down
Loading

0 comments on commit af93a3f

Please sign in to comment.