diff --git a/README.md b/README.md index 68d9ef7..b774b43 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ const requests = Surix.requests; - `addTagsToEntity`: Add tags to an existing entity. - `removeTagsFromEntity`: Removes tags from an entity. - `getTags`: Gets all the entity tags in the project. +- `updateTag`: Updates the specified tag in an entity. - `project`: Fetches the current Surix project. - `getAppData`: Fetches app data stored by the app in the current project - `updateAppData`: Updates/adds app data to the current project @@ -168,6 +169,22 @@ service.request(requests.data.removeTagsFromEntity, args).then((updatedEntity) = **Note**: Tags that are not in the entity will be ignored. +### Updating a tag in an entity +```javascript +const args = { + tags: 'people', + update: { + name: 'persons' + } +}; + +surix.request(requests.data.updateTag, args).then(updatedTag => { + //Tag updated successfully +}).catch(error) => { + //Error +}); +``` + ### Get all tags in the project ```javascript service.request(requests.data.getTags).then((tags) => { diff --git a/build/dist/src/requests.d.ts b/build/dist/src/requests.d.ts index 37eea77..cb1b49f 100644 --- a/build/dist/src/requests.d.ts +++ b/build/dist/src/requests.d.ts @@ -7,6 +7,7 @@ export declare const requests: { addTagsToEntity: string; removeTagsFromEntity: string; getTags: string; + updateTag: string, getAppData: string; updateAppData: string; }; diff --git a/dist/client-service.js b/dist/client-service.js index 19d7b85..a15b277 100644 --- a/dist/client-service.js +++ b/dist/client-service.js @@ -234,6 +234,7 @@ exports.requests = { addTagsToEntity: 'data.addTagsToEntity', removeTagsFromEntity: 'data.removeTagsFromEntity', getTags: 'data.getTags', + updateTag: 'data.updateTag', getAppData: 'data.getAppData', updateAppData: 'data.updateAppData' }, diff --git a/src/requests.ts b/src/requests.ts index 2c70c36..4fa6356 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -7,6 +7,7 @@ export const requests = { addTagsToEntity: 'data.addTagsToEntity', removeTagsFromEntity: 'data.removeTagsFromEntity', getTags: 'data.getTags', + updateTag: 'data.updateTag', getAppData: 'data.getAppData', updateAppData: 'data.updateAppData' }, diff --git a/tests/service.test.tsx b/tests/service.test.tsx index 688b4eb..2c32088 100644 --- a/tests/service.test.tsx +++ b/tests/service.test.tsx @@ -1,4 +1,5 @@ import { Service, requests } from '..'; +import { request } from 'http'; jest.spyOn(global.window.parent , 'postMessage'); @@ -66,5 +67,21 @@ describe('Requests', async () => { expect(window.parent.postMessage).toHaveBeenCalled(); }); + test('Update Tag', async() => { + const args = { + tag: 'current tag name', + upadate: { + name: 'new tag name' + } + }; + surix.request(requests.data.updateTag, args).then(updatedTag => { + //Tag updated successfully + }).catch((error) => { + //Error + }); + + expect(window.parent.postMessage).toHaveBeenCalled(); + }); + }); }); \ No newline at end of file