Commit 6ff15039 by David Kaltschmidt

File organization, action naming, comments

- moved ActionTypes to `./state/actionTypes`
- renamed click-related actions
- added comments to actions and state types
- prefixed Explore actions with `explore/`
- fixed query override issue when row was added
parent 9aede9e6
......@@ -18,15 +18,15 @@ import {
changeDatasource,
changeSize,
changeTime,
clickClear,
clickCloseSplit,
clickExample,
clickSplit,
clearQueries,
initializeExplore,
modifyQueries,
runQueries,
scanStart,
scanStop,
setQueries,
splitClose,
splitOpen,
} from './state/actions';
import { Alert } from './Error';
......@@ -42,10 +42,7 @@ interface ExploreProps {
changeDatasource: typeof changeDatasource;
changeSize: typeof changeSize;
changeTime: typeof changeTime;
clickClear: typeof clickClear;
clickCloseSplit: typeof clickCloseSplit;
clickExample: typeof clickExample;
clickSplit: typeof clickSplit;
clearQueries: typeof clearQueries;
datasourceError: string;
datasourceInstance: any;
datasourceLoading: boolean | null;
......@@ -65,7 +62,10 @@ interface ExploreProps {
scanRange?: RawTimeRange;
scanStart: typeof scanStart;
scanStop: typeof scanStop;
setQueries: typeof setQueries;
split: boolean;
splitClose: typeof splitClose;
splitOpen: typeof splitOpen;
showingStartPage?: boolean;
supportsGraph: boolean | null;
supportsLogs: boolean | null;
......@@ -152,20 +152,20 @@ export class Explore extends React.PureComponent<ExploreProps> {
};
onClickClear = () => {
this.props.clickClear(this.props.exploreId);
this.props.clearQueries(this.props.exploreId);
};
onClickCloseSplit = () => {
this.props.clickCloseSplit();
this.props.splitClose();
};
// Use this in help pages to set page to a single query
onClickExample = (query: DataQuery) => {
this.props.clickExample(this.props.exploreId, query);
this.props.setQueries(this.props.exploreId, [query]);
};
onClickSplit = () => {
this.props.clickSplit();
this.props.splitOpen();
};
onClickLabel = (key: string, value: string) => {
......@@ -175,7 +175,7 @@ export class Explore extends React.PureComponent<ExploreProps> {
onModifyQueries = (action, index?: number) => {
const { datasourceInstance } = this.props;
if (datasourceInstance && datasourceInstance.modifyQuery) {
const modifier = (queries: DataQuery, action: any) => datasourceInstance.modifyQuery(queries, action);
const modifier = (queries: DataQuery, modification: any) => datasourceInstance.modifyQuery(queries, modification);
this.props.modifyQueries(this.props.exploreId, action, index, modifier);
}
};
......@@ -366,15 +366,15 @@ const mapDispatchToProps = {
changeDatasource,
changeSize,
changeTime,
clickClear,
clickCloseSplit,
clickExample,
clickSplit,
clearQueries,
initializeExplore,
modifyQueries,
runQueries,
scanStart,
scanStop,
setQueries,
splitClose,
splitOpen,
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(Explore));
......@@ -6,13 +6,12 @@ import { RawTimeRange, TimeRange } from '@grafana/ui';
import { ExploreId, ExploreItemState } from 'app/types/explore';
import { StoreState } from 'app/types';
import { clickGraphButton } from './state/actions';
import { toggleGraph } from './state/actions';
import Graph from './Graph';
import Panel from './Panel';
interface GraphContainerProps {
onChangeTime: (range: TimeRange) => void;
clickGraphButton: typeof clickGraphButton;
exploreId: ExploreId;
graphResult?: any[];
loading: boolean;
......@@ -20,11 +19,12 @@ interface GraphContainerProps {
showingGraph: boolean;
showingTable: boolean;
split: boolean;
toggleGraph: typeof toggleGraph;
}
export class GraphContainer extends PureComponent<GraphContainerProps> {
onClickGraphButton = () => {
this.props.clickGraphButton(this.props.exploreId);
this.props.toggleGraph(this.props.exploreId);
};
render() {
......@@ -55,7 +55,7 @@ function mapStateToProps(state: StoreState, { exploreId }) {
}
const mapDispatchToProps = {
clickGraphButton,
toggleGraph,
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(GraphContainer));
......@@ -7,12 +7,11 @@ import { ExploreId, ExploreItemState } from 'app/types/explore';
import { LogsModel } from 'app/core/logs_model';
import { StoreState } from 'app/types';
import { clickLogsButton } from './state/actions';
import { toggleLogs } from './state/actions';
import Logs from './Logs';
import Panel from './Panel';
interface LogsContainerProps {
clickLogsButton: typeof clickLogsButton;
exploreId: ExploreId;
loading: boolean;
logsHighlighterExpressions?: string[];
......@@ -25,11 +24,12 @@ interface LogsContainerProps {
scanning?: boolean;
scanRange?: RawTimeRange;
showingLogs: boolean;
toggleLogs: typeof toggleLogs;
}
export class LogsContainer extends PureComponent<LogsContainerProps> {
onClickLogsButton = () => {
this.props.clickLogsButton(this.props.exploreId);
this.props.toggleLogs(this.props.exploreId);
};
render() {
......@@ -85,7 +85,7 @@ function mapStateToProps(state: StoreState, { exploreId }) {
}
const mapDispatchToProps = {
clickLogsButton,
toggleLogs,
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(LogsContainer));
......@@ -5,30 +5,30 @@ import { connect } from 'react-redux';
import { ExploreId, ExploreItemState } from 'app/types/explore';
import { StoreState } from 'app/types';
import { clickTableButton } from './state/actions';
import { toggleGraph } from './state/actions';
import Table from './Table';
import Panel from './Panel';
import TableModel from 'app/core/table_model';
interface TableContainerProps {
clickTableButton: typeof clickTableButton;
exploreId: ExploreId;
loading: boolean;
onClickLabel: (key: string, value: string) => void;
onClickCell: (key: string, value: string) => void;
showingTable: boolean;
tableResult?: TableModel;
toggleGraph: typeof toggleGraph;
}
export class TableContainer extends PureComponent<TableContainerProps> {
onClickTableButton = () => {
this.props.clickTableButton(this.props.exploreId);
this.props.toggleGraph(this.props.exploreId);
};
render() {
const { loading, onClickLabel, showingTable, tableResult } = this.props;
const { loading, onClickCell, showingTable, tableResult } = this.props;
return (
<Panel label="Table" loading={loading} isOpen={showingTable} onToggle={this.onClickTableButton}>
<Table data={tableResult} loading={loading} onClickCell={onClickLabel} />
<Table data={tableResult} loading={loading} onClickCell={onClickCell} />
</Panel>
);
}
......@@ -43,7 +43,7 @@ function mapStateToProps(state: StoreState, { exploreId }) {
}
const mapDispatchToProps = {
clickTableButton,
toggleGraph,
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(TableContainer));
import { RawTimeRange, TimeRange } from '@grafana/ui';
import { Emitter } from 'app/core/core';
import {
ExploreId,
ExploreItemState,
HistoryItem,
RangeScanner,
ResultType,
QueryTransaction,
} from 'app/types/explore';
import { DataSourceSelectItem } from 'app/types/datasources';
import { DataQuery } from 'app/types';
export enum ActionTypes {
AddQueryRow = 'explore/ADD_QUERY_ROW',
ChangeDatasource = 'explore/CHANGE_DATASOURCE',
ChangeQuery = 'explore/CHANGE_QUERY',
ChangeSize = 'explore/CHANGE_SIZE',
ChangeTime = 'explore/CHANGE_TIME',
ClearQueries = 'explore/CLEAR_QUERIES',
HighlightLogsExpression = 'explore/HIGHLIGHT_LOGS_EXPRESSION',
InitializeExplore = 'explore/INITIALIZE_EXPLORE',
InitializeExploreSplit = 'explore/INITIALIZE_EXPLORE_SPLIT',
LoadDatasourceFailure = 'explore/LOAD_DATASOURCE_FAILURE',
LoadDatasourceMissing = 'explore/LOAD_DATASOURCE_MISSING',
LoadDatasourcePending = 'explore/LOAD_DATASOURCE_PENDING',
LoadDatasourceSuccess = 'explore/LOAD_DATASOURCE_SUCCESS',
ModifyQueries = 'explore/MODIFY_QUERIES',
QueryTransactionFailure = 'explore/QUERY_TRANSACTION_FAILURE',
QueryTransactionStart = 'explore/QUERY_TRANSACTION_START',
QueryTransactionSuccess = 'explore/QUERY_TRANSACTION_SUCCESS',
RemoveQueryRow = 'explore/REMOVE_QUERY_ROW',
RunQueries = 'explore/RUN_QUERIES',
RunQueriesEmpty = 'explore/RUN_QUERIES_EMPTY',
ScanRange = 'explore/SCAN_RANGE',
ScanStart = 'explore/SCAN_START',
ScanStop = 'explore/SCAN_STOP',
SetQueries = 'explore/SET_QUERIES',
SplitClose = 'explore/SPLIT_CLOSE',
SplitOpen = 'explore/SPLIT_OPEN',
StateSave = 'explore/STATE_SAVE',
ToggleGraph = 'explore/TOGGLE_GRAPH',
ToggleLogs = 'explore/TOGGLE_LOGS',
ToggleTable = 'explore/TOGGLE_TABLE',
}
export interface AddQueryRowAction {
type: ActionTypes.AddQueryRow;
exploreId: ExploreId;
index: number;
query: DataQuery;
}
export interface ChangeQueryAction {
type: ActionTypes.ChangeQuery;
exploreId: ExploreId;
query: DataQuery;
index: number;
override: boolean;
}
export interface ChangeSizeAction {
type: ActionTypes.ChangeSize;
exploreId: ExploreId;
width: number;
height: number;
}
export interface ChangeTimeAction {
type: ActionTypes.ChangeTime;
exploreId: ExploreId;
range: TimeRange;
}
export interface ClearQueriesAction {
type: ActionTypes.ClearQueries;
exploreId: ExploreId;
}
export interface HighlightLogsExpressionAction {
type: ActionTypes.HighlightLogsExpression;
exploreId: ExploreId;
expressions: string[];
}
export interface InitializeExploreAction {
type: ActionTypes.InitializeExplore;
exploreId: ExploreId;
containerWidth: number;
datasource: string;
eventBridge: Emitter;
exploreDatasources: DataSourceSelectItem[];
queries: DataQuery[];
range: RawTimeRange;
}
export interface InitializeExploreSplitAction {
type: ActionTypes.InitializeExploreSplit;
}
export interface LoadDatasourceFailureAction {
type: ActionTypes.LoadDatasourceFailure;
exploreId: ExploreId;
error: string;
}
export interface LoadDatasourcePendingAction {
type: ActionTypes.LoadDatasourcePending;
exploreId: ExploreId;
datasourceId: number;
}
export interface LoadDatasourceMissingAction {
type: ActionTypes.LoadDatasourceMissing;
exploreId: ExploreId;
}
export interface LoadDatasourceSuccessAction {
type: ActionTypes.LoadDatasourceSuccess;
exploreId: ExploreId;
StartPage?: any;
datasourceInstance: any;
history: HistoryItem[];
initialDatasource: string;
initialQueries: DataQuery[];
logsHighlighterExpressions?: any[];
showingStartPage: boolean;
supportsGraph: boolean;
supportsLogs: boolean;
supportsTable: boolean;
}
export interface ModifyQueriesAction {
type: ActionTypes.ModifyQueries;
exploreId: ExploreId;
modification: any;
index: number;
modifier: (queries: DataQuery[], modification: any) => DataQuery[];
}
export interface QueryTransactionFailureAction {
type: ActionTypes.QueryTransactionFailure;
exploreId: ExploreId;
queryTransactions: QueryTransaction[];
}
export interface QueryTransactionStartAction {
type: ActionTypes.QueryTransactionStart;
exploreId: ExploreId;
resultType: ResultType;
rowIndex: number;
transaction: QueryTransaction;
}
export interface QueryTransactionSuccessAction {
type: ActionTypes.QueryTransactionSuccess;
exploreId: ExploreId;
history: HistoryItem[];
queryTransactions: QueryTransaction[];
}
export interface RemoveQueryRowAction {
type: ActionTypes.RemoveQueryRow;
exploreId: ExploreId;
index: number;
}
export interface RunQueriesEmptyAction {
type: ActionTypes.RunQueriesEmpty;
exploreId: ExploreId;
}
export interface ScanStartAction {
type: ActionTypes.ScanStart;
exploreId: ExploreId;
scanner: RangeScanner;
}
export interface ScanRangeAction {
type: ActionTypes.ScanRange;
exploreId: ExploreId;
range: RawTimeRange;
}
export interface ScanStopAction {
type: ActionTypes.ScanStop;
exploreId: ExploreId;
}
export interface SetQueriesAction {
type: ActionTypes.SetQueries;
exploreId: ExploreId;
queries: DataQuery[];
}
export interface SplitCloseAction {
type: ActionTypes.SplitClose;
}
export interface SplitOpenAction {
type: ActionTypes.SplitOpen;
itemState: ExploreItemState;
}
export interface StateSaveAction {
type: ActionTypes.StateSave;
}
export interface ToggleTableAction {
type: ActionTypes.ToggleTable;
exploreId: ExploreId;
}
export interface ToggleGraphAction {
type: ActionTypes.ToggleGraph;
exploreId: ExploreId;
}
export interface ToggleLogsAction {
type: ActionTypes.ToggleLogs;
exploreId: ExploreId;
}
export type Action =
| AddQueryRowAction
| ChangeQueryAction
| ChangeSizeAction
| ChangeTimeAction
| ClearQueriesAction
| HighlightLogsExpressionAction
| InitializeExploreAction
| InitializeExploreSplitAction
| LoadDatasourceFailureAction
| LoadDatasourceMissingAction
| LoadDatasourcePendingAction
| LoadDatasourceSuccessAction
| ModifyQueriesAction
| QueryTransactionFailureAction
| QueryTransactionStartAction
| QueryTransactionSuccessAction
| RemoveQueryRowAction
| RunQueriesEmptyAction
| ScanRangeAction
| ScanStartAction
| ScanStopAction
| SetQueriesAction
| SplitCloseAction
| SplitOpenAction
| ToggleGraphAction
| ToggleLogsAction
| ToggleTableAction;
......@@ -83,43 +83,160 @@ export enum ExploreId {
right = 'right',
}
/**
* Global Explore state
*/
export interface ExploreState {
/**
* True if split view is active.
*/
split: boolean;
/**
* Explore state of the left split (left is default in non-split view).
*/
left: ExploreItemState;
/**
* Explore state of the right area in split view.
*/
right: ExploreItemState;
}
export interface ExploreItemState {
/**
* React component to be shown when no queries have been run yet, e.g., for a query language cheat sheet.
*/
StartPage?: any;
/**
* Width used for calculating the graph interval (can't have more datapoints than pixels)
*/
containerWidth: number;
/**
* Datasource instance that has been selected. Datasource-specific logic can be run on this object.
*/
datasourceInstance: any;
/**
* Error to be shown when datasource loading or testing failed.
*/
datasourceError: string;
/**
* True if the datasource is loading. `null` if the loading has not started yet.
*/
datasourceLoading: boolean | null;
/**
* True if there is no datasource to be selected.
*/
datasourceMissing: boolean;
/**
* Emitter to send events to the rest of Grafana.
*/
eventBridge?: Emitter;
/**
* List of datasources to be shown in the datasource selector.
*/
exploreDatasources: DataSourceSelectItem[];
/**
* List of timeseries to be shown in the Explore graph result viewer.
*/
graphResult?: any[];
/**
* History of recent queries. Datasource-specific and initialized via localStorage.
*/
history: HistoryItem[];
/**
* Initial datasource for this Explore, e.g., set via URL.
*/
initialDatasource?: string;
/**
* Initial queries for this Explore, e.g., set via URL. Each query will be
* converted to a query row. Query edits should be tracked in `modifiedQueries` though.
*/
initialQueries: DataQuery[];
/**
* True if this Explore area has been initialized.
* Used to distinguish URL state injection versus split view state injection.
*/
initialized: boolean;
/**
* Log line substrings to be highlighted as you type in a query field.
* Currently supports only the first query row.
*/
logsHighlighterExpressions?: string[];
/**
* Log query result to be displayed in the logs result viewer.
*/
logsResult?: LogsModel;
/**
* Copy of `initialQueries` that tracks user edits.
* Don't connect this property to a react component as it is updated on every query change.
* Used when running queries. Needs to be reset to `initialQueries` when those are reset as well.
*/
modifiedQueries: DataQuery[];
/**
* Query intervals for graph queries to determine how many datapoints to return.
* Needs to be updated when `datasourceInstance` or `containerWidth` is changed.
*/
queryIntervals: QueryIntervals;
/**
* List of query transaction to track query duration and query result.
* Graph/Logs/Table results are calculated on the fly from the transaction,
* based on the transaction's result types. Transaction also holds the row index
* so that results can be dropped and re-computed without running queries again
* when query rows are removed.
*/
queryTransactions: QueryTransaction[];
/**
* Tracks datasource when selected in the datasource selector.
* Allows the selection to be discarded if something went wrong during the asynchronous
* loading of the datasource.
*/
requestedDatasourceId?: number;
/**
* Time range for this Explore. Managed by the time picker and used by all query runs.
*/
range: TimeRange | RawTimeRange;
/**
* Scanner function that calculates a new range, triggers a query run, and returns the new range.
*/
scanner?: RangeScanner;
/**
* True if scanning for more results is active.
*/
scanning?: boolean;
/**
* Current scanning range to be shown to the user while scanning is active.
*/
scanRange?: RawTimeRange;
/**
* True if graph result viewer is expanded. Query runs will contain graph queries.
*/
showingGraph: boolean;
/**
* True if logs result viewer is expanded. Query runs will contain logs queries.
*/
showingLogs: boolean;
/**
* True StartPage needs to be shown. Typically set to `false` once queries have been run.
*/
showingStartPage?: boolean;
/**
* True if table result viewer is expanded. Query runs will contain table queries.
*/
showingTable: boolean;
/**
* True if `datasourceInstance` supports graph queries.
*/
supportsGraph: boolean | null;
/**
* True if `datasourceInstance` supports logs queries.
*/
supportsLogs: boolean | null;
/**
* True if `datasourceInstance` supports table queries.
*/
supportsTable: boolean | null;
/**
* Table model that combines all query table results into a single table.
*/
tableResult?: TableModel;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment