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