Skip to content
Closed
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
28 changes: 24 additions & 4 deletions src/main/utils/nodeTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,31 @@ function shouldIncludeNode(
return false;
}
if (
(settings.ignoreHiddenLayers ||
typeof settings.ignoreHiddenLayers === "undefined") &&
!node.visible
settings.ignoreHiddenLayers ||
typeof settings.ignoreHiddenLayers === "undefined"
) {
return false;
if (!node.visible) {
return false;
}
if (settings.ignoreHiddenLayersIncludingChildren) {
let isParentHidden = false;
let parent = node.parent;
try {
while (parent) {
if ("visible" in parent && !(parent as SceneNode).visible) {
console.log(parent, "PARENT HIDDEN");
isParentHidden = true;
break;
}
parent = parent.parent;
}
if (isParentHidden) {
return false;
}
} catch (error) {
console.error("Error checking parent visibility:", error);
}
}
}
if (
settings.ignoreTextLayers &&
Expand Down
2 changes: 2 additions & 0 deletions src/main/utils/settingsTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const setPluginData = async (data: Partial<TolgeeConfig>) => {
apiKey,
apiUrl,
ignoreHiddenLayers,
ignoreHiddenLayersIncludingChildren,
ignoreNumbers,
ignorePrefix,
ignoreTextLayers,
Expand All @@ -92,6 +93,7 @@ export const setPluginData = async (data: Partial<TolgeeConfig>) => {
apiUrl,
documentInfo: true,
ignoreHiddenLayers,
ignoreHiddenLayersIncludingChildren,
ignoreNumbers,
ignorePrefix,
ignoreTextLayers,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export type GlobalSettings = {
*/
keyFormat?: string;
ignoreHiddenLayers?: boolean;
ignoreHiddenLayersIncludingChildren?: boolean;
ignoreTextLayers?: boolean;
variableCasing?:
| "snake_case"
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/ActionsBottom/ActionsBottom.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
flex-direction: column;
align-items: flex-end;
background-color: var(--figma-color-bg);
z-index: 1;
z-index: 2;
}

.actions {
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/InfoTooltip/InfoTooltip.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
align-items: center;
justify-content: center;
cursor: pointer;
z-index: 2;
color: var(--figma-color-text-primary);
}
1 change: 1 addition & 0 deletions src/ui/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
--figma-color-teal-bg: rgb(53, 196, 176, 0.16);
--figma-color-red: rgb(255, 46, 83);
--figma-color-red-bg: rgb(255, 46, 83, 0.16);
--figma-color-text-primary: #ffffff;
}
}

Expand Down
23 changes: 11 additions & 12 deletions src/ui/views/Index/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
node.ns = value;
};

const editorMode = useEditorMode();

Check warning on line 91 in src/ui/views/Index/ListItem.tsx

View workflow job for this annotation

GitHub Actions / Static check 🪲

'editorMode' is assigned a value but never used

return (
<NodeRow
Expand Down Expand Up @@ -123,18 +123,17 @@
onClick={() => handleConnect(node)}
className={styles.connectButton}
>
{editorMode.data !== "dev" &&
(node.connected ? (
<InsertLink width={16} height={16} />
) : (
<InsertLink
width={16}
height={16}
style={{
color: "var(--figma-color-text-secondary)",
}}
/>
))}
{node.connected ? (
<InsertLink width={16} height={16} />
) : (
<InsertLink
width={16}
height={16}
style={{
color: "var(--figma-color-text-secondary)",
}}
/>
)}
</div>
<KeyOptionsButton node={{ ...node, key: keyName ?? node.key }} />
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/ui/views/Pull/Pull.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const Pull: FunctionalComponent<Props> = ({ lang }) => {
} catch (e) {
if (e === "invalid_project_api_key") {
setError("Invalid project API key");
} else if (e === "too_many_uploaded_images") {
setError(
"Too many uploaded images. Disable update screenshots in settings."
);
} else {
setError(`Cannot get translation data. ${e}`);
}
Expand Down
112 changes: 68 additions & 44 deletions src/ui/views/Push/Push.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const Push: FunctionalComponent = () => {
const [changes, setChanges] = useState<KeyChanges>();
const selectedNodes = useConnectedNodes({ ignoreSelection: false });
const tolgeeConfig = useGlobalState((c) => c.config);
const [screenshotCount, setScreenshotCount] = useState(0);

const nodes = selectedNodes.data?.items ?? [];

Expand Down Expand Up @@ -100,6 +101,10 @@ export const Push: FunctionalComponent = () => {
computeDiff();
}, [nodes.length]);

const totalScreenshotCount = useMemo(() => {
return changes?.screenshots.length || 0;
}, [changes]);

const setNodesDataMutation = useSetNodesDataMutation();

const loadingStatus =
Expand All @@ -112,11 +117,6 @@ export const Push: FunctionalComponent = () => {
method: "post",
});

const addNewTranslations = useApiMutation({
url: "/v2/projects/keys/import",
method: "post",
});

const addTagsToKeys = useApiMutation({
url: "/v2/projects/tag-complex",
method: "put",
Expand Down Expand Up @@ -231,7 +231,7 @@ export const Push: FunctionalComponent = () => {
translations: {
[language]: {
text: item.newValue,
resolution: "OVERRIDE",
resolution: item.oldValue ? "OVERRIDE" : "NEW",
},
},
});
Expand All @@ -256,44 +256,63 @@ export const Push: FunctionalComponent = () => {
},
});

