function updateContextsFromPortalMessage()

in src/hooks/useKnockoutExplorer.ts [877:971]


function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
  if (
    configContext.PORTAL_BACKEND_ENDPOINT &&
    configContext.platform === Platform.Portal &&
    process.env.NODE_ENV === "development"
  ) {
    inputs.portalBackendEndpoint = configContext.PROXY_PATH;
  }

  const authorizationToken = inputs.authorizationToken || "";
  const databaseAccount = inputs.databaseAccount;

  updateConfigContext({
    ARM_ENDPOINT: normalizeArmEndpoint(inputs.csmEndpoint || configContext.ARM_ENDPOINT),
    MONGO_PROXY_ENDPOINT: inputs.mongoProxyEndpoint,
    CASSANDRA_PROXY_ENDPOINT: inputs.cassandraProxyEndpoint,
    PORTAL_BACKEND_ENDPOINT: inputs.portalBackendEndpoint,
  });

  updateAADEndpoints(inputs.serverId as PortalEnv);

  updateUserContext({
    authorizationToken,
    databaseAccount,
    resourceGroup: inputs.resourceGroup,
    subscriptionId: inputs.subscriptionId,
    tenantId: inputs.tenantId,
    subscriptionType: inputs.subscriptionType,
    userName: inputs.userName,
    quotaId: inputs.quotaId,
    portalEnv: inputs.serverId as PortalEnv,
    hasWriteAccess: inputs.hasWriteAccess ?? true,
    collectionCreationDefaults: inputs.defaultCollectionThroughput,
    isTryCosmosDBSubscription: inputs.isTryCosmosDBSubscription,
    feedbackPolicies: inputs.feedbackPolicies,
  });

  if (inputs.isPostgresAccount) {
    updateUserContext({ apiType: "Postgres", isReplica: !!inputs.isReplica });

    if (inputs.connectionStringParams) {
      // TODO: Remove after the nodes param has been updated to be a flat array in the OSS extension
      let flattenedNodesArray: Node[] = [];
      inputs.connectionStringParams.nodes?.forEach((node: Node | Node[]) => {
        if (Array.isArray(node)) {
          flattenedNodesArray = [...flattenedNodesArray, ...node];
        } else {
          flattenedNodesArray.push(node);
        }
      });
      inputs.connectionStringParams.nodes = flattenedNodesArray;
      updateUserContext({ postgresConnectionStrParams: inputs.connectionStringParams });
    }
  }

  if (inputs.isVCoreMongoAccount) {
    if (inputs.connectionStringParams) {
      updateUserContext({
        apiType: "VCoreMongo",
        vcoreMongoConnectionParams: inputs.connectionStringParams,
      });
    }
  }

  if (inputs.features) {
    Object.assign(userContext.features, extractFeatures(new URLSearchParams(inputs.features)));
  }

  if (inputs.flights) {
    if (inputs.flights.indexOf(Flights.AutoscaleTest) !== -1) {
      userContext.features.autoscaleDefault;
    }
    if (inputs.flights.indexOf(Flights.PartitionKeyTest) !== -1) {
      userContext.features.partitionKeyDefault = true;
    }
    if (inputs.flights.indexOf(Flights.PartitionKeyTest) !== -1) {
      userContext.features.partitionKeyDefault = true;
    }
    if (inputs.flights.indexOf(Flights.PKPartitionKeyTest) !== -1) {
      userContext.features.partitionKeyDefault2 = true;
    }
    if (inputs.flights.indexOf(Flights.PhoenixNotebooks) !== -1) {
      userContext.features.phoenixNotebooks = true;
    }
    if (inputs.flights.indexOf(Flights.PhoenixFeatures) !== -1) {
      userContext.features.phoenixFeatures = true;
    }
    if (inputs.flights.indexOf(Flights.NotebooksDownBanner) !== -1) {
      userContext.features.notebooksDownBanner = true;
    }
    if (inputs.flights.indexOf(Flights.PublicGallery) !== -1) {
      userContext.features.publicGallery = true;
    }
  }
}