Skip to content

Commit 26cb079

Browse files
author
Roman M
committed
Add dashboard and apply better structure of golang functions
1 parent 1f4983b commit 26cb079

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/utils/clickhouseErrorHandling.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ export function getPermissionErrorMessage(
9494
datasourceId?: string
9595
): string {
9696
const messages: Record<PermissionErrorContextType, string> = {
97-
[PermissionErrorContext.ADHOC_KEYS]: 'System.columns table inaccessible - ad-hoc filters disabled',
98-
[PermissionErrorContext.ADHOC_VALUES]: 'System.columns table inaccessible - cannot fetch tag values',
99-
[PermissionErrorContext.AUTOCOMPLETE]: 'System tables inaccessible - autocomplete disabled',
100-
[PermissionErrorContext.DATABASES]: 'System table access denied for DATABASES query - returning empty result',
101-
[PermissionErrorContext.TABLES]: 'System table access denied for TABLES query - returning empty result',
102-
[PermissionErrorContext.COLUMNS]: 'System table access denied for COLUMNS query - returning empty result',
103-
[PermissionErrorContext.QUERY_BUILDER]: 'System table access denied - returning empty result',
104-
[PermissionErrorContext.SYSTEM_DATABASES]: 'System tables inaccessible - system database list disabled',
97+
[PermissionErrorContext.ADHOC_KEYS]: 'ClickHouse system.columns table inaccessible - ad-hoc filters disabled',
98+
[PermissionErrorContext.ADHOC_VALUES]: 'ClickHouse system.columns table inaccessible - cannot fetch tag values',
99+
[PermissionErrorContext.AUTOCOMPLETE]: 'ClickHouse system tables inaccessible - autocomplete disabled',
100+
[PermissionErrorContext.DATABASES]: 'ClickHouse system table access denied for DATABASES query - returning empty result',
101+
[PermissionErrorContext.TABLES]: 'ClickHouse system table access denied for TABLES query - returning empty result',
102+
[PermissionErrorContext.COLUMNS]: 'ClickHouse system table access denied for COLUMNS query - returning empty result',
103+
[PermissionErrorContext.QUERY_BUILDER]: 'ClickHouse system table access denied - returning empty result',
104+
[PermissionErrorContext.SYSTEM_DATABASES]: 'ClickHouse system tables inaccessible - system database list disabled',
105105
};
106106

107107
const baseMessage = messages[context] || 'Permission denied - returning empty result';

src/views/QueryEditor/QueryEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function QueryEditor(props: QueryEditorProps<CHDataSource, CHQuery, CHDat
2323

2424
useEffect(() => {
2525
if (formattedData !== initializedQuery.query) {
26-
onChange({ ...initializedQuery, rawQuery: formattedData })
26+
onChange({ ...initializedQuery, formattedQuery: formattedData })
2727
}
2828

2929
// eslint-disable-next-line
@@ -120,7 +120,7 @@ export function QueryEditorVariable(props: QueryEditorProps<CHDataSource, CHQuer
120120

121121
useEffect(() => {
122122
if (formattedData !== initializedQuery.query) {
123-
onChange({ ...initializedQuery, rawQuery: formattedData })
123+
onChange({ ...initializedQuery, formattedQuery: formattedData })
124124
}
125125

126126
// eslint-disable-next-line

src/views/QueryEditor/hooks/useFormattedData.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@ export const useFormattedData = (query: CHQuery, datasource: CHDataSource, optio
1111
const [error, setError] = useState<string | null>(null);
1212

1313
useEffect(() => {
14-
if ((datasource.options || options) && datasource.templateSrv) {
15-
datasource.replace(datasource.options || options, query).then((replaced) => {
16-
setFormattedData(replaced.stmt);
17-
setError(null);
18-
}).catch((e) => {
19-
setFormattedData(query.query);
20-
// Display the error we received from backend
21-
const errorStr = e.data?.error || e.toString();
22-
setError(errorStr);
23-
})
24-
} else {
25-
// Only set error if datasource is genuinely missing required properties
26-
setError('No datasource is defined or datasource not fully initialized. Please try to force reload');
27-
}
14+
// Determine if we're in a context where template replacement is possible
15+
const hasExecutionContext = (datasource.options?.range || options?.range);
16+
const hasTemplateService = !!datasource.templateSrv;
17+
18+
if (hasExecutionContext && hasTemplateService) {
19+
// Normal dashboard mode - perform replacement
20+
datasource.replace(datasource.options || options, query).then((replaced) => {
21+
setFormattedData(replaced.stmt);
22+
setError(null);
23+
}).catch((e) => {
24+
setFormattedData(query.query);
25+
const errorStr = e.data?.error || e.toString();
26+
setError(errorStr);
27+
});
28+
} else if (hasTemplateService) {
29+
// Alerts/Explore mode - no execution context yet
30+
// This is EXPECTED behavior, not an error
31+
setFormattedData(query.query);
32+
setError(null);
33+
} else {
34+
// Critical error - no template service available
35+
setFormattedData(query.query);
36+
setError('Grafana template service unavailable. Please refresh the page.');
37+
}
2838

2939
// eslint-disable-next-line
3040
}, [query, datasource.name, datasource.options, options, datasource.templateSrv]);

0 commit comments

Comments
 (0)