Skip to content

Commit

Permalink
CB-5712 adds loaders for administration menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyteleshev committed Oct 18, 2024
1 parent ffe0a18 commit 5f37d7e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { ILoadableState } from '@cloudbeaver/core-utils';

import type { IRouteParams } from './IRouteParams.js';

export enum AdministrationItemType {
Expand Down Expand Up @@ -84,6 +86,7 @@ export interface IAdministrationItemOptions {
replace?: IAdministrationItemReplaceOptions;
defaultSub?: string;
defaultParam?: string;
getLoader?: () => ILoadableState[] | ILoadableState;
getDrawerComponent: () => AdministrationItemDrawerComponent;
getContentComponent: () => AdministrationItemContentComponent;
onLoad?: AdministrationItemEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export class AuthProvidersResource extends CachedMapResource<string, AuthProvide
}

protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, AuthProvider>> {
await this.serverConfigResource.load();

const all = this.aliases.isAlias(originalKey, CachedMapAllKey);

const { providers } = await this.graphQLService.sdk.getAuthProviders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ import {
type StyleRegistry,
ToolsActionStyles,
ToolsPanelStyles,
useAutoLoad,
useS,
} from '@cloudbeaver/core-blocks';
import { useService } from '@cloudbeaver/core-di';
import { OptionsPanelService, TabList, TabListStyles, TabsState, TabStyles } from '@cloudbeaver/core-ui';
import type { ILoadableState } from '@cloudbeaver/core-utils';
import { CaptureView } from '@cloudbeaver/core-view';

import { AdministrationCaptureViewContext } from './AdministrationCaptureViewContext.js';
import { AdministrationViewService } from './AdministrationViewService.js';
import { DrawerItem } from './DrawerItem.js';
import { reduceLoaders } from './getLoaders.js';
import { ItemContent } from './ItemContent.js';
import style from './shared/Administration.module.css';
import AdministrationStylesTab from './shared/AdministrationTab.module.css';
Expand Down Expand Up @@ -95,6 +98,9 @@ export const Administration = observer<React.PropsWithChildren<Props>>(function
const OptionsPanel = optionsPanelService.getPanelComponent();
const visibleItems = administrationItemService.getActiveItems(configurationWizard);
const onlyActiveItem = administrationItemService.items.find(filterOnlyActive(configurationWizard));
const loaders = administrationItemService.items.reduce<ILoadableState[]>(reduceLoaders, []);

useAutoLoad(Administration, loaders);

useLayoutEffect(() => {
contentRef.current?.scrollTo({ top: 0, left: 0 });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { IAdministrationItem } from '@cloudbeaver/core-administration';
import type { ILoadableState } from '@cloudbeaver/core-utils';

export function reduceLoaders(acc: ILoadableState[], item: IAdministrationItem): ILoadableState[] {
if (!item.getLoader) {
return acc;
}

const loader = item.getLoader();

if (Array.isArray(loader)) {
acc.push(...loader);
} else {
acc.push(loader);
}

return acc;
}

0 comments on commit 5f37d7e

Please sign in to comment.