feat: Add custom attribute table (#2929)

This commit is contained in:
Sivin Varghese
2021-09-08 09:37:58 +05:30
committed by GitHub
parent 39c4fa111a
commit c80289e661
9 changed files with 242 additions and 42 deletions

View File

@@ -14,18 +14,18 @@ export const getters = {
getUIFlags(_state) {
return _state.uiFlags;
},
getAttributes: _state => attributeType => {
getAttributesByModel: _state => attributeModel => {
return _state.records.filter(
record => record.attribute_display_type === attributeType
record => record.attribute_model === attributeModel
);
},
};
export const actions = {
get: async function getAttributes({ commit }) {
get: async function getAttributesByModel({ commit }, modelId) {
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: true });
try {
const response = await AttributeAPI.get();
const response = await AttributeAPI.getAttributesByModel(modelId);
commit(types.SET_CUSTOM_ATTRIBUTE, response.data);
} catch (error) {
// Ignore error

View File

@@ -11,7 +11,7 @@ describe('#actions', () => {
describe('#get', () => {
it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue({ data: attributesList });
await actions.get({ commit }, { inboxId: 23 });
await actions.get({ commit });
expect(commit.mock.calls).toEqual([
[types.default.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: true }],
[types.default.SET_CUSTOM_ATTRIBUTE, attributesList],
@@ -20,7 +20,7 @@ describe('#actions', () => {
});
it('sends correct actions if API is error', async () => {
axios.get.mockRejectedValue({ message: 'Incorrect header' });
await actions.get({ commit }, { inboxId: 23 });
await actions.get({ commit });
expect(commit.mock.calls).toEqual([
[types.default.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: true }],
[types.default.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: false }],

View File

@@ -1,16 +1,16 @@
export default [
{
attribute_display_name: 'Language',
attribute_display_type: 0,
attribute_display_type: 1,
attribute_description: 'The conversation language',
attribute_key: 'language',
attribute_model: 0,
},
{
attribute_display_name: 'Language one',
attribute_display_type: 1,
attribute_display_type: 2,
attribute_description: 'The conversation language one',
attribute_key: 'language_one',
attribute_model: 3,
attribute_model: 1,
},
];

View File

@@ -2,15 +2,15 @@ import { getters } from '../../attributes';
import attributesList from './fixtures';
describe('#getters', () => {
it('getAttributes', () => {
it('getAttributesByModel', () => {
const state = { records: attributesList };
expect(getters.getAttributes(state)(1)).toEqual([
expect(getters.getAttributesByModel(state)(1)).toEqual([
{
attribute_display_name: 'Language one',
attribute_display_type: 1,
attribute_display_type: 2,
attribute_description: 'The conversation language one',
attribute_key: 'language_one',
attribute_model: 3,
attribute_model: 1,
},
]);
});