Skip to content

Commit

Permalink
fix(system): Run query on initial load (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwaterman authored Jan 4, 2024
1 parent b49a45c commit 0f8ec32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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

0 comments on commit 0f8ec32

Please sign in to comment.