Commit 3fd707f3 by Torkel Ödegaard

redux: progress

parent 2a64d19f
...@@ -15,12 +15,11 @@ interface Props { ...@@ -15,12 +15,11 @@ interface Props {
alertRules: AlertRule[]; alertRules: AlertRule[];
updateLocation: typeof updateLocation; updateLocation: typeof updateLocation;
getAlertRulesAsync: typeof getAlertRulesAsync; getAlertRulesAsync: typeof getAlertRulesAsync;
stateFilter: string;
} }
interface State { interface State {
rules: AlertRule[];
search: string; search: string;
stateFilter: string;
} }
export class AlertRuleList extends PureComponent<Props, State> { export class AlertRuleList extends PureComponent<Props, State> {
...@@ -37,29 +36,31 @@ export class AlertRuleList extends PureComponent<Props, State> { ...@@ -37,29 +36,31 @@ export class AlertRuleList extends PureComponent<Props, State> {
super(props); super(props);
this.state = { this.state = {
rules: [],
search: '', search: '',
stateFilter: '',
}; };
} }
componentDidMount() { componentDidMount() {
this.fetchRules(); this.fetchRules(this.getStateFilter());
} }
onStateFilterChanged = evt => { onStateFilterChanged = evt => {
this.props.updateLocation({ this.props.updateLocation({
query: { state: evt.target.value }, query: { state: evt.target.value },
}); });
this.fetchRules(); this.fetchRules(evt.target.value);
}; };
async fetchRules() { getStateFilter(): string {
await this.props.getAlertRulesAsync(); const { stateFilter } = this.props;
if (stateFilter) {
return stateFilter.toString();
}
return 'all';
}
// this.props.alertList.loadRules({ async fetchRules(stateFilter: string) {
// state: this.props.view.query.get('state') || 'all', await this.props.getAlertRulesAsync({ state: stateFilter });
// });
} }
onOpenHowTo = () => { onOpenHowTo = () => {
...@@ -76,7 +77,7 @@ export class AlertRuleList extends PureComponent<Props, State> { ...@@ -76,7 +77,7 @@ export class AlertRuleList extends PureComponent<Props, State> {
render() { render() {
const { navModel, alertRules } = this.props; const { navModel, alertRules } = this.props;
const { search, stateFilter } = this.state; const { search } = this.state;
return ( return (
<div> <div>
...@@ -99,7 +100,7 @@ export class AlertRuleList extends PureComponent<Props, State> { ...@@ -99,7 +100,7 @@ export class AlertRuleList extends PureComponent<Props, State> {
<label className="gf-form-label">States</label> <label className="gf-form-label">States</label>
<div className="gf-form-select-wrapper width-13"> <div className="gf-form-select-wrapper width-13">
<select className="gf-form-input" onChange={this.onStateFilterChanged} value={stateFilter}> <select className="gf-form-input" onChange={this.onStateFilterChanged} value={this.getStateFilter()}>
{this.stateFilters.map(AlertStateFilterOption)} {this.stateFilters.map(AlertStateFilterOption)}
</select> </select>
</div> </div>
...@@ -200,6 +201,7 @@ export class AlertRuleItem extends React.Component<AlertRuleItemProps, any> { ...@@ -200,6 +201,7 @@ export class AlertRuleItem extends React.Component<AlertRuleItemProps, any> {
const mapStateToProps = (state: StoreState) => ({ const mapStateToProps = (state: StoreState) => ({
navModel: getNavModel(state.navIndex, 'alert-list'), navModel: getNavModel(state.navIndex, 'alert-list'),
alertRules: state.alertRules, alertRules: state.alertRules,
stateFilter: state.location.query.state,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
......
...@@ -14,9 +14,11 @@ export const loadAlertRules = (rules: AlertRule[]): LoadAlertRulesAction => ({ ...@@ -14,9 +14,11 @@ export const loadAlertRules = (rules: AlertRule[]): LoadAlertRulesAction => ({
export type Action = LoadAlertRulesAction; export type Action = LoadAlertRulesAction;
export const getAlertRulesAsync = () => async (dispatch: Dispatch<Action>): Promise<AlertRule[]> => { export const getAlertRulesAsync = (options: { state: string }) => async (
dispatch: Dispatch<Action>
): Promise<AlertRule[]> => {
try { try {
const rules = await getBackendSrv().get('/api/alerts', {}); const rules = await getBackendSrv().get('/api/alerts', options);
dispatch(loadAlertRules(rules)); dispatch(loadAlertRules(rules));
return rules; return rules;
} catch (error) { } catch (error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment