import { Debounce } from 'lodash-decorators'; import React from 'react'; import type { Subscription } from 'rxjs'; import { CreateFunctionButton } from './CreateFunctionButton'; import { FunctionGroupings } from './FunctionGroupings'; import type { Application } from '../application/application.model'; import type { IFunctionGroup } from '../domain'; import type { IFilterTag } from '../filterModel/FilterTags'; import { FilterTags } from '../filterModel/FilterTags'; import { FunctionState } from '../state'; import { Spinner } from '../widgets/spinners/Spinner'; export interface IFunctionsProps { app: Application; } export interface IFunctionsState { initialized: boolean; groups: IFunctionGroup[]; tags: IFilterTag[]; } export class Functions extends React.Component { private groupsUpdatedListener: Subscription; private functionsRefreshUnsubscribe: () => any; constructor(props: IFunctionsProps) { super(props); this.state = { initialized: false, groups: [], tags: [], }; } public componentDidMount(): void { const { app } = this.props; this.groupsUpdatedListener = FunctionState.filterService.groupsUpdatedStream.subscribe(() => this.groupsUpdated()); FunctionState.filterModel.asFilterModel.activate(); this.functionsRefreshUnsubscribe = app .getDataSource('functions') .onRefresh(null, () => this.updateFunctionGroups()); app.setActiveState(app.loadBalancers); this.updateFunctionGroups(); } public componentWillUnmount(): void { this.groupsUpdatedListener.unsubscribe(); this.functionsRefreshUnsubscribe(); } private groupsUpdated(): void { this.setState({ groups: FunctionState.filterModel.asFilterModel.groups, tags: FunctionState.filterModel.asFilterModel.tags, }); } @Debounce(200) private updateFunctionGroups(): void { FunctionState.filterModel.asFilterModel.applyParamsToUrl(); FunctionState.filterService.updateFunctionGroups(this.props.app); this.groupsUpdated(); if (this.props.app.getDataSource('functions').loaded) { this.setState({ initialized: true }); } } private clearFilters = (): void => { FunctionState.filterService.clearFilters(); this.updateFunctionGroups(); }; private tagCleared = (): void => { this.updateFunctionGroups(); }; public render(): React.ReactElement { const groupings = this.state.initialized ? (
{this.state.groups.length === 0 && (

No functions match the filters you've selected.

)}
) : (
); return (
{groupings}
); } }