Commit 79dc0bd9 authored by julienmege's avatar julienmege
Browse files

extract common from process list

parent 0a09cbf3
{
"env": {
"test": {
"presets": ["latest"],
"plugins": ["transform-object-rest-spread"]
},
"rollup": {
"presets": [
["latest", {
"es2015": {
"modules": false
}
}]
],
"plugins": ["transform-object-rest-spread", "external-helpers"]
}
}
}
\ No newline at end of file
......@@ -1289,6 +1289,16 @@
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
"dev": true
},
"cross-env": {
"version": "5.1.4",
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.1.4.tgz",
"integrity": "sha512-Mx8mw6JWhfpYoEk7PGvHxJMLQwQHORAs8+2bX+C1lGQ4h3GkDb1zbzC2Nw85YH9ZQMlO0BHZxMacgrfPmMFxbg==",
"dev": true,
"requires": {
"cross-spawn": "5.1.0",
"is-windows": "1.0.2"
}
},
"cross-spawn": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
......
......@@ -7,6 +7,7 @@
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-latest": "^6.24.1",
"cross-env": "^5.1.4",
"jest": "^21.2.1",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^3.0.2",
......
const options = {
method: 'GET',
credentials: 'same-origin', // automatically send cookies for the current domain
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
// 'Cookie': document.cookie,
'Access-Control-Allow-Origin': '*'
},
mode: 'cors',
cache: 'default'
}
const url = '/bonita/API/bpm/process?p=0&c=10&o=displayName ASC&f=activationState=ENABLED'
// return a promise with processes as the first parameter
export default function () {
return fetch(url, options)
.then(function (response) {
if (response.ok) {
return Promise.resolve(response.json())
}
return Promise.reject(response.error())
})
}
/* A process looks like that :
{
"displayDescription": "",
"deploymentDate": "2018-02-14 12:18:34.254",
"displayName": "Pool",
"name": "Pool",
"description": "",
"deployedBy": "4",
"id": "7544905540282516773",
"activationState": "ENABLED",
"version": "1.0",
"configurationState": "RESOLVED",
"last_update_date": "2018-02-14 12:18:34.723",
"actorinitiatorid": "1"
}
*/
export {default as fetchProcesses} from './fetchProcesses'
\ No newline at end of file
export {default as apiClient} from './Client';
export {default as cookie} from './Cookie';
\ No newline at end of file
......@@ -2,19 +2,21 @@ subprojects {
apply plugin: 'com.moowork.node'
def currentDir = project.rootProject.projectDir
project.node {
version = '8.9.4'
npmVersion = '5.6.0'
download = true
workDir = project.file("${currentDir}/.gradle/nodejs")
npmWorkDir = project.file("${currentDir}/.gradle/npm")
project.beforeEvaluate {
project.node {
version = '8.9.4'
npmVersion = '5.6.0'
download = true
workDir = project.file("${currentDir}/.gradle/nodejs")
npmWorkDir = project.file("${currentDir}/.gradle/npm")
}
}
project.tasks.npm_install.configure {
inputs.files('package.json', 'package-lock.json')
outputs.dirs('node_modules')
}
def buildNpm = project.task([type: com.moowork.gradle.node.npm.NpmTask, dependsOn: project.tasks.npm_install], 'buildNpm') {
//environment ["BABEL_ENV", "rollup"]
args = ['run', 'build']
inputs.files('package.json', 'package-lock.json')
inputs.dir('src')
......
......@@ -7,5 +7,6 @@ bonitaPage {
// Workaround to manage React-CLI non conventional build directory
project.buildDir = 'build-gradle'
project.tasks.buildPage.configure {
dependsOn ':common:api:buildNpm'
inputs.dir('public')
}
\ No newline at end of file
......@@ -3,6 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@bonita/api": "file:../common/api",
"@bonita/bonita-theme": "file:../common/bonita-theme",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.1"
......
import { apiClient } from '../common';
import { apiClient } from '@bonita/api';
// I use a class syntax here but we can use a more functional approach if we want.
class CategoryApi {
......
export default class Pagination {
constructor(page, size, total) {
this.page = page;
this.size = size; // = bonita `c` parameter (count)
this.total = total;
}
static from(contentRange) {
const match = /(\d+)-(\d+)\/(\d+)/g.exec(contentRange);
if (!match || match.length < 4) {
return {};
}
return new Pagination(parseInt(match[1]), parseInt(match[2]), parseInt(match[3]))
}
}
\ No newline at end of file
import Pagination from './Pagination';
describe('pagination', () => {
it('should parse content-range', () => {
const pagination = Pagination.from('12-25/1234');
expect(pagination).toEqual({
page: 12,
size: 25,
total: 1234
});
});
it('should return an empty object when parsing fail', () => {
expect(Pagination.from('fail')).toEqual({});
expect(Pagination.from('1-2')).toEqual({});
expect(Pagination.from('')).toEqual({});
expect(Pagination.from(undefined)).toEqual({});
});
});
This will be shared across all pages and bonita projects that needs to use it.
No changes should be done in this code base unless we feel that most of pages will need that change
\ No newline at end of file
export {default as apiClient} from './Client';
export {default as cookie} from './Cookie';
export {default as Pagination} from './Pagination';
\ No newline at end of file
......@@ -6,6 +6,10 @@ pluginManagement {
}
}
include 'common'
include 'common:api'
include 'common:bonita-theme'
include 'page-process-list'
include 'pages'
include 'pages:page-hello-world'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment