Skip to content

Commit

Permalink
bring in ticker from argo-ui
Browse files Browse the repository at this point in the history
Signed-off-by: Emily <[email protected]>
  • Loading branch information
emily-blixt-ck committed Dec 14, 2023
1 parent 27398b2 commit f8cf2c0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ui/src/app/components/pods/pods.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import * as moment from 'moment';
import {DropDown, Duration, Ticker} from 'argo-ui';
import {DropDown, Duration} from 'argo-ui';
import {RolloutReplicaSetInfo} from '../../../models/rollout/generated';
import {ReplicaSetStatus, ReplicaSetStatusIcon} from '../status-icon/status-icon';
import './pods.scss';
Expand All @@ -10,6 +10,7 @@ import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import {IconDefinition, faCheck, faCircleNotch, faClipboard, faExclamationTriangle, faQuestionCircle, faTimes} from '@fortawesome/free-solid-svg-icons';
import {EllipsisMiddle} from '../ellipsis-middle/ellipsis-middle';
import {InfoItem} from '../info-item/info-item';
import {Ticker} from '../ticker/ticker';

export enum PodStatus {
Pending = 'pending',
Expand Down
40 changes: 40 additions & 0 deletions ui/src/app/components/ticker/ticker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as moment from 'moment';
import * as React from 'react';
import {interval, Subscription} from 'rxjs';

export class Ticker extends React.Component<{intervalMs?: number; disabled?: boolean; children?: (time: moment.Moment) => React.ReactNode}, {time: moment.Moment}> {
private subscription: Subscription | null = null;

constructor(props: {intervalMs?: number; children?: (time: moment.Moment) => React.ReactNode}) {
super(props);
this.state = {time: moment()};
this.ensureSubscribed();
}

public render() {
return this.props.children && this.props.children(this.state.time);
}

public componentDidUpdate() {
this.ensureSubscribed();
}

public componentWillUnmount() {
this.ensureUnsubscribed();
}

private ensureSubscribed() {
if (this.props.disabled) {
this.ensureUnsubscribed();
} else if (!this.subscription) {
this.subscription = interval(this.props.intervalMs || 1000).subscribe(() => this.setState({time: moment()}));
}
}

private ensureUnsubscribed() {
if (this.subscription != null) {
this.subscription.unsubscribe();
this.subscription = null;
}
}
}

0 comments on commit f8cf2c0

Please sign in to comment.