Skip to content

Commit 3db28e6

Browse files
authored
fix editprohibited evaluation (#3677)
* fix condition * fix types
1 parent ad20172 commit 3db28e6

File tree

6 files changed

+71
-11
lines changed

6 files changed

+71
-11
lines changed

.changeset/silly-apricots-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tokens-studio/figma-plugin": patch
3+
---
4+
5+
Fixed an issue that caused the plugin to stay in readonly mode

packages/tokens-studio-for-figma/src/app/store/providers/ado/ado.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useDispatch, useSelector } from 'react-redux';
2-
import React from 'react';
2+
import React, { useEffect } from 'react';
33
import compact from 'just-compact';
44
import { Dispatch } from '@/app/store';
55
import useConfirm from '@/app/hooks/useConfirm';
@@ -45,7 +45,7 @@ export const useADO = () => {
4545
// This ensures multi-file is enabled even if the license was validated after this callback was created
4646
if (isProUser) storageClient.enableMultiFile();
4747
return storageClient;
48-
}, []); // Removed isProUser from dependencies to always use current value
48+
}, [isProUser]);
4949

5050
const askUserIfPull = React.useCallback(async () => {
5151
const confirmResult = await confirm({
@@ -139,9 +139,19 @@ export const useADO = () => {
139139

140140
const checkAndSetAccess = React.useCallback(async (context: AdoCredentials) => {
141141
const storage = storageClientFactory(context);
142+
if (isProUser) {
143+
storage.enableMultiFile();
144+
}
142145
const hasWriteAccess = await storage.canWrite();
143146
dispatch.tokenState.setEditProhibited(!hasWriteAccess);
144-
}, [dispatch, storageClientFactory]);
147+
}, [dispatch, storageClientFactory, isProUser]);
148+
149+
// Re-check access when isProUser changes from false to true (license validation during startup)
150+
useEffect(() => {
151+
if (isProUser && localApiState && localApiState.id && localApiState.provider === 'ado') {
152+
checkAndSetAccess(localApiState as AdoCredentials);
153+
}
154+
}, [isProUser, localApiState, checkAndSetAccess]);
145155

146156
const pullTokensFromADO = React.useCallback(async (context: AdoCredentials): Promise<RemoteResponseData | null> => {
147157
const storage = storageClientFactory(context);

packages/tokens-studio-for-figma/src/app/store/providers/bitbucket/bitbucket.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useDispatch, useSelector } from 'react-redux';
2-
import { useCallback, useMemo } from 'react';
2+
import { useCallback, useMemo, useEffect } from 'react';
33
import compact from 'just-compact';
44
import { Dispatch } from '@/app/store';
55
import useConfirm from '@/app/hooks/useConfirm';
@@ -56,7 +56,7 @@ export function useBitbucket() {
5656
if (isProUser) storageClient.enableMultiFile();
5757
return storageClient;
5858
},
59-
[], // Removed isProUser from dependencies to always use current value
59+
[isProUser],
6060
);
6161

6262
const askUserIfPull = useCallback(async () => {
@@ -152,6 +152,9 @@ export function useBitbucket() {
152152
context, owner, repo,
153153
}: { context: BitbucketCredentials; owner: string; repo: string }) => {
154154
const storage = storageClientFactory(context, owner, repo);
155+
if (isProUser) {
156+
storage.enableMultiFile();
157+
}
155158
try {
156159
const hasWriteAccess = await storage.canWrite();
157160
dispatch.tokenState.setEditProhibited(!hasWriteAccess);
@@ -162,9 +165,21 @@ export function useBitbucket() {
162165
dispatch.tokenState.setEditProhibited(true);
163166
}
164167
},
165-
[dispatch, storageClientFactory],
168+
[dispatch, storageClientFactory, isProUser],
166169
);
167170

171+
// Re-check access when isProUser changes from false to true (license validation during startup)
172+
useEffect(() => {
173+
if (isProUser && localApiState && 'id' in localApiState && localApiState.id && localApiState.provider === 'bitbucket') {
174+
const [owner, repo] = localApiState.id.split('/');
175+
checkAndSetAccess({
176+
context: localApiState as BitbucketCredentials,
177+
owner,
178+
repo,
179+
});
180+
}
181+
}, [isProUser, localApiState, checkAndSetAccess]);
182+
168183
const pullTokensFromBitbucket = useCallback(
169184
async (context: BitbucketCredentials): Promise<RemoteResponseData | null> => {
170185
const storage = storageClientFactory(context);

packages/tokens-studio-for-figma/src/app/store/providers/file.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function useFile() {
1414
// This ensures multi-file is enabled even if the license was validated after this callback was created
1515
if (isProUser) storageClient.enableMultiFile();
1616
return storageClient;
17-
}, []); // Removed isProUser from dependencies to always use current value
17+
}, [isProUser]);
1818

1919
const readTokensFromFileOrDirectory = useCallback(async (files: FileList): Promise<RemoteResponseData | null> => {
2020
const storage = storageClientFactory(files);

packages/tokens-studio-for-figma/src/app/store/providers/github/github.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useDispatch, useSelector } from 'react-redux';
2-
import { useCallback, useMemo } from 'react';
2+
import { useCallback, useMemo, useEffect } from 'react';
33
import compact from 'just-compact';
44
import { Dispatch } from '@/app/store';
55
import useConfirm from '@/app/hooks/useConfirm';
@@ -50,7 +50,7 @@ export function useGitHub() {
5050
// This ensures multi-file is enabled even if the license was validated after this callback was created
5151
if (isProUser) storageClient.enableMultiFile();
5252
return storageClient;
53-
}, []); // Removed isProUser from dependencies to always use current value
53+
}, [isProUser]);
5454

5555
const askUserIfPull = useCallback(async () => {
5656
const confirmResult = await confirm({
@@ -171,9 +171,27 @@ export function useGitHub() {
171171
context, owner, repo,
172172
}: { context: GithubCredentials; owner: string; repo: string }) => {
173173
const storage = storageClientFactory(context, owner, repo);
174+
175+
// Enable multi-file if user is pro, even if storage was created before license validation
176+
if (isProUser) {
177+
storage.enableMultiFile();
178+
}
179+
174180
const hasWriteAccess = await storage.canWrite();
175181
dispatch.tokenState.setEditProhibited(!hasWriteAccess);
176-
}, [dispatch, storageClientFactory]);
182+
}, [dispatch, storageClientFactory, isProUser]);
183+
184+
// Re-check access when isProUser changes from false to true (license validation during startup)
185+
useEffect(() => {
186+
if (isProUser && localApiState && 'id' in localApiState && localApiState.id && localApiState.provider === 'github') {
187+
const [owner, repo] = localApiState.id.split('/');
188+
checkAndSetAccess({
189+
context: localApiState as GithubCredentials,
190+
owner,
191+
repo,
192+
});
193+
}
194+
}, [isProUser, localApiState, checkAndSetAccess]);
177195

178196
const pullTokensFromGitHub = useCallback(async (context: GithubCredentials): Promise<RemoteResponseData | null> => {
179197
const storage = storageClientFactory(context);

packages/tokens-studio-for-figma/src/app/store/providers/gitlab/gitlab.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useDispatch, useSelector } from 'react-redux';
2-
import { useCallback, useMemo } from 'react';
2+
import { useCallback, useMemo, useEffect } from 'react';
33
import compact from 'just-compact';
44
import { Dispatch } from '@/app/store';
55
import useConfirm from '@/app/hooks/useConfirm';
@@ -153,10 +153,22 @@ export function useGitLab() {
153153
context,
154154
}: { context: GitlabCredentials }) => {
155155
const storage = await storageClientFactory(context, isProUser);
156+
if (isProUser) {
157+
storage.enableMultiFile();
158+
}
156159
const hasWriteAccess = await storage.canWrite();
157160
dispatch.tokenState.setEditProhibited(!hasWriteAccess);
158161
}, [dispatch, storageClientFactory, isProUser]);
159162

163+
// Re-check access when isProUser changes from false to true (license validation during startup)
164+
useEffect(() => {
165+
if (isProUser && localApiState && localApiState.id && localApiState.provider === 'gitlab') {
166+
checkAndSetAccess({
167+
context: localApiState as GitlabCredentials,
168+
});
169+
}
170+
}, [isProUser, localApiState, checkAndSetAccess]);
171+
160172
const pullTokensFromGitLab = useCallback(async (context: GitlabCredentials): Promise<RemoteResponseData | null> => {
161173
const storage = await storageClientFactory(context, isProUser);
162174
await checkAndSetAccess({

0 commit comments

Comments
 (0)