Skip to content

Commit

Permalink
omplement "Validate All Pipelines" option within the choices for the …
Browse files Browse the repository at this point in the history
…Validate button.
  • Loading branch information
DjamilaBaroudi committed May 30, 2024
1 parent 3b29459 commit 0fca218
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dist
node_modules
.vscode-test/
*.vsix
.DS_Store
.DS_Store
.bruin.yml
13 changes: 12 additions & 1 deletion src/panels/BruinPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,24 @@ export class BruinPanel {
console.error("No workspace folder found.");
return;
}

const validatorAll = new BruinValidate(
getDefaultBruinExecutablePath(),
workspaceFolder.uri.fsPath
);
console.log("Validating All pipelines########################", workspaceFolder.uri.fsPath);

await validatorAll.validate(workspaceFolder.uri.fsPath);
await validatorAll.validate(workspaceFolder.uri.fsPath);
break;

case "bruin.validateCurrentPipeline":
if (!this._lastRenderedDocumentUri) {
console.error("No active document to validate.");
return;
}
console.log("Validating current pipeline*********************");
break;

case "bruin.validate":
if (!this._lastRenderedDocumentUri) {
console.error("No active document to validate.");
Expand Down
34 changes: 23 additions & 11 deletions webview-ui/src/components/AssetGeneral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
:defaultAction="handleBruinValidateCurrentAsset"
:status="validateButtonStatus"
buttonLabel="Validate"
:menuItems="['Pipeline']"
:menuItems="['Current Pipeline', 'All Pipelines']"
@exec-choice="validateChoice"
/>
<CommandButton
:isDisabled="isError || isNotAsset"
:defaultAction="runSql"
:menuItems="['Downstream']"
:menuItems="['Downstream', 'Current Pipeline']"
buttonLabel="Run"
@exec-choice="runWithOptions"
/>
Expand Down Expand Up @@ -67,10 +67,19 @@ const props = defineProps<{
name: string | null;
}>();
function handleBruinValidateAll() {
vscode.postMessage({
command: "bruin.validateAll",
});
function handleBruinValidateAll(action: string) {
switch(action){
case "All Pipelines":
vscode.postMessage({
command: "bruin.validateAll",
});
break;
case "Current Pipeline":
vscode.postMessage({
command: "bruin.validateCurrentPipeline",
});
break;
}
}
function handleBruinValidateCurrentAsset() {
Expand All @@ -96,7 +105,7 @@ const validateChoice = computed(() => handleBruinValidateAll);
function runSql(runOption?: string) {
let payload = getCheckboxChangePayload();
if (runOption == "Pipeline") {
if (runOption == "Current Pipeline") {
vscode.postMessage({
command: "bruin.runAll",
});
Expand Down Expand Up @@ -146,7 +155,12 @@ watch(
function getCheckboxChangePayload() {
console.log("start date", startDate.value);
console.log("end date", endDate.value);
return concatCommandFlags(startDate.value, endDate.value, endDateExclusive.value, checkboxItems.value);
return concatCommandFlags(
startDate.value,
endDate.value,
endDateExclusive.value,
checkboxItems.value
);
}
const language = ref("");
Expand Down Expand Up @@ -192,6 +206,7 @@ function receiveMessage(event: { data: any }) {
validationSuccess.value = updateValue(envelope, "success");
validationError.value = updateValue(envelope, "error");
validateButtonStatus.value = updateValue(envelope, "loading");
console.debug("-------------------------Validation result------------------------", validationSuccess.value);
validateButtonStatus.value = determineValidationStatus(
validationSuccess.value,
validationError.value,
Expand All @@ -208,9 +223,6 @@ function receiveMessage(event: { data: any }) {
language.value = renderSQLAssetSuccess.value ? "sql" : "python";
resetStates([validationError, validationSuccess, validateButtonStatus]);
console.log("Is not asset", isNotAsset.value);
console.log("Error state", isError.value);
console.log("Error message From Genearl", errorMessage.value);
break;
case "run-success":
Expand Down
160 changes: 90 additions & 70 deletions webview-ui/src/components/ErrorAlert.vue
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<template>
<div v-if="formattedErrorMessage" class="rounded-md bg-red-50 p-4 my-4">
<div v-if="formattedErrorMessages.length" class="rounded-md bg-red-50 p-4 my-4">
<div class="flex">
<div class="flex-shrink-0">
<XCircleIcon class="h-5 w-5 text-red-500" aria-hidden="true" />
</div>
<div class="ml-4">
<h3 class="text-lg font-medium text-red-800" v-if="formattedErrorMessage.pipeline">
Pipeline: {{ formattedErrorMessage.pipeline }}
</h3>
<div v-for="(issue, index) in formattedErrorMessage.issues" :key="index" class="mt-3">
<h4 class="text-md font-semibold text-gray-900" v-if="issue.asset">
Asset: {{ issue.asset }}
</h4>
<p class="text-sm text-red-600">{{ issue.description }}</p>
<div
v-if="issue.context.length"
class="flex items-center space-x-1 mt-2 justify-end text-[color:var(--vscode-editor-background)]"
>
<span class="font-semibold"> Details </span>
<transition name="fade">
<ChevronUpIcon
v-if="issue.expanded.value"
class="h-5 w-5"
aria-hidden="true"
@click="issue.expanded.value = !issue.expanded.value"
/>
<ChevronDownIcon
v-else
class="h-5 w-5"
aria-hidden="true"
@click="issue.expanded.value = !issue.expanded.value"
/>
</transition>
<div v-for="(errorMessage, index) in formattedErrorMessages" :key="index" class="mb-4">
<h3 class="text-lg font-medium text-red-800" v-if="errorMessage.pipeline">
Pipeline: {{ errorMessage.pipeline }}
</h3>
<div v-for="(issue, issueIndex) in errorMessage.issues" :key="issueIndex" class="mt-3">
<h4 class="text-md font-semibold text-gray-900" v-if="issue.asset">
Asset: {{ issue.asset }}
</h4>
<p class="text-sm text-red-600">{{ issue.description }}</p>
<div
v-if="issue.context.length"
class="flex items-center space-x-1 mt-2 justify-end text-[color:var(--vscode-editor-background)]"
>
<span class="font-semibold">Details</span>
<transition name="fade">
<ChevronUpIcon
v-if="issue.expanded.value"
class="h-5 w-5"
aria-hidden="true"
@click="issue.expanded.value = !issue.expanded.value"
/>
<ChevronDownIcon
v-else
class="h-5 w-5"
aria-hidden="true"
@click="issue.expanded.value = !issue.expanded.value"
/>
</transition>
</div>
<div class="text-sm text-gray-700 ml-1 mt-1 w-full" v-show="issue.expanded.value">
<pre class="whitespace-pre-wrap bg-red-100 rounded p-2">{{ formattedIssueContext(issue.context) }}</pre>
</div>
<div class="text-sm text-gray-700 ml-1 mt-1" v-show="issue.expanded.value">
<pre class="whitespace-pre-wrap bg-red-100 rounded p-2">{{
formattedIssueContext(issue.context)
}}</pre>
</div>
</div>
</div>
Expand All @@ -46,75 +46,95 @@


<script setup lang="ts">
import { computed, ref } from "vue";
import { computed, ref, type Ref } from "vue";
import { defineProps } from "vue";
import { XCircleIcon, ChevronDownIcon, ChevronUpIcon } from "@heroicons/vue/20/solid";
import type {ParsedValidationErrorMessage} from "@/types";
// Define the types explicitly
interface Issue {
asset: string | null;
description: string;
context: string[];
}
interface ParsedValidationErrorMessage {
pipeline: string | null;
issues: Record<string, Issue[]>;
}
interface FormattedIssue {
asset: string | null;
description: string;
context: string[];
expanded: Ref<boolean>;
}
interface FormattedErrorMessage {
pipeline: string | null;
issues: FormattedIssue[];
}
const props = defineProps<{
errorMessage: string | any | null;
}>();
// Helper function to format issue context
const formattedIssueContext = (context) => {
return context.join("\n");
};
const formattedErrorMessage = computed(() => {
if (!props.errorMessage) return null;
const formattedIssueContext = (context: string[]) => context.join("\n");
const formattedErrorMessages = computed<FormattedErrorMessage[]>(() => {
if (!props.errorMessage) return [];
try {
const errorObject = JSON.parse(props.errorMessage);
const errorObject = JSON.parse(props.errorMessage)
const validationError = errorObject[0] as ParsedValidationErrorMessage;
// Handling a simple error message
// Handling a simple error message from render command
if (errorObject.error) {
console.log("Error message:", errorObject.error);
return {
pipeline: null, // Set to null or a default message
issues: [{
asset: null, // Asset can be null
description: errorObject.error, // Ensure description is always populated
context: [],
expanded: ref(false),
}]
};
return [
{
pipeline: null,
issues: [
{
asset: null,
description: errorObject.error,
context: [],
expanded: ref(false),
},
],
},
];
}
// Handling structured error messages
if (validationError.pipeline || validationError.issues) {
return {
// Handling validation errors
if (Array.isArray(errorObject) && errorObject.length > 0) {
return errorObject.map((validationError: ParsedValidationErrorMessage) => ({
pipeline: validationError.pipeline || null,
issues: Object.entries(validationError.issues || {})
.map(([test, issues]) => {
return issues.map((issue) => ({
issues: Object.entries(validationError.issues || {})
.flatMap(([test, issues]) =>
issues.map(issue => ({
asset: issue.asset || null,
description: issue.description, // Description is expected to be always available
description: issue.description,
context: issue.context || [],
expanded: ref(false),
}));
})
.flat(),
};
}))
),
}));
}
return null;
return [];
} catch (e) {
console.error("Failed to parse error message:", e);
return null;
return [];
}
});
</script>



<style scoped>
pre {
white-space: pre-wrap;
word-wrap: break-word;
line-height: 1.5;
}
.fade-enter-active,
.fade-leave-active {
Expand Down

0 comments on commit 0fca218

Please sign in to comment.