// Add tags to keys
if (
(tolgeeConfig?.addTags ?? false) &&
tolgeeConfig?.tags &&
tolgeeConfig.tags.length > 0
) {
await addTagsToKeys.mutateAsync({
content: {
"application/json": {
tagFiltered: tolgeeConfig?.tags ?? [],
filterKeys: [
...changes.newKeys,
...changes.unchangedKeys,
...changes.changedKeys,
].map((k) => ({
name: k.key,
namespace: k.ns || undefined,
})),
try {
// Add tags to keys
if (
(tolgeeConfig?.addTags ?? false) &&
tolgeeConfig?.tags &&
tolgeeConfig.tags.length > 0
) {
await addTagsToKeys.mutateAsync({
content: {
"application/json": {
tagFiltered: tolgeeConfig?.tags ?? [],
filterKeys: [
...changes.newKeys,
...changes.unchangedKeys,
...changes.changedKeys,
].map((k) => ({
name: k.key,
namespace: k.ns || undefined,
})),
},
},
},
});
});
}
} catch (e) {
setErrorMessage(
`Error adding tags. ${e}. Translations were still updated.`
);
}

if (tolgeeConfig?.updateScreenshots ?? true) {
for (const screenshot of changes.screenshots.values()) {
const relatedKeys = screenshot.keys
.map((data) => ({
keyName: data.key,
namespace: data.ns || undefined,
}))
.slice(0, 100);
await bigMeta.mutateAsync({
content: {
"application/json": {
relatedKeysInOrder: relatedKeys,
try {
const relatedKeys = screenshot.keys
.map((data) => ({
keyName: data.key,
namespace: data.ns || undefined,
}))
.slice(0, 100);
await bigMeta.mutateAsync({
content: {
"application/json": {
relatedKeysInOrder: relatedKeys,
},
},
},
});
});
setScreenshotCount(screenshotCount + 1);
} catch (e) {
if (e === "too_many_uploaded_images") {
setErrorMessage(
"Too many uploaded images. Disable update screenshots in settings. Translations were still updated."
);
} else {
setErrorMessage(
`Error updating screenshots. ${e}. Translations were still updated.`
);
}
}
}
}

Expand All @@ -303,8 +322,14 @@ export const Push: FunctionalComponent = () => {
setError(true);
if (e === "invalid_project_api_key") {
setErrorMessage("Invalid project API key");
} else if (e === "too_many_uploaded_images") {
setErrorMessage(
"Too many uploaded images. Disable update screenshots in settings."
);
} else if (e === "import_keys_error") {
setErrorMessage("Error importing keys. Please try again.");
} else {
setErrorMessage(`Cannot get translation data. ${e}`);
setErrorMessage(`Cannot push translations. ${e}`);
}
console.error(e);
} finally {
Expand All @@ -327,8 +352,6 @@ export const Push: FunctionalComponent = () => {
? changes.changedKeys.length + changes.newKeys.length
: 0;

const screenshotCount = changes?.screenshots.length || 0;

const noChanges = changesSize === 0;

return (
Expand Down Expand Up @@ -373,7 +396,7 @@ export const Push: FunctionalComponent = () => {
</Fragment>
) : (
<Fragment>
{screenshotCount !== 0 && (
{totalScreenshotCount !== 0 && (
<Fragment>
<Checkbox
data-cy="push_upload_screenshots_checkbox"
Expand All @@ -382,7 +405,7 @@ export const Push: FunctionalComponent = () => {
setUploadScreenshots(Boolean(e.currentTarget.checked))
}
>
<Text>Upload {screenshotCount} screenshot(s)</Text>
<Text>Upload {totalScreenshotCount} screenshot(s)</Text>
</Checkbox>
<VerticalSpace space="medium" />
</Fragment>
Expand All @@ -397,7 +420,8 @@ export const Push: FunctionalComponent = () => {
>
Cancel
</Button>
{noChanges && (screenshotCount === 0 || !uploadScreenshots) ? (
{noChanges &&
(totalScreenshotCount === 0 || !uploadScreenshots) ? (
<Button
data-cy="push_finish_button"
onClick={handleConnectOnly}
Expand Down
5 changes: 5 additions & 0 deletions src/ui/views/Settings/StringsEditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@
pointer-events: none;
opacity: 0.5;
}
@media (prefers-color-scheme: dark) {
.strings-editor .cm-placeholder {
color: var(--figma-color-text-primary) !important;
}
}
Loading