Skip to content

Commit

Permalink
feat: add message when linter failed to run
Browse files Browse the repository at this point in the history
  • Loading branch information
czgu committed Feb 10, 2023
1 parent c3ddec1 commit 4f94930
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 9 additions & 2 deletions querybook/webapp/components/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export const QueryEditor: React.FC<
/* ---- end of <ReactCodeMirror /> properties ---- */

const renderLintButtons = () => {
if (value.length === 0) {
if (value.length === 0 || getLintErrors == null) {
return null;
}

Expand Down Expand Up @@ -648,7 +648,14 @@ export const QueryEditor: React.FC<
)}
</div>
);
} else if (getLintErrors) {
} else if (lintSummary.failedToLint) {
return (
<span className="flex-row mr8 lint-num-warnings">
<Icon name="AlertTriangle" className="mr4" size={16} />
Linter is having issues
</span>
);
} else {
return (
<span className="flex-row mr8 lint-passed">
<Icon name="CheckCircle" className="mr4" size={16} />
Expand Down
22 changes: 14 additions & 8 deletions querybook/webapp/hooks/queryEditor/useLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function useQueryLintAnnotations(
editorRef: React.MutableRefObject<CodeMirror.Editor>
) {
const [isLintingQuery, setIsLinting] = useState(false);
const [failedToLint, setFailedToLint] = useState(false);
const [queryAnnotations, setQueryAnnotations] = useState<ILinterWarning[]>(
[]
);
Expand All @@ -94,15 +95,22 @@ function useQueryLintAnnotations(
useEffect(() => {
setIsLinting(true);
getQueryLintAnnotations(query)
.then(setQueryAnnotations)
.then((annotations) => {
setQueryAnnotations(annotations);
setFailedToLint(false);
})
.catch(() => {
setFailedToLint(true);
setQueryAnnotations([]);
})
.finally(() => {
setIsLinting(false);
});

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedQuery, getQueryLintAnnotations]);

return { isLintingQuery, queryAnnotations };
return { isLintingQuery, queryAnnotations, failedToLint };
}

function useTableLintAnnotations(
Expand Down Expand Up @@ -159,11 +167,8 @@ export function useLint({
getTableByName,
!!getLintErrors
);
const { isLintingQuery, queryAnnotations } = useQueryLintAnnotations(
query,
getLintErrors,
editorRef
);
const { isLintingQuery, queryAnnotations, failedToLint } =
useQueryLintAnnotations(query, getLintErrors, editorRef);
const lintAnnotationsRef = useRef<ILinterWarning[]>([]);
const lintAnnotations = useMemo(
() => tableAnnotations.concat(queryAnnotations),
Expand All @@ -188,8 +193,9 @@ export function useLint({
return {
numErrors,
numWarnings,
failedToLint,
};
}, [lintAnnotations]);
}, [lintAnnotations, failedToLint]);

useEffect(() => {
onLintCompletion?.(lintSummary.numErrors > 0);
Expand Down

0 comments on commit 4f94930

Please sign in to comment.