How to use @bentley/presentation-frontend - 10 common examples

To help you get started, we’ve selected a few @bentley/presentation-frontend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / test-apps / presentation-test-app / src / frontend / index.tsx View on Github external
setCustomFavoritePropertiesManager();

    // __PUBLISH_EXTRACT_START__ Presentation.Frontend.Initialization
    Presentation.initialize({
      // specify `clientId` so Presentation framework can share caches
      // between sessions for the same clients
      clientId: MyAppFrontend.getClientId(),

      // specify locale for localizing presentation data
      activeLocale: IModelApp.i18n.languageList()[0],
    });
    // __PUBLISH_EXTRACT_END__

    // __PUBLISH_EXTRACT_START__ Presentation.Frontend.SetSelectionScope
    Presentation.selection.scopes.activeScope = "top-assembly";
    // __PUBLISH_EXTRACT_END__

    readyPromises.push(UiCore.initialize(IModelApp.i18n));
    readyPromises.push(UiComponents.initialize(IModelApp.i18n));
    this._ready = Promise.all(readyPromises).then(() => { });
  }
github imodeljs / imodeljs / presentation / testing / src / Helpers.ts View on Github external
PresentationBackend.initialize(backendProps);

  // set up rpc interfaces
  initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);

  if (!isFrontendAppInitialized) {
    // init frontend
    frontendApp.startup();
    setCustomFavoritePropertiesManager();
    isFrontendAppInitialized = true;
  }

  const defaultFrontendProps: PresentationFrontendProps = {
    activeLocale: IModelApp.i18n.languageList()[0],
  };
  PresentationFrontend.initialize({ ...defaultFrontendProps, ...frontendProps });

  isInitialized = true;
};
github imodeljs / imodeljs / test-apps / presentation-test-app / src / frontend / index.tsx View on Github external
public static startup() {
    IModelApp.startup();
    const readyPromises = new Array>();

    const localizationNamespace = IModelApp.i18n.registerNamespace("Sample");
    readyPromises.push(localizationNamespace.readFinished);

    // Configure a CORS proxy in development mode.
    if (process.env.NODE_ENV === "development")
      Config.App.set("imjs_dev_cors_proxy_server", `http://${window.location.hostname}:3001`); // By default, this will run on port 3001

    setCustomFavoritePropertiesManager();

    // __PUBLISH_EXTRACT_START__ Presentation.Frontend.Initialization
    Presentation.initialize({
      // specify `clientId` so Presentation framework can share caches
      // between sessions for the same clients
      clientId: MyAppFrontend.getClientId(),

      // specify locale for localizing presentation data
      activeLocale: IModelApp.i18n.languageList()[0],
    });
    // __PUBLISH_EXTRACT_END__

    // __PUBLISH_EXTRACT_START__ Presentation.Frontend.SetSelectionScope
    Presentation.selection.scopes.activeScope = "top-assembly";
    // __PUBLISH_EXTRACT_END__

    readyPromises.push(UiCore.initialize(IModelApp.i18n));
    readyPromises.push(UiComponents.initialize(IModelApp.i18n));
    this._ready = Promise.all(readyPromises).then(() => { });
github imodeljs / imodeljs / test-apps / ui-test-app / src / frontend / index.tsx View on Github external
public static async initialize() {
    Presentation.initialize();
    Presentation.selection.scopes.activeScope = "top-assembly";
    UiCore.initialize(IModelApp.i18n); // tslint:disable-line:no-floating-promises
    UiComponents.initialize(IModelApp.i18n); // tslint:disable-line:no-floating-promises

    const oidcConfiguration = this.getOidcConfiguration();
    await UiFramework.initialize(SampleAppIModelApp.store, IModelApp.i18n, oidcConfiguration, "frameworkState");

    // initialize Presentation
    Presentation.initialize({
      activeLocale: IModelApp.i18n.languageList()[0],
    });

    // Register tools.
    Tool1.register(this.sampleAppNamespace);
    Tool2.register(this.sampleAppNamespace);
    ToolWithSettings.register(this.sampleAppNamespace);
github imodeljs / imodeljs / presentation / testing / src / Helpers.ts View on Github external
export const terminate = (frontendApp = IModelApp) => {
  if (!isInitialized)
    return;

  // store directory that needs to be cleaned-up
  const tempDirectory = (PresentationBackend.initProps && PresentationBackend.initProps.id)
    ? path.join(KnownLocations.tmpdir, "ecpresentation", PresentationBackend.initProps.id) : undefined;

  // terminate backend
  PresentationBackend.terminate();
  IModelHost.shutdown();
  if (tempDirectory)
    rimraf.sync(tempDirectory);

  // terminate frontend
  PresentationFrontend.terminate();
  frontendApp.shutdown();

  isInitialized = false;
  isFrontendAppInitialized = false;
};
github imodeljs / imodeljs / ui / framework / src / ui-framework / UiFramework.ts View on Github external
public static setActiveSelectionScope(selectionScopeId: string): void {
    // istanbul ignore else
    if (UiFramework.frameworkState) {
      const foundIndex = UiFramework.frameworkState.sessionState.availableSelectionScopes.findIndex((selectionScope: PresentationSelectionScope) => selectionScope.id === selectionScopeId);
      if (-1 !== foundIndex) {
        const scope = UiFramework.frameworkState.sessionState.availableSelectionScopes[foundIndex];
        UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, scope.id);
        Presentation.selection.scopes.activeScope = scope.id;
      }
    }
  }
github imodeljs / imodeljs / ui / framework / src / ui-framework / syncui / SyncUiEventDispatcher.ts View on Github external
(iModelConnection.iModelToken && iModelConnection.iModelToken.iModelId) ? UiFramework.setActiveIModelId(iModelConnection.iModelToken.iModelId) : "";
    if (SyncUiEventDispatcher._unregisterListenerFunc)
      SyncUiEventDispatcher._unregisterListenerFunc();

    // listen for changes from presentation rules selection manager (this is done once an iModelConnection is available to ensure Presentation.selection is valid)
    SyncUiEventDispatcher._unregisterListenerFunc = Presentation.selection.selectionChange.addListener((args: SelectionChangeEventArgs, provider: ISelectionProvider) => {
      if (args.level !== 0) {
        // don't need to handle sub-selections
        return;
      }
      const selection = provider.getSelection(args.imodel, args.level);
      const numSelected = getInstancesCount(selection);
      UiFramework.dispatchActionToStore(SessionStateActionId.SetNumItemsSelected, numSelected);
    });

    Presentation.selection.scopes.getSelectionScopes(iModelConnection).then((availableScopes: SelectionScope[]) => { // tslint:disable-line:no-floating-promises
      // istanbul ignore else
      if (availableScopes) {
        const presentationScopes: PresentationSelectionScope[] = [];
        availableScopes.map((scope) => presentationScopes.push(scope));
        UiFramework.dispatchActionToStore(SessionStateActionId.SetAvailableSelectionScopes, presentationScopes);
      }
    });

    const activeSelectionScope = Presentation.selection.scopes.activeScope;
    if (activeSelectionScope) {
      if (typeof (activeSelectionScope) === "object") {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, (activeSelectionScope as SelectionScope).id);
      } else {
        UiFramework.dispatchActionToStore(SessionStateActionId.SetSelectionScope, activeSelectionScope);
      }
    }
