You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/07/30 07:25:31 UTC

[GitHub] [incubator-superset] tanmaylaud commented on a change in pull request #10455: chore: Migrate Timer component from jsx to tsx

tanmaylaud commented on a change in pull request #10455:
URL: https://github.com/apache/incubator-superset/pull/10455#discussion_r462762720



##########
File path: superset-frontend/src/components/Timer.tsx
##########
@@ -0,0 +1,76 @@
+/**
+ * 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 React, { useEffect, useRef, useState } from 'react';
+import { Label } from 'react-bootstrap';
+
+import { now, fDuration } from '../modules/dates';
+
+interface TimerProps {
+  endTime?: number;
+  isRunning: boolean;
+  startTime?: number;
+  status?: string;
+  style?: object;

Review comment:
       react-bootstrap has the 'bsStyle' . So, putting React.CSSProperties makes sense. Adding it.

##########
File path: superset-frontend/src/components/Timer.tsx
##########
@@ -0,0 +1,76 @@
+/**
+ * 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 React, { useEffect, useRef, useState } from 'react';
+import { Label } from 'react-bootstrap';
+
+import { now, fDuration } from '../modules/dates';
+
+interface TimerProps {
+  endTime?: number;
+  isRunning: boolean;
+  startTime?: number;
+  status?: string;
+  style?: object;
+}
+
+export default function Timer({
+  endTime,
+  isRunning,
+  startTime,
+  status = 'success',
+  style,
+}: TimerProps) {
+  const [clockStr, setClockStr] = useState<string>('');

Review comment:
       Yes, it is not required. removing it.

##########
File path: superset-frontend/src/components/Timer.tsx
##########
@@ -0,0 +1,76 @@
+/**
+ * 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 React, { useEffect, useRef, useState } from 'react';
+import { Label } from 'react-bootstrap';
+
+import { now, fDuration } from '../modules/dates';
+
+interface TimerProps {
+  endTime?: number;
+  isRunning: boolean;
+  startTime?: number;
+  status?: string;
+  style?: object;
+}
+
+export default function Timer({
+  endTime,
+  isRunning,
+  startTime,
+  status = 'success',
+  style,
+}: TimerProps) {
+  const [clockStr, setClockStr] = useState<string>('');
+  const timer = useRef<NodeJS.Timeout>();

Review comment:
       I was waiting for someone to look at this from performance POV. Thanks for this. will change it to useState. I had put useRef considering the timer was to be set and unset very often. But useState makes it simpler.

##########
File path: superset-frontend/src/components/Timer.tsx
##########
@@ -0,0 +1,76 @@
+/**
+ * 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 React, { useEffect, useRef, useState } from 'react';
+import { Label } from 'react-bootstrap';
+
+import { now, fDuration } from '../modules/dates';
+
+interface TimerProps {
+  endTime?: number;
+  isRunning: boolean;
+  startTime?: number;
+  status?: string;
+  style?: object;
+}
+
+export default function Timer({
+  endTime,
+  isRunning,
+  startTime,
+  status = 'success',
+  style,
+}: TimerProps) {
+  const [clockStr, setClockStr] = useState<string>('');
+  const timer = useRef<NodeJS.Timeout>();
+
+  const stopwatch = () => {
+    if (startTime) {
+      const endDttm = endTime || now();
+      if (startTime < endDttm) {
+        setClockStr(fDuration(startTime, endDttm));
+      }
+      if (!isRunning) {
+        clearTimeout(timer.current!);
+      }
+    }
+  };
+
+  function stopTimer() {
+    clearInterval(timer.current!);

Review comment:
       Agreed! 

##########
File path: superset-frontend/src/components/Timer.tsx
##########
@@ -0,0 +1,76 @@
+/**
+ * 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 React, { useEffect, useRef, useState } from 'react';
+import { Label } from 'react-bootstrap';
+
+import { now, fDuration } from '../modules/dates';
+
+interface TimerProps {
+  endTime?: number;
+  isRunning: boolean;
+  startTime?: number;
+  status?: string;
+  style?: object;
+}
+
+export default function Timer({
+  endTime,
+  isRunning,
+  startTime,
+  status = 'success',
+  style,
+}: TimerProps) {
+  const [clockStr, setClockStr] = useState<string>('');
+  const timer = useRef<NodeJS.Timeout>();
+
+  const stopwatch = () => {
+    if (startTime) {
+      const endDttm = endTime || now();
+      if (startTime < endDttm) {
+        setClockStr(fDuration(startTime, endDttm));
+      }
+      if (!isRunning) {
+        clearTimeout(timer.current!);
+      }
+    }
+  };
+
+  function stopTimer() {

Review comment:
       defaulting to arrow notation 👍 




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org