fix global filter input (#9567)

* fix global filter input

* remove clear

* close global filters after clicking apply

* add restFilter
This commit is contained in:
mcbrewster 2020-04-07 14:31:19 -06:00 committed by GitHub
parent 73a6baaeb6
commit 6e50d29b4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 11 deletions

View File

@ -313,6 +313,7 @@ export interface LoadDataViewState {
selectedFilterIndex: number;
selectedFilter?: DruidFilter;
showGlobalFilter: boolean;
newFilterValue?: Record<string, any>;
// for schema
schemaQueryState: QueryState<{
@ -2066,7 +2067,7 @@ export class LoadDataView extends React.PureComponent<LoadDataViewProps, LoadDat
}
renderGlobalFilterControls() {
const { spec, showGlobalFilter } = this.state;
const { spec, showGlobalFilter, newFilterValue } = this.state;
const intervals: string[] = deepGet(spec, 'spec.dataSchema.granularitySpec.intervals');
const { restFilter } = splitFilter(deepGet(spec, 'spec.dataSchema.transformSpec.filter'));
const hasGlobalFilter = Boolean(intervals || restFilter);
@ -2094,19 +2095,24 @@ export class LoadDataView extends React.PureComponent<LoadDataViewProps, LoadDat
/>
<FormGroup label="Extra filter">
<JsonInput
value={restFilter}
onChange={f => {
const curFilter = splitFilter(
deepGet(spec, 'spec.dataSchema.transformSpec.filter'),
);
const newFilter = joinFilter(deepSet(curFilter, `restFilter`, f));
this.updateSpec(deepSet(spec, 'spec.dataSchema.transformSpec.filter', newFilter));
}}
value={newFilterValue}
onChange={f => this.setState({ newFilterValue: f })}
height="200px"
/>
</FormGroup>
<div className="control-buttons">
<Button text="Apply" intent={Intent.PRIMARY} onClick={() => this.queryForFilter()} />
<Button
text="Apply"
intent={Intent.PRIMARY}
onClick={() => {
const curFilter = splitFilter(
deepGet(spec, 'spec.dataSchema.transformSpec.filter'),
);
const newFilter = joinFilter(deepSet(curFilter, `restFilter`, newFilterValue));
this.updateSpec(deepSet(spec, 'spec.dataSchema.transformSpec.filter', newFilter));
this.setState({ showGlobalFilter: false, newFilterValue: undefined });
}}
/>
<Button text="Cancel" onClick={() => this.setState({ showGlobalFilter: false })} />
</div>
</div>
@ -2116,7 +2122,12 @@ export class LoadDataView extends React.PureComponent<LoadDataViewProps, LoadDat
<FormGroup>
<Button
text={`${hasGlobalFilter ? 'Edit' : 'Add'} global filter`}
onClick={() => this.setState({ showGlobalFilter: true })}
onClick={() =>
this.setState({
showGlobalFilter: true,
newFilterValue: restFilter,
})
}
/>
</FormGroup>
);