Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): label autocomplete for report tab #6881

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions ui/src/app/reports/components/reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface State {
archivedWorkflows: boolean;
namespace: string;
labels: string[];
autocompleteLabels: string[];
error?: Error;
charts?: Chart[];
}
Expand Down Expand Up @@ -59,12 +60,14 @@ export class Reports extends BasePage<RouteComponentProps<any>, State> {
this.state = {
archivedWorkflows: !!this.queryParam('archivedWorkflows'),
namespace: Utils.getNamespace(this.props.match.params.namespace) || '',
labels: (this.queryParam('labels') || '').split(',').filter(v => v !== '')
labels: (this.queryParam('labels') || '').split(',').filter(v => v !== ''),
autocompleteLabels: ['']
};
}

public componentDidMount() {
this.fetchReport(this.state.namespace, this.state.labels, this.state.archivedWorkflows);
this.fetchWorkflowsLabels(this.state.archivedWorkflows);
}

public render() {
Expand Down Expand Up @@ -253,13 +256,35 @@ export class Reports extends BasePage<RouteComponentProps<any>, State> {
];
}

private fetchWorkflowsLabels(isArchivedWorkflows: boolean): void {
if (isArchivedWorkflows) {
services.archivedWorkflows.listLabelKeys().then(list => {
this.setState({
autocompleteLabels: list.items || []
});
});
}
}

private fetchArchivedWorkflowsLabels(key: string): Promise<any> {
return services.archivedWorkflows.listLabelValues(key).then(list => {
return list.items.map(i => key + '=' + i);
});
}

private renderFilters() {
return (
<div className='wf-filters-container'>
<div className='row'>
<div className=' columns small-12 xlarge-12'>
<p className='wf-filters-container__title'>Archived Workflows</p>
<Checkbox checked={this.state.archivedWorkflows} onChange={checked => this.fetchReport(this.state.namespace, this.state.labels, checked)} />
<Checkbox
checked={this.state.archivedWorkflows}
onChange={checked => {
this.fetchReport(this.state.namespace, this.state.labels, checked);
this.fetchWorkflowsLabels(checked);
}}
/>
</div>
<div className=' columns small-12 xlarge-12'>
<p className='wf-filters-container__title'>Namespace</p>
Expand All @@ -275,6 +300,8 @@ export class Reports extends BasePage<RouteComponentProps<any>, State> {
<TagsInput
placeholder='Labels'
tags={this.state.labels}
autocomplete={this.state.archivedWorkflows ? this.state.autocompleteLabels : null}
sublistQuery={this.state.archivedWorkflows ? this.fetchArchivedWorkflowsLabels : null}
onChange={labels => this.fetchReport(this.state.namespace, labels, this.state.archivedWorkflows)}
/>
</div>
Expand Down