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

feat: add message when linter failed to run #1157

Merged
merged 1 commit into from
Feb 10, 2023
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
22 changes: 21 additions & 1 deletion querybook/webapp/components/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,19 @@ export const QueryEditor: React.FC<
/* ---- end of <ReactCodeMirror /> properties ---- */

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

if (isLinting) {
return (
<span className="flex-row mr8">
<Icon name="Loading" className="mr4" size={16} />
Linting
</span>
);
}

if (lintSummary.numErrors + lintSummary.numWarnings > 0) {
return (
<div
Expand Down Expand Up @@ -656,7 +669,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(
() =>
Expand Down Expand Up @@ -193,8 +198,9 @@ export function useLint({
return {
numErrors,
numWarnings,
failedToLint,
};
}, [lintAnnotations]);
}, [lintAnnotations, failedToLint]);

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