Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
extract view attributes related functions to ViewAttributesAction.js
Browse files Browse the repository at this point in the history
#1357

@wiadev  pls review
  • Loading branch information
teosarca committed Dec 3, 2017
1 parent c6a32d7 commit 1f4e3d6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 82 deletions.
78 changes: 0 additions & 78 deletions src/actions/GenericActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ export function initLayout(
);
}

export function getViewAttributesLayout(windowId, viewId, rowId) {
return axios.get(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes/layout'
);
}

export function getData(
entity, docType, docId, tabId, rowId, subentity, subentityId, isAdvanced,
orderBy, viewId
Expand All @@ -49,73 +38,6 @@ export function getData(
);
}

export function getViewAttributeDropdown(windowId, viewId, rowId, attribute) {
return axios.get(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes/attribute/' + attribute +
'/dropdown'
);
}
/**
*
* @param {*} windowId
* @param {*} viewId
* @param {*} rowId
*/
export function getViewAttributes (
windowId, viewId, rowId
) {
return axios.get(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes'
);
}

function getPatchRequestPayload(property, value) {
let payload = [];
if (Array.isArray(property) && value !== undefined) {
payload = property.map(item => ({
op: 'replace',
path: item.field,
value
}));
} else if (property && value !== undefined) {
payload = [{
op: 'replace',
path: property,
value
}];
}

return payload;
}

export function patchViewAttributes(
windowId,
viewId,
rowId,
property,
value
) {
const payload = getPatchRequestPayload(property, value);

return axios.patch(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes', payload);
}

export function createInstance(entity, docType, docId, tabId, subentity) {
return axios.post(
config.API_URL +
Expand Down
85 changes: 85 additions & 0 deletions src/actions/ViewAttributesActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import axios from 'axios';

//
// Handles view attributes (the panel which is displayed on the right side of a view, if view supports attributes)
// Endpoints: /rest/api/documentView/{windowId}/{viewId}/{rowId}/attributes/**
//

export function getViewAttributesLayout(windowId, viewId, rowId) {
return axios.get(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes/layout'
);
}

export function getViewAttributeDropdown(windowId, viewId, rowId, attribute) {
return axios.get(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes/attribute/' + attribute +
'/dropdown'
);
}

/**
*
* @param {*} windowId
* @param {*} viewId
* @param {*} rowId
*/
export function getViewAttributes (
windowId, viewId, rowId
) {
return axios.get(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes'
);
}

function createPatchRequestPayload(property, value) {
let payload = [];
if (Array.isArray(property) && value !== undefined) {
payload = property.map(item => ({
op: 'replace',
path: item.field,
value
}));
} else if (property && value !== undefined) {
payload = [{
op: 'replace',
path: property,
value
}];
}

return payload;
}

export function patchViewAttributes(
windowId,
viewId,
rowId,
property,
value
) {
const payload = createPatchRequestPayload(property, value);

return axios.patch(
config.API_URL +
'/documentView'+
'/' + windowId +
'/' + viewId +
'/' + rowId +
'/attributes', payload);
}
2 changes: 1 addition & 1 deletion src/components/DataLayoutWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {connect} from 'react-redux';

import {
patchViewAttributes
} from '../actions/GenericActions';
} from '../actions/ViewAttributesActions';

import {
parseToDisplay
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/SelectionAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import counterpart from 'counterpart';
import {
getViewAttributesLayout,
getViewAttributes
} from '../../actions/GenericActions';
} from '../../actions/ViewAttributesActions';

import RawWidget from '../widget/RawWidget';

Expand Down
7 changes: 5 additions & 2 deletions src/components/widget/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { connect } from 'react-redux';
import RawList from './RawList';

import {
dropdownRequest,
getViewAttributeDropdown
dropdownRequest
} from '../../../actions/GenericActions';

import {
getViewAttributeDropdown
} from '../../../actions/ViewAttributesActions';

class List extends Component {
constructor(props) {
super(props);
Expand Down

0 comments on commit 1f4e3d6

Please sign in to comment.