How to use the react-mosaic-component.getNodeAtPath function in react-mosaic-component

To help you get started, we’ve selected a few react-mosaic-component 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 cruise-automation / webviz / packages / webviz-core / src / components / Panel.js View on Github external
_openSiblingPanel = (panelType: string, siblingConfigCreator: (PanelConfig) => PanelConfig) => {
      const siblingComponent = PanelList.getComponentForType(panelType);
      if (!siblingComponent) {
        return;
      }
      const defaultSiblingConfig = siblingComponent.defaultConfig;

      const panelConfigById = this.props.store.getState().panels.savedProps;
      const { mosaicActions, mosaicWindowActions } = this.context;
      const ownPath = mosaicWindowActions.getPath();

      // Try to find a sibling summary panel and update it with the `siblingConfig`.
      const siblingPathEnd = ownPath[ownPath.length - 1] === "first" ? "second" : "first";
      const siblingPath = ownPath.slice(0, ownPath.length - 1).concat(siblingPathEnd);
      const siblingId = getNodeAtPath(mosaicActions.getRoot(), siblingPath);
      if (typeof siblingId === "string" && getPanelTypeFromId(siblingId) === panelType) {
        const siblingConfig: PanelConfig = { ...defaultSiblingConfig, ...(panelConfigById[siblingId]: any) };
        this.props.savePanelConfig({
          id: siblingId,
          config: siblingConfigCreator(siblingConfig),
          defaultConfig: defaultSiblingConfig,
        });
        return;
      }

      // Otherwise, open a new panel.
      const newPanelPath = ownPath.concat("second");
      mosaicWindowActions.split({ type: panelType }).then(() => {
        const newPanelId = getNodeAtPath(mosaicActions.getRoot(), newPanelPath);
        this.props.savePanelConfig({
          id: newPanelId,
github cruise-automation / webviz / packages / webviz-core / src / components / Panel.js View on Github external
mosaicWindowActions.split({ type: panelType }).then(() => {
        const newPanelId = getNodeAtPath(mosaicActions.getRoot(), newPanelPath);
        this.props.savePanelConfig({
          id: newPanelId,
          config: siblingConfigCreator(defaultSiblingConfig),
          defaultConfig: defaultSiblingConfig,
        });
      });
    };
github cruise-automation / webviz / packages / webviz-core / src / components / PanelToolbar / index.js View on Github external
split = (store, id: ?string, direction: "row" | "column") => {
    const { mosaicActions, mosaicWindowActions } = this.context;
    const type = this.getPanelType();
    if (!id || !type) {
      throw new Error("Trying to split unknown panel!");
    }

    getGlobalHooks().onPanelSplit(type);

    const config = store.getState().panels.savedProps[id];
    const newId = getPanelIdForType(type);
    this.props.savePanelConfig({ id: newId, config, defaultConfig: {} });

    const path = mosaicWindowActions.getPath();
    const root = mosaicActions.getRoot();
    mosaicActions.replaceWith(path, { direction, first: getNodeAtPath(root, path), second: newId });
  };
github cruise-automation / webviz / packages / webviz-core / src / panels / PanelList / index.js View on Github external
onPanelMenuItemDrop = (config: DropDescription) => {
    const { mosaicLayout, changePanelLayout, savePanelConfig } = this.props;
    const { panelType, position, path } = config;
    const newNode = getPanelIdForType(panelType);
    const node = getNodeAtPath(mosaicLayout, path);
    const before = position === "left" || position === "top";
    const [first, second] = before ? [newNode, node] : [node, newNode];
    const direction = position === "left" || position === "right" ? "row" : "column";
    const updates = [
      {
        path,
        spec: {
          $set: { first, second, direction },
        },
      },
    ];
    if (config.panelConfig) {
      savePanelConfig({ id: newNode, config: config.panelConfig, defaultConfig: {} });
    }
    const newLayout = updateTree(mosaicLayout, updates);
    changePanelLayout(newLayout);
github cruise-automation / webviz / packages / webviz-core / src / components / PanelToolbar / utils.js View on Github external
export function getPanelTypeFromMosiac(mosaicWindowActions: any, mosaicActions: any) {
  if (!mosaicWindowActions || !mosaicActions) {
    return null;
  }
  const node = getNodeAtPath(mosaicActions.getRoot(), mosaicWindowActions.getPath());
  const type = getPanelTypeFromId(node);

  return type;
}