vogievetsky commented on a change in pull request #7912: Web-console: add timed 
button 
URL: https://github.com/apache/incubator-druid/pull/7912#discussion_r295354453
 
 

 ##########
 File path: web-console/src/components/timed-button/timed-button.tsx
 ##########
 @@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Button, ButtonGroup, IButtonProps, Popover, Radio, RadioGroup } from 
'@blueprintjs/core';
+import { IconNames } from '@blueprintjs/icons';
+import React from 'react';
+
+import { localStorageGet, LocalStorageKeys, localStorageSet } from 
'../../utils';
+
+import './timed-button.scss';
+import Timeout = NodeJS.Timeout;
+
+export interface Interval {
+  label: string;
+  value: number;
+}
+
+export interface TimedButtonProps extends IButtonProps {
+  intervals: Interval[];
+  onRefresh: (auto: boolean) => void;
+  localstoragekey?: LocalStorageKeys;
+  label: string;
+}
+
+export interface TimedButtonState {
+  interval: number;
+}
+
+export class TimedButton extends React.PureComponent<TimedButtonProps, 
TimedButtonState> {
+  constructor(props: TimedButtonProps, context: any) {
+    super(props, context);
+    this.state = {
+      interval: 30000
+    };
+  }
+
+  private timer: Timeout;
+
+  componentDidMount(): void {
+    let interval = 30000;
+    if (this.props.localstoragekey) {
+      if (localStorageGet(this.props.localstoragekey) !== null) {
+        interval = Number(localStorageGet(this.props.localstoragekey));
+      }
+      this.setState({interval: interval});
+      if (interval) {
+        this.timer = setTimeout(() => {this.continousRefresh(interval); }, 
interval);
+      }
+    }
+  }
+
+
+  componentWillUnmount(): void {
+    clearTimeout(this.timer);
+  }
+
+  continousRefresh = (selectedInterval: number) => {
+    if (selectedInterval) {
+      this.timer = setTimeout(() => {
+        this.props.onRefresh(true);
+        this.continousRefresh(selectedInterval);
+      }, selectedInterval);
+    }
+  }
+
+  handleSelection( selectedInterval: number) {
+    clearTimeout(this.timer);
+    this.setState({interval: selectedInterval});
+    if (this.props.localstoragekey) {
+      localStorageSet(this.props.localstoragekey, String(selectedInterval));
+    }
+    this.continousRefresh(selectedInterval);
+  }
+
+  render() {
+    const { label, intervals, localstoragekey, onRefresh, type, ...other } = 
this.props;
+    const { interval } = this.state;
+
+    return <ButtonGroup>
 
 Review comment:
   for completeness you might need to pass some props (like `minimal`, `large`, 
`intent`, etc) to the ButtonGroup. Have a look at the button group interface 
and see what props it shares with Button and make sure those all work as 
desired.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to