Follow the tool's credential mode in the share dialog once it loads

The dialog read the mode once, so opening Share before the connections
loaded showed owner mode for a member-mode tool and ignored a forced
mode.
This commit is contained in:
arc53-machine committed 2026-09-29 15:12:41 +01:00
1 parent 875118ed20
commit 27495f0bc2
2 files changed
+22 -1

No files matched your search

@@ -477,6 +477,17 @@ describe('ShareToTeamModal credentials', () => {
expect(text()).toContain('settings.connectors.share.forced');
});
it('follows the mode once the connection loads after opening', async () => {
await render();
await render(credentials({ hasWrites: true, mode: 'member' }));
expect(toggle('member').getAttribute('aria-checked')).toBe('true');
// Member mode runs on each member's own account: nothing to confirm.
expect(body().querySelector('#share-confirm-writes')).toBeNull();
await render(credentials({ hasWrites: true, forcedMode: 'owner' }));
expect(toggle('owner').getAttribute('aria-checked')).toBe('true');
expect(toggle('member').disabled).toBe(true);
});
describe('access settings of a connected tool', () => {
const toolSettings = (values: Record<string, boolean> = {}) => ({
success: true,
+11 -1
View File
@@ -157,9 +157,19 @@ export default function ShareToTeamModal({
const [loadError, setLoadError] = useState(false);
const [actionError, setActionError] = useState<string | null>(null);
const savedCredentialMode =
credentials?.forcedMode ?? credentials?.mode ?? 'owner';
const [credentialMode, setCredentialMode] = useState<'owner' | 'member'>(
credentials?.forcedMode ?? credentials?.mode ?? 'owner',
savedCredentialMode,
);
// The caller may open the dialog before the tool's connection has loaded:
// follow the mode (or an admin's forced one) when it arrives or changes.
const [seenCredentialMode, setSeenCredentialMode] =
useState(savedCredentialMode);
if (savedCredentialMode !== seenCredentialMode) {
setSeenCredentialMode(savedCredentialMode);
setCredentialMode(savedCredentialMode);
}
const [writesConfirmed, setWritesConfirmed] = useState(false);
const needsWriteConfirm =
!!credentials && credentialMode === 'owner' && credentials.hasWrites;