feat: Add custom attribute table (#2929)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 }],
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user