/* Copyright 2026 Marimo. All rights reserved. */ import { useAtomValue } from "jotai"; import { get } from "lodash-es"; import { FolderCog2 } from "lucide-react"; import type { FieldPath } from "react-hook-form"; import { Tooltip } from "@/components/ui/tooltip"; import { configOverridesAtom, useUserConfig } from "@/core/config/config"; import type { UserConfig } from "@/core/config/config-schema"; import { Kbd } from "../ui/kbd"; /** * Hook to determine if a user config value is overridden by project config. * Returns { isOverridden, currentValue, overriddenValue } */ function useIsConfigOverridden( userConfig: UserConfig, name: FieldPath, ): { isOverridden: boolean; currentValue: unknown; overriddenValue: unknown; } { const currentValue = get(userConfig, name); const overrides = useAtomValue(configOverridesAtom); const overriddenValue = get(overrides as UserConfig, name); const isOverridden = overriddenValue != null && currentValue !== overriddenValue; return { isOverridden, currentValue, overriddenValue }; } /** * Wraps a component and shows a tooltip if the user config is overridden by the * project config. */ export const DisableIfOverridden = ({ name, children, }: { name: FieldPath; children: React.ReactNode; }) => { const [userConfig] = useUserConfig(); const { isOverridden } = useIsConfigOverridden(userConfig, name); return isOverridden ? (

This setting is overridden by the{" "} pyproject.toml config.

To change it, edit the project config{" "} pyproject.toml directly.

} >
{children}
) : ( children ); }; export const IsOverridden = ({ userConfig, name, }: { userConfig: UserConfig; name: FieldPath; }) => { const { isOverridden, currentValue, overriddenValue } = useIsConfigOverridden( userConfig, name, ); if (!isOverridden) { return null; } return ( This setting is overridden by{" "} pyproject.toml.
Edit the pyproject.toml file directly to change this setting.
User value: {String(currentValue)}
Project value: {String(overriddenValue)} } > Overridden by pyproject.toml [{String(overriddenValue)}]
); };