Skip to content

Commit 7335902

Browse files
david-vaclavekdavid-vaclavek
andauthored
LOC-1114 - Figma Fixes and Improvements (#22)
* ✨ feat(Import): add upload status endpoint * ✨ feat(Key): add deprecate endpoint * 🐛 fix:(screenshots): fix `removeMetadata` data type * 🐛 fix(screenshots): fix `addMetadata` and `removeMetadata` params casing * ✨ feat(`listKeys`): add support for `metadata` parameter * 🚨 lint: fix --------- Co-authored-by: david-vaclavek <david@localazy.com>
1 parent cf94fbe commit 7335902

File tree

9 files changed

+112
-2
lines changed

9 files changed

+112
-2
lines changed

src/api/methods/api-import.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ImportJsonRequest } from '@/types/import-json-request';
99
import { Project } from '@/types/project';
1010
import { delay } from '@/utils/delay';
1111
import { JsonUtils } from '@/utils/json-utils';
12+
import { ImportProgressRequest } from '@/types/import-progress-request';
13+
import { UploadSessionStatus } from '@/types/upload-session-status';
1214

1315
export class ApiImport extends ApiBase {
1416
/**
@@ -39,6 +41,21 @@ export class ApiImport extends ApiBase {
3941
return this.getImportedFile(project, data, result);
4042
}
4143

44+
/**
45+
* Get progress of the import session.
46+
*
47+
* @param request Import session progress request.
48+
* @param config Request config.
49+
*
50+
* Not available in the Localazy API Docs yet.
51+
*/
52+
public async getProgress(request: ImportProgressRequest, config?: RequestConfig): Promise<UploadSessionStatus> {
53+
const { project, importBatch }: ImportProgressRequest = request;
54+
const projectId: string = ApiBase.getId(project, 'project');
55+
56+
return (await this.api.client.get(`/projects/${projectId}/import/${importBatch}`, config)) as UploadSessionStatus;
57+
}
58+
4259
protected async getImportedFile(
4360
project: string | Project,
4461
data: ImportData,

src/api/methods/api-keys.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ApiBase } from '@/api/methods/api-base';
22
import { KeyDeleteRequest } from '@/types/key-delete-request';
3+
import { KeyDeprecateRequest } from '@/types/key-deprecate-request';
34
import { KeyUpdateRequest } from '@/types/key-update-request';
45
import { RequestConfig } from '@/types/request-config';
56

@@ -35,4 +36,29 @@ export class ApiKeys extends ApiBase {
3536

3637
await this.api.client.delete(`/projects/${projectId}/keys/${keyId}`, config);
3738
}
39+
40+
/**
41+
* Deprecate keys.
42+
*
43+
* @param request Key deprecate request config.
44+
* @param config Request config.
45+
*/
46+
public async deprecate(request: KeyDeprecateRequest, config?: RequestConfig): Promise<void> {
47+
const { project, phrases }: KeyDeprecateRequest = request;
48+
49+
const localPhrases: string[] = phrases.map((phrase) => {
50+
if (typeof phrase === 'object' && 'id' in phrase) {
51+
return phrase.id;
52+
}
53+
54+
if (typeof phrase === 'string') {
55+
return phrase;
56+
}
57+
58+
return phrase;
59+
});
60+
const projectId: string = ApiBase.getId(project, 'project');
61+
62+
await this.api.client.post(`/projects/${projectId}/keys/deprecate`, { phrases: localPhrases }, config);
63+
}
3864
}

src/enums/upload-status.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum UploadStatus {
2+
NOT_FOUND = 'not_found',
3+
SCHEDULED = 'scheduled',
4+
IN_PROGRESS = 'in_progress',
5+
DONE = 'done',
6+
INVALID_ID = 'invalid_id',
7+
ERROR = 'error',
8+
}

src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export * from '@/api/methods/api-webhooks';
2727
export * from '@/enums/i18n-deprecate';
2828
export * from '@/enums/project-tone';
2929
export * from '@/enums/project-type';
30+
export * from '@/enums/upload-status';
3031
export * from '@/enums/user-role';
3132
export * from '@/enums/webhook-event';
3233
export * from '@/http/fetch-http-adapter';
@@ -57,8 +58,10 @@ export * from '@/types/import-data';
5758
export * from '@/types/import-file-options';
5859
export * from '@/types/import-i18n-options';
5960
export * from '@/types/import-json-request';
61+
export * from '@/types/import-progress-request';
6062
export * from '@/types/json';
6163
export * from '@/types/key-delete-request';
64+
export * from '@/types/key-deprecate-request';
6265
export * from '@/types/key-update-request';
6366
export * from '@/types/key-value';
6467
export * from '@/types/key';
@@ -79,6 +82,7 @@ export * from '@/types/screenshot-update-request';
7982
export * from '@/types/screenshot';
8083
export * from '@/types/screenshots-list-request';
8184
export * from '@/types/screenshots-list-tags-request';
85+
export * from '@/types/upload-session-status';
8286
export * from '@/types/webhook';
8387
export * from '@/types/webhooks-get-secret-request';
8488
export * from '@/types/webhooks-list-request';

src/types/file-list-keys-request.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ export type FileListKeysRequest = {
3737
* Receive additional info such as translation note, whether it's hidden etc.
3838
*/
3939
extra_info?: boolean;
40+
41+
/**
42+
* Receive also metadata for the key.
43+
*/
44+
metadata?: boolean;
4045
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Project } from '@/types/project';
2+
3+
export type ImportProgressRequest = {
4+
/**
5+
* Project object or Project ID.
6+
*/
7+
project: Project | string;
8+
9+
/**
10+
* Import session identifier.
11+
*/
12+
importBatch: string;
13+
};

src/types/key-deprecate-request.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Project } from '@/types/project';
2+
import { Key } from '@/types/key';
3+
4+
export type KeyDeprecateRequest = {
5+
/**
6+
* Project object or Project ID.
7+
*/
8+
project: Project | string;
9+
10+
/**
11+
* List of keys identifiers to deprecate.
12+
*/
13+
phrases: Key[] | Pick<Key, 'id'>[] | string[];
14+
};

src/types/screenshot-update-request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export type ScreenshotUpdateRequest = {
4545
/**
4646
* Add or remove metadata. Adding has priority over removing. Cannot be used together with metadata.
4747
*/
48-
addMetaData?: ScreenshotMetadata;
49-
removeMetaData?: ScreenshotMetadata;
48+
addMetadata?: ScreenshotMetadata;
49+
removeMetadata?: string[];
5050

5151
/**
5252
* Replace metadata with the current value. Cannot be used together with addMetadata and/or removeMetadata.

src/types/upload-session-status.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { UploadStatus } from '@/enums/upload-status';
2+
3+
export type UploadSessionStatus = {
4+
/**
5+
* Possible status of the upload session.
6+
*/
7+
status: UploadStatus;
8+
9+
/**
10+
* Number of keys added in the upload session.
11+
*/
12+
added?: number;
13+
14+
/**
15+
* Number of keys updated in the upload session.
16+
*/
17+
updated?: number;
18+
19+
/**
20+
* Number of keys deprecated in the upload session.
21+
*/
22+
deprecated?: number;
23+
};

0 commit comments

Comments
 (0)