Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-months-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tokens-studio/figma-plugin": patch
---

Improved recovery dialog button labels to be more explicit. The "Use remote" action (which discards local changes) is now the primary action with danger styling, while "Recover changes" (which keeps local changes) is the secondary cancel action. This makes it clearer which action is destructive.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe('pullTokensFactory', () => {
],
} as unknown as StartupMessage;

mockConfirm.mockResolvedValueOnce(true);
mockConfirm.mockResolvedValueOnce(false);

const fn = pullTokensFactory(
mockStore,
Expand All @@ -330,6 +330,61 @@ describe('pullTokensFactory', () => {
expect(state.tokenState.remoteData).toEqual({ metadata: null, themes: [], tokens: {} });
});

it('should show recovery dialog with correct button labels and danger variant', async () => {
const mockStore = createMockStore({
uiState: {
storageType: mockStorageType,
},
});

const mockParams = {
localTokenData: {
checkForChanges: true,
values: {
global: [
{
type: TokenTypes.COLOR,
name: 'colors.red',
value: '#ff0000',
$extensions: {
'studio.tokens': {
id: 'mock-uuid',
},
},
},
],
},
},
localApiProviders: [
{ ...mockStorageType, secret: 'secret' },
],
} as unknown as StartupMessage;

mockConfirm.mockResolvedValueOnce(false);

const fn = pullTokensFactory(
mockStore,
mockStore.dispatch,
{},
mockParams,
mockUseConfirm,
mockUseRemoteTokens,
);

mockFetchBranches.mockResolvedValueOnce(['main']);

await fn();

// Verify the confirm dialog was called with correct parameters
expect(mockConfirm).toHaveBeenCalledWith({
text: 'Recover local changes?',
description: 'You have local changes unsaved to the remote storage.',
confirmAction: 'Use remote',
cancelAction: 'Recover changes',
variant: 'danger',
});
});

it('should go to start tab if the localTokenData is missing somehow', async () => {
const mockStore = createMockStore({
uiState: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ export function pullTokensFactory(
const activeTheme = typeof params.activeTheme === 'string' ? { [INTERNAL_THEMES_NO_GROUP]: params.activeTheme } : params.activeTheme;

const askUserIfRecoverLocalChanges = async () => {
const shouldRecoverLocalChanges = await useConfirmResult.confirm({
const shouldUseRemote = await useConfirmResult.confirm({
text: 'Recover local changes?',
description: 'You have local changes unsaved to the remote storage.',
confirmAction: 'Use remote',
cancelAction: 'Recover changes',
variant: 'danger',
});
return shouldRecoverLocalChanges;
// Return the opposite: if user confirms "Use remote", we should NOT recover local changes
return !shouldUseRemote;
};

const getApiCredentials = async (shouldPull: boolean, isRemoteStorage: boolean) => {
Expand Down