LogsContainer.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import React, { PureComponent } from 'react';
  2. import { hot } from 'react-hot-loader';
  3. import { connect } from 'react-redux';
  4. import { RawTimeRange, TimeRange } from '@grafana/ui';
  5. import { ExploreId, ExploreItemState } from 'app/types/explore';
  6. import { LogsModel, LogsDedupStrategy } from 'app/core/logs_model';
  7. import { StoreState } from 'app/types';
  8. import { toggleLogs, changeDedupStrategy } from './state/actions';
  9. import Logs from './Logs';
  10. import Panel from './Panel';
  11. interface LogsContainerProps {
  12. exploreId: ExploreId;
  13. loading: boolean;
  14. logsHighlighterExpressions?: string[];
  15. logsResult?: LogsModel;
  16. onChangeTime: (range: TimeRange) => void;
  17. onClickLabel: (key: string, value: string) => void;
  18. onStartScanning: () => void;
  19. onStopScanning: () => void;
  20. range: RawTimeRange;
  21. scanning?: boolean;
  22. scanRange?: RawTimeRange;
  23. showingLogs: boolean;
  24. toggleLogs: typeof toggleLogs;
  25. changeDedupStrategy: typeof changeDedupStrategy;
  26. dedupStrategy: LogsDedupStrategy;
  27. width: number;
  28. }
  29. export class LogsContainer extends PureComponent<LogsContainerProps> {
  30. onClickLogsButton = () => {
  31. this.props.toggleLogs(this.props.exploreId, this.props.showingLogs);
  32. };
  33. handleDedupStrategyChange = (dedupStrategy: LogsDedupStrategy) => {
  34. this.props.changeDedupStrategy(this.props.exploreId, dedupStrategy);
  35. };
  36. render() {
  37. const {
  38. exploreId,
  39. loading,
  40. logsHighlighterExpressions,
  41. logsResult,
  42. onChangeTime,
  43. onClickLabel,
  44. onStartScanning,
  45. onStopScanning,
  46. range,
  47. showingLogs,
  48. scanning,
  49. scanRange,
  50. width,
  51. } = this.props;
  52. return (
  53. <Panel label="Logs" loading={loading} isOpen={showingLogs} onToggle={this.onClickLogsButton}>
  54. <Logs
  55. dedupStrategy={this.props.dedupStrategy || LogsDedupStrategy.none}
  56. data={logsResult}
  57. exploreId={exploreId}
  58. key={logsResult && logsResult.id}
  59. highlighterExpressions={logsHighlighterExpressions}
  60. loading={loading}
  61. onChangeTime={onChangeTime}
  62. onClickLabel={onClickLabel}
  63. onStartScanning={onStartScanning}
  64. onStopScanning={onStopScanning}
  65. onDedupStrategyChange={this.handleDedupStrategyChange}
  66. range={range}
  67. scanning={scanning}
  68. scanRange={scanRange}
  69. width={width}
  70. />
  71. </Panel>
  72. );
  73. }
  74. }
  75. const selectItemUIState = (itemState: ExploreItemState) => {
  76. const { showingGraph, showingLogs, showingTable, showingStartPage, dedupStrategy } = itemState;
  77. return {
  78. showingGraph,
  79. showingLogs,
  80. showingTable,
  81. showingStartPage,
  82. dedupStrategy,
  83. };
  84. };
  85. function mapStateToProps(state: StoreState, { exploreId }) {
  86. const explore = state.explore;
  87. const item: ExploreItemState = explore[exploreId];
  88. const { logsHighlighterExpressions, logsResult, queryTransactions, scanning, scanRange, range } = item;
  89. const loading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done);
  90. const {showingLogs, dedupStrategy} = selectItemUIState(item);
  91. return {
  92. loading,
  93. logsHighlighterExpressions,
  94. logsResult,
  95. scanning,
  96. scanRange,
  97. showingLogs,
  98. range,
  99. dedupStrategy,
  100. };
  101. }
  102. const mapDispatchToProps = {
  103. toggleLogs,
  104. changeDedupStrategy,
  105. };
  106. export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(LogsContainer));