Skip to content

Commit

Permalink
Fix Prettier issues
Browse files Browse the repository at this point in the history
  • Loading branch information
guidomodarelli committed Sep 27, 2024
1 parent bca9d84 commit a025932
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@
* under the License.
*/

import { Filter, QueryStart } from '../../../../../../../src/plugins/data/public';
import {
Filter,
QueryStart,
} from '../../../../../../../src/plugins/data/public';

export const clearStateFromSavedQuery = (queryService: QueryStart, setFilters: (filters: Filter[]) => void) => {
export const clearStateFromSavedQuery = (
queryService: QueryStart,
setFilters: (filters: Filter[]) => void,
) => {
setFilters([]);
queryService.queryString.clearQuery();
};
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ export const populateStateFromSavedQuery = (
// filters
const savedQueryFilters = savedQuery.attributes.filters || [];
setFilters(savedQueryFilters);

};
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ interface UseSavedQueriesReturn {
clearSavedQuery: () => void;
}

export const useSavedQuery = (props: UseSavedQueriesProps): UseSavedQueriesReturn => {
export const useSavedQuery = (
props: UseSavedQueriesProps,
): UseSavedQueriesReturn => {
// Handle saved queries
const [savedQuery, setSavedQuery] = useState<SavedQuery | undefined>();
const osdUrlStateStorage = OsdUrlStateStorage.getInstance();
Expand All @@ -67,7 +69,11 @@ export const useSavedQuery = (props: UseSavedQueriesProps): UseSavedQueriesRetur
const updateSavedQuery = async (savedQuery: SavedQuery) => {
setSavedQuery(savedQuery);
saveSavedQuery(savedQuery.id);
populateStateFromSavedQuery(props.queryService, props.setFilters, savedQuery);
populateStateFromSavedQuery(
props.queryService,
props.setFilters,
savedQuery,
);
};

const clearSavedQuery = () => {
Expand All @@ -81,10 +87,13 @@ export const useSavedQuery = (props: UseSavedQueriesProps): UseSavedQueriesRetur
useEffect(() => {
const fetchSavedQuery = async () => {
try {
const savedQueryId = osdUrlStateStorage.appStateFromUrl.savedQuery as string;
const savedQueryId = osdUrlStateStorage.appStateFromUrl
.savedQuery as string;
if (!savedQueryId) return;
// fetch saved query
const savedQuery = await props.queryService.savedQueries.getSavedQuery(savedQueryId);
const savedQuery = await props.queryService.savedQueries.getSavedQuery(
savedQueryId,
);
updateSavedQuery(savedQuery);
} catch (error) {
clearSavedQuery();
Expand Down
11 changes: 8 additions & 3 deletions plugins/main/public/components/overview/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { MainModule } from '../common/modules/main';
import { WzCurrentOverviewSectionWrapper } from '../common/modules/overview-current-section-wrapper';
import { PinnedAgentManager } from '../wz-agent-selector/wz-agent-selector-service';
import { withRouteResolvers } from '../common/hocs';
import { enableMenu, ip, nestedResolve, savedSearch } from '../../services/resolves';
import {
enableMenu,
ip,
nestedResolve,
savedSearch,
} from '../../services/resolves';
import { useRouterSearch } from '../common/hooks';
import NavigationService from '../../react-services/navigation-service';
import OsdUrlStateStorage from '../../react-services/state-storage';
Expand Down Expand Up @@ -70,10 +75,10 @@ export const Overview: React.FC = withRouteResolvers({
tab: tab,
subtab: tabView,
}}
switchSubTab={(subTab) => switchSubTab(subTab)}
switchSubTab={subTab => switchSubTab(subTab)}
/>
<WzCurrentOverviewSectionWrapper
switchTab={(tab) => switchTab(tab)}
switchTab={tab => switchTab(tab)}
currentTab={tab}
/>
</>
Expand Down
1 change: 0 additions & 1 deletion plugins/main/public/react-services/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export * from './action-agents';
export * from './app-state';
export * from './check-daemons-status';
Expand Down
30 changes: 20 additions & 10 deletions plugins/main/public/react-services/state-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { OSD_URL_STATE_STORAGE_ID } from '../../common/constants';
import { AppState } from './app-state';
import { migrateLegacyQuery } from '../utils/migrate_legacy_query';
import { cloneDeep } from 'lodash';
import { getDataPlugin, getUiSettings } from "../kibana-services";
import NavigationService from "./navigation-service";
import { getDataPlugin, getUiSettings } from '../kibana-services';
import NavigationService from './navigation-service';

export default class OsdUrlStateStorage {
private static instance: OsdUrlStateStorage;
Expand All @@ -39,7 +39,7 @@ export default class OsdUrlStateStorage {
private constructor(
private readonly data: DataPublicPluginStart,
config: IUiSettingsClient,
history: History
history: History,
) {
this.osdUrlStateStorage = createOsdUrlStateStorage({
useHash: config.get(OSD_URL_STATE_STORAGE_ID),
Expand All @@ -48,11 +48,15 @@ export default class OsdUrlStateStorage {
}

get appStateFromUrl() {
return this.osdUrlStateStorage.get(OsdUrlStateStorage.APP_STORAGE_KEY) as AppState;
return this.osdUrlStateStorage.get(
OsdUrlStateStorage.APP_STORAGE_KEY,
) as AppState;
}

get appStateContainer() {
const defaultQuery = migrateLegacyQuery(this.data.query.queryString.getDefaultQuery());
const defaultQuery = migrateLegacyQuery(
this.data.query.queryString.getDefaultQuery(),
);
let initialAppState = {
query: defaultQuery,
...this.appStateFromUrl,
Expand All @@ -62,7 +66,11 @@ export default class OsdUrlStateStorage {

public async replaceUrlAppState(newPartial: AppState = {}) {
const state = { ...this.appStateContainer.getState(), ...newPartial };
await this.osdUrlStateStorage.set(OsdUrlStateStorage.APP_STORAGE_KEY, state, { replace: true });
await this.osdUrlStateStorage.set(
OsdUrlStateStorage.APP_STORAGE_KEY,
state,
{ replace: true },
);
}

public syncState() {
Expand All @@ -75,8 +83,10 @@ export default class OsdUrlStateStorage {
this.setAppFilters();
this.setAppQuery();

const stopSyncingQueryAppStateWithStateContainer = this.connectToQueryState();
const { stop: stopSyncingGlobalStateWithUrl } = this.syncQueryStateWithUrl();
const stopSyncingQueryAppStateWithStateContainer =
this.connectToQueryState();
const { stop: stopSyncingGlobalStateWithUrl } =
this.syncQueryStateWithUrl();

this.replaceUrlAppState().then(() => start());

Expand Down Expand Up @@ -115,13 +125,13 @@ export default class OsdUrlStateStorage {
// sync initial app filters from state to filterManager
// https://github.com/opensearch-project/OpenSearch-Dashboards/blob/2.13.0/src/plugins/dashboard/public/application/utils/use/use_dashboard_app_state.tsx#L84-L86
this.data.query.filterManager.setAppFilters(
cloneDeep(this.appStateContainer.getState().filters)
cloneDeep(this.appStateContainer.getState().filters),
);
}

private setAppQuery() {
this.data.query.queryString.setQuery(
migrateLegacyQuery(this.appStateContainer.getState().query)
migrateLegacyQuery(this.appStateContainer.getState().query),
);
}
}
4 changes: 1 addition & 3 deletions plugins/main/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": [
"./**/*"
],
"include": ["./**/*"],
"compilerOptions": {
"allowJs": true
}
Expand Down

0 comments on commit a025932

Please sign in to comment.