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

fix(system): Run query on initial load #55

Merged
merged 2 commits into from
Jan 4, 2024
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
10 changes: 9 additions & 1 deletion src/datasources/system/components/SystemQueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FormEvent } from 'react';
import React, { FormEvent, useEffect } from 'react';
import { AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui';
import { QueryEditorProps, SelectableValue } from '@grafana/data';
import { SystemDataSource } from '../SystemDataSource';
Expand All @@ -11,6 +11,14 @@ type Props = QueryEditorProps<SystemDataSource, SystemQuery>;
export function SystemQueryEditor({ query, onChange, onRunQuery, datasource }: Props) {
query = datasource.prepareQuery(query);

useEffect(() => {
if (query.queryKind === SystemQueryType.Summary) {
onChange(query);
onRunQuery();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Only run on mount

const workspaces = useWorkspaceOptions(datasource);

const onQueryTypeChange = (value: SystemQueryType) => {
Expand Down
11 changes: 9 additions & 2 deletions src/datasources/workspace/components/WorkspaceQueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ import { WorkspaceDataSource } from '../WorkspaceDataSource';

type Props = QueryEditorProps<WorkspaceDataSource, WorkspaceQuery>;

export function WorkspaceQueryEditor({ onRunQuery }: Props) {
useEffect(onRunQuery, [onRunQuery]);
export function WorkspaceQueryEditor({ query, onChange, onRunQuery }: Props) {
useEffect(() => {
// The "init" property is required for the initial query in Explore to work since the query
// only runs if a change to a property is detected. It otherwise has no use and can be removed
// if a property is added to "WorkspaceQuery".
onChange(Object.assign({ init: true }, query));
onRunQuery();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Only run on mount

return (
<span>This data source returns all SystemLink workspaces and does not include a query editor.</span>
Expand Down