From 26a3150fd87849191dac6ce20dc3417499c82a4a Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Mon, 13 Sep 2021 15:56:18 +0530 Subject: [PATCH] feat: Adds the ability to edit and delete custom attributes (#2982) * feat: Adds the ability to edit and delete custom attributes * Review fixes * Minor fixes * Adds specs * Minor fixes * Update settings.routes.js Co-authored-by: Muhsin Keloth --- app/javascript/dashboard/helper/commons.js | 7 + .../dashboard/helper/specs/commons.spec.js | 12 +- .../i18n/locale/en/attributesMgmt.json | 24 ++- .../settings/attributes/AddAttribute.vue | 45 +---- .../settings/attributes/CustomAttribute.vue | 78 +++++++++ .../settings/attributes/EditAttribute.vue | 162 ++++++++++++++++++ .../settings/attributes/constants.js | 37 ++++ .../dashboard/store/modules/attributes.js | 2 + 8 files changed, 325 insertions(+), 42 deletions(-) create mode 100644 app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue create mode 100644 app/javascript/dashboard/routes/dashboard/settings/attributes/constants.js diff --git a/app/javascript/dashboard/helper/commons.js b/app/javascript/dashboard/helper/commons.js index 40ff06c83..85e997802 100644 --- a/app/javascript/dashboard/helper/commons.js +++ b/app/javascript/dashboard/helper/commons.js @@ -61,3 +61,10 @@ export const createPendingMessage = data => { return pendingMessage; }; + +export const convertToSlug = text => { + return text + .toLowerCase() + .replace(/[^\w ]+/g, '') + .replace(/ +/g, '_'); +}; diff --git a/app/javascript/dashboard/helper/specs/commons.spec.js b/app/javascript/dashboard/helper/specs/commons.spec.js index 2df5e36b5..379e97e86 100644 --- a/app/javascript/dashboard/helper/specs/commons.spec.js +++ b/app/javascript/dashboard/helper/specs/commons.spec.js @@ -1,4 +1,8 @@ -import { getTypingUsersText, createPendingMessage } from '../commons'; +import { + getTypingUsersText, + createPendingMessage, + convertToSlug, +} from '../commons'; describe('#getTypingUsersText', () => { it('returns the correct text is there is only one typing user', () => { @@ -83,3 +87,9 @@ describe('#createPendingMessage', () => { expect(pending.attachments.length).toBe(1); }); }); + +describe('convertToSlug', () => { + it('should convert to slug', () => { + expect(convertToSlug('Test@%^&*(){}>.!@`~_ ing')).toBe('test__ing'); + }); +}); diff --git a/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json b/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json index a3bbd1254..d7bcb597a 100644 --- a/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json +++ b/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json @@ -35,7 +35,29 @@ }, "API": { "SUCCESS_MESSAGE": "Attribute added successfully", - "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" + "ERROR_MESSAGE": "Could not able to create an attribute, Please try again later" + } + }, + "DELETE": { + "BUTTON_TEXT": "Delete", + "API": { + "SUCCESS_MESSAGE": "Attribute deleted successfully.", + "ERROR_MESSAGE": "Couldn't delete the attribute. Try again." + }, + "CONFIRM": { + "TITLE": "Are you sure want to delete - %{attributeName}", + "PLACE_HOLDER": "Please type {attributeName} to confirm", + "MESSAGE": "Deleting will remove the attribute", + "YES": "Delete ", + "NO": "Cancel" + } + }, + "EDIT": { + "TITLE": "Edit attribute", + "UPDATE_BUTTON_TEXT": "Update", + "API": { + "SUCCESS_MESSAGE": "Attribute updated successfully", + "ERROR_MESSAGE": "There was an error updating attribute, please try again" } }, "TABS": { diff --git a/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue b/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue index 632e520e1..d374a104d 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue @@ -85,6 +85,8 @@ diff --git a/app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue b/app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue new file mode 100644 index 000000000..d8a3a3fc5 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue @@ -0,0 +1,162 @@ +