Skip to content

Commit

Permalink
Disable auto-refresh in edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Heenawter committed Jun 26, 2024
1 parent d263fa8 commit fe6de5f
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,8 @@ export const dashboardContainerReducers = {
setDisableQueryInput: (state: DashboardReduxState, action: PayloadAction<boolean>) => {
state.componentState.disableQueryInput = action.payload;
},

setDisableAutoRefresh: (state: DashboardReduxState, action: PayloadAction<boolean>) => {
state.componentState.disableAutoRefresh = action.payload;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const reducersToIgnore: Array<keyof typeof dashboardContainerReducers> =
'setExpandedPanelId',
'setHasUnsavedChanges',
'setDisableQueryInput',
'setDisableAutoRefresh',
];

/**
Expand Down
1 change: 1 addition & 0 deletions src/plugins/dashboard/public/dashboard_container/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface DashboardPublicState {
focusedPanelId?: string;

disableQueryInput?: boolean;
disableAutoRefresh?: boolean;
}

export type DashboardLoadType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function InternalDashboardTopNav({
(state) => state.componentState.hasRunClientsideMigrations
);
const disableQueryInput = dashboard.select((state) => state.componentState.disableQueryInput);
const disableAutoRefresh = dashboard.select((state) => state.componentState.disableAutoRefresh);
const hasUnsavedChanges = dashboard.select((state) => state.componentState.hasUnsavedChanges);
const fullScreenMode = dashboard.select((state) => state.componentState.fullScreenMode);
const savedQueryId = dashboard.select((state) => state.componentState.savedQueryId);
Expand Down Expand Up @@ -340,6 +341,7 @@ export function InternalDashboardTopNav({
: setHeaderActionMenu
}
disableQueryInput={disableQueryInput}
disableAutoRefresh={disableAutoRefresh}
className={fullScreenMode ? 'kbnTopNavMenu-isFullScreen' : undefined}
config={
visibilityProps.showTopNavMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function SavedSearchDataviewEditor({

useEffect(() => {
(api.parentApi as DashboardContainer).ignoreUnifiedSearch = true;
(api.parentApi as DashboardContainer).dispatch.setDisableAutoRefresh(true);

/** Handle query */
const originalQuery = services.data.query.queryString.getQuery();
Expand Down Expand Up @@ -103,6 +104,7 @@ export function SavedSearchDataviewEditor({
services.timefilter.setTime(originalTime);

(api.parentApi as DashboardContainer).ignoreUnifiedSearch = false;
(api.parentApi as DashboardContainer).dispatch.setDisableAutoRefresh(false);
querySubscription.unsubscribe();
filtersSubscription.unsubscribe();
timeRangeSubscription.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function SavedSearchEsqlEditor({
useEffect(() => {
(api.parentApi as DashboardContainer).ignoreUnifiedSearch = true;
(api.parentApi as DashboardContainer).dispatch.setDisableQueryInput(true);
(api.parentApi as DashboardContainer).dispatch.setDisableAutoRefresh(true);

/** Handle filters */
const originalFilters = services.filterManager.getFilters();
Expand Down Expand Up @@ -82,12 +83,12 @@ export function SavedSearchEsqlEditor({
});

return () => {
(api.parentApi as DashboardContainer).dispatch.setDisableQueryInput(false);

services.filterManager.setFilters(originalFilters);
services.timefilter.setTime(originalTime);

(api.parentApi as DashboardContainer).ignoreUnifiedSearch = false;
(api.parentApi as DashboardContainer).dispatch.setDisableQueryInput(false);
(api.parentApi as DashboardContainer).dispatch.setDisableAutoRefresh(false);
filtersSubscription.unsubscribe();
timeRangeSubscription.unsubscribe();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface QueryBarTopRowProps<QT extends Query | AggregateQuery = Query>
showDatePicker?: boolean;
isDisabled?: boolean;
disableQueryInput?: boolean;
disableAutoRefresh?: boolean;
showAutoRefreshOnly?: boolean;
timeHistory?: TimeHistoryContract;
timeRangeForSuggestionsOverride?: boolean;
Expand Down Expand Up @@ -505,7 +506,7 @@ export const QueryBarTopRow = React.memo(
refreshInterval={props.refreshInterval}
onTimeChange={onTimeChange}
onRefresh={onRefresh}
onRefreshChange={props.onRefreshChange}
onRefreshChange={props.disableAutoRefresh ? undefined : props.onRefreshChange}
showUpdateButton={false}
recentlyUsedRanges={recentlyUsedRanges}
locale={i18n.getLocale()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type StatefulSearchBarProps<QT extends Query | AggregateQuery = Query> =
onSavedQueryIdChange?: (savedQueryId?: string) => void;
onFiltersUpdated?: (filters: Filter[]) => void;
disableQueryInput?: boolean;
disableAutoRefresh?: boolean;
};

// Respond to user changing the filters
Expand Down Expand Up @@ -228,6 +229,7 @@ export function createSearchBar({
submitButtonStyle={props.submitButtonStyle}
isDisabled={props.isDisabled}
disableQueryInput={props.disableQueryInput}
disableAutoRefresh={props.disableAutoRefresh}
screenTitle={props.screenTitle}
indexPatterns={props.indexPatterns}
indicateNoData={props.indicateNoData}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/unified_search/public/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export interface SearchBarOwnProps<QT extends AggregateQuery | Query = Query> {
*/
isDisabled?: boolean;
disableQueryInput?: boolean;
disableAutoRefresh?: boolean;

submitOnBlur?: boolean;

Expand Down Expand Up @@ -617,6 +618,7 @@ class SearchBarUI<QT extends (Query | AggregateQuery) | Query = Query> extends C
showQueryInput={this.props.showQueryInput}
showAddFilter={this.props.showFilterBar}
disableQueryInput={this.props.disableQueryInput}
disableAutoRefresh={this.props.disableAutoRefresh}
isDisabled={this.props.isDisabled}
onRefresh={this.props.onRefresh}
onRefreshChange={this.props.onRefreshChange}
Expand Down

0 comments on commit fe6de5f

Please sign in to comment.