Skip to content

Commit

Permalink
chore: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
gtk-grafana committed Dec 18, 2024
1 parent b99db18 commit 42661b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,10 @@ describe.each(['11.1.2', '11.1.1'])('AdHocFiltersVariable', (v) => {
const evtHandler = jest.fn();
variable.subscribeToEvent(SceneVariableValueChangedEvent, evtHandler);

variable.updateFilters( [{ key: 'key2', operator: '=', value: 'val1' }]);
variable.updateFilters([{ key: 'key2', operator: '=', value: 'val1' }]);

expect(evtHandler).toHaveBeenCalled();
expect(variable.state.filterExpression).toEqual(`key2="val1"`)
expect(variable.state.filterExpression).toEqual(`key2="val1"`);
});

it('updateFilters should not publish event on when expr did change, if skipPublish is true', () => {
Expand All @@ -1008,7 +1008,7 @@ describe.each(['11.1.2', '11.1.1'])('AdHocFiltersVariable', (v) => {
variable.updateFilters([{ key: 'key2', operator: '=', value: 'val1' }], { skipPublish: true });

expect(evtHandler).not.toHaveBeenCalled();
expect(variable.state.filterExpression).toEqual(`key2="val1"`)
expect(variable.state.filterExpression).toEqual(`key2="val1"`);
});

it('Should create variable with applyMode as manual by default and it allows to override it', () => {
Expand Down
16 changes: 10 additions & 6 deletions packages/scenes/src/variables/adhoc/AdHocFiltersVariable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,24 @@ export class AdHocFiltersVariable
* If `skipPublish` option is true, this will not emit the `SceneVariableValueChangedEvent`,
* allowing consumers to update the filters without triggering dependent data providers.
*/
public updateFilters(filters: AdHocFilterWithLabels[], options?: {
skipPublish?: boolean
}): void {
public updateFilters(
filters: AdHocFilterWithLabels[],
options?: {
skipPublish?: boolean;
}
): void {
let filterExpressionChanged = false;
let filterExpression = undefined
let filterExpression = undefined;

if (filters && filters !== this.state.filters) {
filterExpression = renderExpression(this.state.expressionBuilder, filters);
filterExpressionChanged = filterExpression !== this.state.filterExpression;
}

super.setState({
filters, filterExpression
})
filters,
filterExpression,
});

if (filterExpressionChanged && options?.skipPublish !== true) {
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
Expand Down

0 comments on commit 42661b0

Please sign in to comment.