Skip to content

Commit

Permalink
[CORL-2439]: Fix configurable flatten replies to ensure included in l…
Browse files Browse the repository at this point in the history
…ocal state (#3835)

* get flattenReplies for initLocalState

* small refactor

* get flattenReplies from StaticConfig

* add flattenReplies to createRouter

* refactor

* types; comment
  • Loading branch information
kabeaty authored and nick-funk committed Jan 6, 2022
1 parent 1f7b74e commit fbed435
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/client/stream/local/initLocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import {
} from "coral-framework/lib/relay";
import { GQLFEATURE_FLAG } from "coral-framework/schema";

import { FEATURE_FLAG } from "coral-stream/__generated__/AllCommentsTabContainer_settings.graphql";
import { initLocalStateQuery } from "coral-stream/__generated__/initLocalStateQuery.graphql";

import { COMMENTS_ORDER_BY } from "../constants";
import { AUTH_POPUP_ID, AUTH_POPUP_TYPE } from "./constants";

interface ResolvedConfig {
readonly featureFlags: FEATURE_FLAG[];
readonly featureFlags: string[];
readonly flattenReplies?: boolean | null;
}

Expand All @@ -32,7 +31,7 @@ async function resolveConfig(
return staticConfig as ResolvedConfig;
}
if (process.env.NODE_ENV === "development") {
// Send a graphql query to server during development to get the feature flags.
// Send a graphql query to server during development to get the needed settings.
// The reason is that we don't have static config during development.
const data = await fetchQuery<initLocalStateQuery>(
environment,
Expand All @@ -49,7 +48,10 @@ async function resolveConfig(

return data.settings as ResolvedConfig;
}
return { featureFlags: [] };
return {
featureFlags: [],
flattenReplies: false,
};
}

/**
Expand Down Expand Up @@ -82,7 +84,7 @@ const initLocalState: InitLocalState = async ({
...rest,
});

const { featureFlags, ...settings } = await resolveConfig(
const { featureFlags, flattenReplies } = await resolveConfig(
environment,
staticConfig
);
Expand Down Expand Up @@ -145,7 +147,7 @@ const initLocalState: InitLocalState = async ({
);

// Enable flatten replies
localRecord.setValue(!!settings.flattenReplies, "flattenReplies");
localRecord.setValue(!!flattenReplies, "flattenReplies");

// Enable z-key comment seen
localRecord.setValue(
Expand Down
5 changes: 5 additions & 0 deletions src/core/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface StaticConfig {
*/
featureFlags: string[];

/**
* flattenReplies is whether or not flattenReplies is enabled on the tenant.
*/
flattenReplies: boolean;

/**
* forceAdminLocalAuth is whether local authentication is always available
* for this Coral deployment. This is useful for ensuring that Coral service
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/app/router/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ const clientHandler = ({
req.coral.tenant?.featureFlags?.filter(validFeatureFlagsFilter(req.user)) ||
[];

const flattenReplies = req.coral.tenant?.flattenReplies || false;

res.render(viewTemplate, {
analytics,
staticURI: config.staticURI,
Expand All @@ -156,6 +158,7 @@ const clientHandler = ({
...config,
featureFlags,
tenantDomain: req.coral.tenant?.domain,
flattenReplies,
},
customCSSURL: enableCustomCSSQuery ? req.query.customCSSURL : null,
});
Expand Down
1 change: 1 addition & 0 deletions src/core/server/app/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function createRouter(app: AppOptions, options: RouterOptions) {
staticURI: app.config.get("static_uri") || "/",
graphQLSubscriptionURI: app.config.get("graphql_subscription_uri") || "",
featureFlags: [],
flattenReplies: false,
forceAdminLocalAuth: app.config.get("force_admin_local_auth"),
};

Expand Down

0 comments on commit fbed435

Please sign in to comment.