mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
fix(cli): Revert the code to hide tips when showing trust dialog (#8946)
This commit is contained in:
@@ -754,7 +754,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
|||||||
const [showIdeRestartPrompt, setShowIdeRestartPrompt] = useState(false);
|
const [showIdeRestartPrompt, setShowIdeRestartPrompt] = useState(false);
|
||||||
|
|
||||||
const { isFolderTrustDialogOpen, handleFolderTrustSelect, isRestarting } =
|
const { isFolderTrustDialogOpen, handleFolderTrustSelect, isRestarting } =
|
||||||
useFolderTrust(settings, setIsTrustedFolder, refreshStatic);
|
useFolderTrust(settings, setIsTrustedFolder);
|
||||||
const { needsRestart: ideNeedsRestart } = useIdeTrustListener();
|
const { needsRestart: ideNeedsRestart } = useIdeTrustListener();
|
||||||
const isInitialMount = useRef(true);
|
const isInitialMount = useRef(true);
|
||||||
|
|
||||||
|
|||||||
@@ -18,18 +18,16 @@ interface AppHeaderProps {
|
|||||||
export const AppHeader = ({ version }: AppHeaderProps) => {
|
export const AppHeader = ({ version }: AppHeaderProps) => {
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
const { nightly, isFolderTrustDialogOpen } = useUIState();
|
const { nightly } = useUIState();
|
||||||
const showTips =
|
|
||||||
!isFolderTrustDialogOpen &&
|
|
||||||
!settings.merged.ui?.hideTips &&
|
|
||||||
!config.getScreenReader();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
{!(settings.merged.ui?.hideBanner || config.getScreenReader()) && (
|
{!(settings.merged.ui?.hideBanner || config.getScreenReader()) && (
|
||||||
<Header version={version} nightly={nightly} />
|
<Header version={version} nightly={nightly} />
|
||||||
)}
|
)}
|
||||||
{showTips && <Tips config={config} />}
|
{!(settings.merged.ui?.hideTips || config.getScreenReader()) && (
|
||||||
|
<Tips config={config} />
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ describe('useFolderTrust', () => {
|
|||||||
let loadTrustedFoldersSpy: vi.SpyInstance;
|
let loadTrustedFoldersSpy: vi.SpyInstance;
|
||||||
let isWorkspaceTrustedSpy: vi.SpyInstance;
|
let isWorkspaceTrustedSpy: vi.SpyInstance;
|
||||||
let onTrustChange: (isTrusted: boolean | undefined) => void;
|
let onTrustChange: (isTrusted: boolean | undefined) => void;
|
||||||
let refreshStatic: () => void;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockSettings = {
|
mockSettings = {
|
||||||
@@ -50,7 +49,6 @@ describe('useFolderTrust', () => {
|
|||||||
isWorkspaceTrustedSpy = vi.spyOn(trustedFolders, 'isWorkspaceTrusted');
|
isWorkspaceTrustedSpy = vi.spyOn(trustedFolders, 'isWorkspaceTrusted');
|
||||||
(process.cwd as vi.Mock).mockReturnValue('/test/path');
|
(process.cwd as vi.Mock).mockReturnValue('/test/path');
|
||||||
onTrustChange = vi.fn();
|
onTrustChange = vi.fn();
|
||||||
refreshStatic = vi.fn();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -60,7 +58,7 @@ describe('useFolderTrust', () => {
|
|||||||
it('should not open dialog when folder is already trusted', () => {
|
it('should not open dialog when folder is already trusted', () => {
|
||||||
isWorkspaceTrustedSpy.mockReturnValue(true);
|
isWorkspaceTrustedSpy.mockReturnValue(true);
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||||
expect(onTrustChange).toHaveBeenCalledWith(true);
|
expect(onTrustChange).toHaveBeenCalledWith(true);
|
||||||
@@ -69,7 +67,7 @@ describe('useFolderTrust', () => {
|
|||||||
it('should not open dialog when folder is already untrusted', () => {
|
it('should not open dialog when folder is already untrusted', () => {
|
||||||
isWorkspaceTrustedSpy.mockReturnValue(false);
|
isWorkspaceTrustedSpy.mockReturnValue(false);
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||||
expect(onTrustChange).toHaveBeenCalledWith(false);
|
expect(onTrustChange).toHaveBeenCalledWith(false);
|
||||||
@@ -78,7 +76,7 @@ describe('useFolderTrust', () => {
|
|||||||
it('should open dialog when folder trust is undefined', () => {
|
it('should open dialog when folder trust is undefined', () => {
|
||||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
||||||
expect(onTrustChange).toHaveBeenCalledWith(undefined);
|
expect(onTrustChange).toHaveBeenCalledWith(undefined);
|
||||||
@@ -89,7 +87,7 @@ describe('useFolderTrust', () => {
|
|||||||
.mockReturnValueOnce(undefined)
|
.mockReturnValueOnce(undefined)
|
||||||
.mockReturnValueOnce(true);
|
.mockReturnValueOnce(true);
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
|
|
||||||
isWorkspaceTrustedSpy.mockReturnValue(true);
|
isWorkspaceTrustedSpy.mockReturnValue(true);
|
||||||
@@ -111,7 +109,7 @@ describe('useFolderTrust', () => {
|
|||||||
.mockReturnValueOnce(undefined)
|
.mockReturnValueOnce(undefined)
|
||||||
.mockReturnValueOnce(true);
|
.mockReturnValueOnce(true);
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@@ -131,7 +129,7 @@ describe('useFolderTrust', () => {
|
|||||||
.mockReturnValueOnce(undefined)
|
.mockReturnValueOnce(undefined)
|
||||||
.mockReturnValueOnce(false);
|
.mockReturnValueOnce(false);
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@@ -150,7 +148,7 @@ describe('useFolderTrust', () => {
|
|||||||
it('should do nothing for default choice', () => {
|
it('should do nothing for default choice', () => {
|
||||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@@ -168,7 +166,7 @@ describe('useFolderTrust', () => {
|
|||||||
it('should set isRestarting to true when trust status changes from false to true', () => {
|
it('should set isRestarting to true when trust status changes from false to true', () => {
|
||||||
isWorkspaceTrustedSpy.mockReturnValueOnce(false).mockReturnValueOnce(true); // Initially untrusted, then trusted
|
isWorkspaceTrustedSpy.mockReturnValueOnce(false).mockReturnValueOnce(true); // Initially untrusted, then trusted
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@@ -184,7 +182,7 @@ describe('useFolderTrust', () => {
|
|||||||
.mockReturnValueOnce(undefined)
|
.mockReturnValueOnce(undefined)
|
||||||
.mockReturnValueOnce(true); // Initially undefined, then trust
|
.mockReturnValueOnce(true); // Initially undefined, then trust
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
useFolderTrust(mockSettings, onTrustChange),
|
||||||
);
|
);
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@@ -194,26 +192,4 @@ describe('useFolderTrust', () => {
|
|||||||
expect(result.current.isRestarting).toBe(false);
|
expect(result.current.isRestarting).toBe(false);
|
||||||
expect(result.current.isFolderTrustDialogOpen).toBe(false); // Dialog should close
|
expect(result.current.isFolderTrustDialogOpen).toBe(false); // Dialog should close
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call refreshStatic when dialog opens and closes', () => {
|
|
||||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
|
||||||
const { result } = renderHook(() =>
|
|
||||||
useFolderTrust(mockSettings, onTrustChange, refreshStatic),
|
|
||||||
);
|
|
||||||
|
|
||||||
// The hook runs, isFolderTrustDialogOpen becomes true, useEffect triggers.
|
|
||||||
// It's called once on mount, and once when the dialog state changes.
|
|
||||||
expect(refreshStatic).toHaveBeenCalledTimes(2);
|
|
||||||
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
|
||||||
|
|
||||||
// Now, simulate closing the dialog
|
|
||||||
isWorkspaceTrustedSpy.mockReturnValue(true); // So the state update works
|
|
||||||
act(() => {
|
|
||||||
result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER);
|
|
||||||
});
|
|
||||||
|
|
||||||
// The state isFolderTrustDialogOpen becomes false, useEffect triggers again
|
|
||||||
expect(refreshStatic).toHaveBeenCalledTimes(3);
|
|
||||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import * as process from 'node:process';
|
|||||||
export const useFolderTrust = (
|
export const useFolderTrust = (
|
||||||
settings: LoadedSettings,
|
settings: LoadedSettings,
|
||||||
onTrustChange: (isTrusted: boolean | undefined) => void,
|
onTrustChange: (isTrusted: boolean | undefined) => void,
|
||||||
refreshStatic: () => void,
|
|
||||||
) => {
|
) => {
|
||||||
const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
|
const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
|
||||||
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
|
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
|
||||||
@@ -32,12 +31,6 @@ export const useFolderTrust = (
|
|||||||
onTrustChange(trusted);
|
onTrustChange(trusted);
|
||||||
}, [folderTrust, onTrustChange, settings.merged]);
|
}, [folderTrust, onTrustChange, settings.merged]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// When the folder trust dialog is about to open/close, we need to force a refresh
|
|
||||||
// of the static content to ensure the Tips are hidden/shown correctly.
|
|
||||||
refreshStatic();
|
|
||||||
}, [isFolderTrustDialogOpen, refreshStatic]);
|
|
||||||
|
|
||||||
const handleFolderTrustSelect = useCallback(
|
const handleFolderTrustSelect = useCallback(
|
||||||
(choice: FolderTrustChoice) => {
|
(choice: FolderTrustChoice) => {
|
||||||
const trustedFolders = loadTrustedFolders();
|
const trustedFolders = loadTrustedFolders();
|
||||||
|
|||||||
Reference in New Issue
Block a user