github imodeljs / imodeljs / presentation / components / src / common / ContentDataProvider.ts View on Github external
private getDefaultContentDescriptor = _.memoize(async (): Promise => {
    // istanbul ignore if
    if (this.keys.size > DEFAULT_KEYS_BATCH_SIZE) {
      const msg = `ContentDataProvider.getContentDescriptor requesting descriptor with ${this.keys.size} keys which
        exceeds the suggested size of ${DEFAULT_KEYS_BATCH_SIZE}. Possible "HTTP 413 Payload Too Large" error.`;
      Logger.logWarning("Presentation.Components", msg);
    }
    return Presentation.presentation.getContentDescriptor(this.createRequestOptions(),
      this._displayType, this.keys, this.selectionInfo);
  });
github imodeljs / imodeljs / ui / framework / src / ui-framework / pickers / ModelSelector / ModelSelector.tsx View on Github external
private _initCategoryState = async () => {
    return Presentation.presentation
      .rulesets()
      .add(require("../../../../rulesets/Categories.json")) // tslint:disable-line:no-floating-promises
      .then((ruleset: RegisteredRuleset) => {
        this._categoryRuleset = ruleset;

        this._setViewType(ruleset).then(() => {
          // tslint:disable-line:no-floating-promises
          this._updateCategoriesWithViewport(this.state.activeView); // tslint:disable-line:no-floating-promises
        });
      });
  }
github imodeljs / imodeljs / presentation / components / src / common / ContentDataProvider.ts View on Github external
private async registerRuleset(ruleset: Ruleset) {
    this._registeredRuleset = await Presentation.presentation.rulesets().add(ruleset);
    if (this._isDisposed) {
      // ensure we don't keep a hanging registered ruleset if the data provider
      // gets destroyed before the ruleset finishes registration
      this.disposeRegisteredRuleset();
    }
  }