Skip to content

Commit

Permalink
[ui-config] enable localization/rename option for white labeled users…
Browse files Browse the repository at this point in the history
… not in content editor mode

Issue: https://linear.app/plasmic/issue/PLA-10385/localization-should-be-enabled-for-all-client-projects
Change-Id: I717b5b968194d986f9639f97726a23434db6dad0
GitOrigin-RevId: 95f0bcf34d42f7753a2b2adeabf804cc62f6799d
  • Loading branch information
IcaroG authored and Copybara committed Jan 29, 2024
1 parent 9dda6ef commit 6a0dd79
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
LeftTabKey,
LEFT_TAB_PANEL_KEYS,
makeNiceAliasName,
PROJECT_CONFIGS,
UiConfig,
} from "@/wab/shared/ui-config-utils";
import { capitalizeFirst } from "@/wab/strs";
Expand Down Expand Up @@ -101,6 +102,19 @@ export function ContentEditorConfigModal(props: {
/>
</Form.Item>

<h3 className="mv-xlg">Project Configs</h3>
<Form.Item name={["projectConfigs"]} noStyle>
<PreferencesControl
label={"Can edit project configurations?"}
prefKeys={PROJECT_CONFIGS.map((t) => ({
value: t,
label: capitalizeFirst(t),
}))}
options={[true, false]}
optionLabel={(op) => (op ? "Enabled" : "Disabled")}
/>
</Form.Item>

<h3 className="mv-xlg">Left tabs</h3>
<Form.Item name={["leftTabs"]} noStyle>
<PreferencesControl
Expand Down
11 changes: 8 additions & 3 deletions platform/wab/src/wab/client/components/top-bar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
isReusableComponent,
} from "@/wab/components";
import { isCoreTeamEmail } from "@/wab/shared/devflag-utils";
import { canEditProjectConfig } from "@/wab/shared/ui-config-utils";
import { Menu, notification, Tooltip } from "antd";
import { observer } from "mobx-react-lite";
import React from "react";
Expand All @@ -49,11 +50,16 @@ function _TopBar({ preview }: TopBarProps) {
const isWhiteLabelUser = appCtx.isWhiteLabelUser();
const isObserver = appCtx.selfInfo?.isObserver;

const uiConfig = studioCtx.getCurrentUiConfig();

const menu = () => {
const builder = new MenuBuilder();
builder.genSection(undefined, (push) => {
builder.genSection(undefined, (push2) => {
if (studioCtx.canEditProject()) {
if (
studioCtx.canEditProject() &&
canEditProjectConfig(uiConfig, "rename")
) {
push2(
<Menu.Item
key="rename"
Expand Down Expand Up @@ -103,7 +109,7 @@ function _TopBar({ preview }: TopBarProps) {
);
}

if (!isWhiteLabelUser) {
if (canEditProjectConfig(uiConfig, "localization")) {
push2(
<Menu.Item
key="localization"
Expand Down Expand Up @@ -283,7 +289,6 @@ function _TopBar({ preview }: TopBarProps) {
};

const contextMenuProps = useContextMenu({ menu });
const uiConfig = studioCtx.getCurrentUiConfig();

const brand =
uiConfig.brand ??
Expand Down
17 changes: 17 additions & 0 deletions platform/wab/src/wab/shared/ui-config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export type LeftTabKey = (typeof LEFT_TAB_PANEL_KEYS)[number];
export const LEFT_TAB_BUTTON_KEYS = [...LEFT_TAB_PANEL_KEYS, "figma"] as const;
export type LeftTabButtonKey = (typeof LEFT_TAB_BUTTON_KEYS)[number];

export const PROJECT_CONFIGS = ["localization", "rename"] as const;

export type ProjectConfig = (typeof PROJECT_CONFIGS)[number];

export interface UiConfig {
styleSectionVisibilities?: Partial<StyleSectionVisibilities>;
canInsertBasics?: Record<InsertBasicAlias, boolean> | boolean;
Expand All @@ -136,6 +140,7 @@ export interface UiConfig {
pageTemplates?: TemplateSpec[];
insertableTemplates?: TemplateSpec[];
leftTabs?: Record<LeftTabButtonKey, "hidden" | "readable" | "writable">;
projectConfigs?: Record<ProjectConfig, boolean>;
brand?: {
logoImgSrc?: string;
logoHref?: string;
Expand Down Expand Up @@ -212,6 +217,7 @@ export function mergeUiConfigs(
leftTabs: mergeshallowObjs(configs.map((c) => c.leftTabs)),
pageTemplates: mergedFirst(configs.map((c) => c.pageTemplates)),
insertableTemplates: mergedFirst(configs.map((c) => c.insertableTemplates)),
projectConfigs: mergeshallowObjs(configs.map((c) => c.projectConfigs)),
// Deep merge `brand`
brand: merge({}, ...configs.map((c) => c.brand)),
};
Expand Down Expand Up @@ -346,3 +352,14 @@ const LEFT_TAB_CONTENT_CREATOR_DEFAULT: Record<
copilot: "hidden",
figma: "hidden",
};

export function canEditProjectConfig(
config: UiConfig,
projectConfig: ProjectConfig
) {
if (!config.projectConfigs) {
return true;
}

return config.projectConfigs[projectConfig] ?? true;
}

0 comments on commit 6a0dd79

Please sign in to comment.