Skip to content

update metadata with tokenSetsData in useChangedState #3357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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/thick-jokes-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tokens-studio/figma-plugin": patch
---

Fixes an issue where pulling from Tokens Studio would display a confusing metadata change, even when no actual changes took place.
28 changes: 24 additions & 4 deletions packages/tokens-studio-for-figma/src/app/components/PullDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useTranslation } from 'react-i18next';
import {
Expand All @@ -7,14 +7,16 @@ import {
import { storageTypeSelector } from '@/selectors';
import usePullDialog from '../hooks/usePullDialog';
import Modal from './Modal';

import { useChangedState } from '@/hooks/useChangedState';
import { transformProviderName } from '@/utils/transformProviderName';
import ChangedStateList from './ChangedStateList';

function PullDialog() {
const { onConfirm, onCancel, pullDialogMode } = usePullDialog();
const {
onConfirm, onCancel, pullDialogMode, closePullDialog,
} = usePullDialog();
const storageType = useSelector(storageTypeSelector);

const { changedPullState } = useChangedState();
const { t } = useTranslation(['sync']);

const handleOverrideClick = React.useCallback(() => {
Expand All @@ -25,8 +27,26 @@ function PullDialog() {
onCancel();
}, [onCancel]);

// Check if there are any changes to display
const hasTokenChanges = Object.entries(changedPullState.tokens).length > 0;
const hasThemeChanges = changedPullState.themes.length > 0;
const hasMetadataChanges = changedPullState.metadata?.tokenSetOrder
&& Object.entries(changedPullState.metadata.tokenSetOrder).length > 0;
const hasChanges = hasTokenChanges || hasThemeChanges || hasMetadataChanges;

// Close the dialog if there are no changes to display
useEffect(() => {
if (pullDialogMode === 'initial' && !hasChanges) {
closePullDialog();
}
}, [pullDialogMode, hasChanges, closePullDialog]);

switch (pullDialogMode) {
case 'initial': {
if (!hasChanges) {
return null;
}

return (
<Modal
title={t('pullFrom', { provider: transformProviderName(storageType.provider) })}
Expand Down
10 changes: 8 additions & 2 deletions packages/tokens-studio-for-figma/src/hooks/useChangedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export function useChangedState() {
return findDifferentState(remoteData, {
tokens,
themes,
metadata: storageType.provider !== StorageProviderType.LOCAL ? { tokenSetOrder } : {},
metadata: storageType.provider !== StorageProviderType.LOCAL ? {
tokenSetsData: remoteData.metadata?.tokenSetsData || {},
tokenSetOrder,
} : {},
});
}, [remoteData, tokens, themes, storageType]);

Expand All @@ -36,7 +39,10 @@ export function useChangedState() {
{
tokens,
themes,
metadata: storageType.provider !== StorageProviderType.LOCAL ? { tokenSetOrder } : {},
metadata: storageType.provider !== StorageProviderType.LOCAL ? {
tokenSetsData: remoteData.metadata?.tokenSetsData || {},
tokenSetOrder,
} : {},
},
remoteData,
);
Expand Down
Loading