Skip to content

Commit 7de9a6c

Browse files
authored
Merge pull request #9 from davidlandais/feat-component-overriding
feat(ui-component-overriding): add possibility to override ui default…
2 parents db48541 + 7ac4ccb commit 7de9a6c

26 files changed

+18838
-164
lines changed

.gitignore

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
lib
12
.cache
3+
.vscode
4+
.idea
5+
coverage
6+
node_modules
7+
lerna-debug.log
8+
npm-debug.log
9+
.DS_Store
10+
docs
211
old
3-
dist/
4-
coverage/
5-
.env
12+
dist
13+
.env

packages/ui-predicate-core/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
lib
22
.cache
3+
.vscode
4+
.idea
35
coverage
46
node_modules
7+
lerna-debug.log
8+
npm-debug.log
9+
.DS_Store
10+
docs
11+
dist

packages/ui-predicate-core/src/PredicateCore.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint no-unused-vars: "off" */
22

33
/**
4-
* Rules
4+
* PredicateCore
55
* @module core
66
* @namespace core
77
* @since 1.0.0
@@ -27,7 +27,7 @@ function head(list) {
2727
return option.fromNullable(list[0]).value();
2828
}
2929

30-
module.exports = function({ dataclasses, invariants, errors, rules }) {
30+
module.exports = function({ dataclasses, invariants, errors, rules, UITypes }) {
3131
const { CompoundPredicate, ComparisonPredicate, Predicate } = dataclasses;
3232
/**
3333
* Get a type by its type_id
@@ -278,7 +278,7 @@ module.exports = function({ dataclasses, invariants, errors, rules }) {
278278
* @memberof core
279279
*/
280280
function PredicateCore(args) {
281-
const { columns, data, options } = args;
281+
const { data, columns, ui, options } = args;
282282

283283
return new Promise((resolve, reject) => {
284284
try {
@@ -572,6 +572,17 @@ module.exports = function({ dataclasses, invariants, errors, rules }) {
572572
);
573573
}
574574

575+
/**
576+
* Get default or overrided ui component
577+
* @param {ui} name the UIType key to get the right component
578+
* @return {any} component
579+
* @since 1.0.0
580+
* @memberof core.api
581+
*/
582+
function getUIComponent(name) {
583+
return ui[name];
584+
}
585+
575586
/**
576587
* Compute the JSON pointer path the element
577588
* @param {Object} element (http://jsonpatch.com/)
@@ -683,6 +694,20 @@ module.exports = function({ dataclasses, invariants, errors, rules }) {
683694
setArgumentValue: _afterPromise(setArgumentValue, _afterWrite),
684695

685696
getArgumentTypeComponentById,
697+
698+
/**
699+
* Enumeration of overridable core ui-predicate component
700+
* @enum {String}
701+
*/
702+
UITypes,
703+
704+
/**
705+
* Get core UI component (e.g. target selector)
706+
* @param {core.ui} ui component name
707+
* @return {Object} component
708+
* @memberof core.api
709+
*/
710+
getUIComponent,
686711
toJSON,
687712

688713
/**

packages/ui-predicate-core/src/PredicateCore.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
ComparisonPredicate,
1212
LogicalType,
1313
},
14+
UITypes,
1415
errors,
1516
} = require('./index');
1617

@@ -591,6 +592,18 @@ describe('UIPredicateCore', () => {
591592
});
592593
});
593594

595+
describe('ctrl.getUIComponent', () => {
596+
it('return a default UI component', () => {
597+
expect.assertions(1);
598+
return PredicateCore({
599+
columns: _defaultConfig(),
600+
ui: UITypes
601+
}).then(ctrl => {
602+
expect(ctrl.getUIComponent(UITypes.TARGETS)).toBe('TARGETS');
603+
});
604+
});
605+
});
606+
594607
describe('ctrl.options', () => {
595608
it('expose computed options', () => {
596609
expect.assertions(1);
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* UITypes
3+
* @module ui
4+
* @namespace core
5+
* @since 1.0.0
6+
* @note default (and overridable) base ui components of ui-predicate (e.g. target select, operator select, add button, remove button, ...)
7+
*/
8+
module.exports = {
9+
TARGETS: 'TARGETS',
10+
LOGICAL_TYPES: 'LOGICAL_TYPES',
11+
OPERATORS: 'OPERATORS',
12+
PREDICATE_ADD: 'PREDICATE_ADD',
13+
PREDICATE_REMOVE: 'PREDICATE_REMOVE',
14+
ARGUMENT_DEFAULT: 'ARGUMENT_DEFAULT',
15+
}

packages/ui-predicate-core/src/__snapshots__/PredicateCore.test.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Array [
3030
"setPredicateLogicalType_id",
3131
"setArgumentValue",
3232
"getArgumentTypeComponentById",
33+
"UITypes",
34+
"getUIComponent",
3335
"toJSON",
3436
"root",
3537
"columns",
+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const errors = require('./errors');
2+
const UITypes = require('./UITypes');
23
const rules = require('./rules');
34
const invariants = require('./invariants')({ errors, rules });
45
const dataclasses = require('./dataclasses')({ invariants, errors });
@@ -7,5 +8,7 @@ const PredicateCore = require('./PredicateCore')({
78
invariants,
89
errors,
910
rules,
11+
UITypes,
1012
});
11-
module.exports = { PredicateCore, errors, invariants, dataclasses };
13+
14+
module.exports = { PredicateCore, errors, invariants, UITypes, dataclasses };

packages/ui-predicate-vue/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
lib
2+
.cache
3+
.vscode
4+
.idea
5+
coverage
6+
node_modules
7+
lerna-debug.log
8+
npm-debug.log
9+
.DS_Store
10+
docs
11+
dist

packages/ui-predicate-vue/getting-started/simple.vue

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<template>
22
<div class="columns">
33
<div class="column">
4-
<ui-predicate :config="config" @changed="onChange" @initialized="onChange"></ui-predicate>
4+
<ui-predicate
5+
v-model="predicate"
6+
:columns="columns"
7+
@changed="onChange"
8+
@initialized="onChange"
9+
/>
510
</div>
611

712
<div class="column">
@@ -38,8 +43,20 @@ export default {
3843
name: 'app',
3944
data() {
4045
return {
41-
ast: {},
42-
config: {
46+
ast: {
47+
48+
},
49+
predicate: {
50+
logicalType_id: 'all',
51+
predicates: [
52+
{
53+
"target_id": "article.videoCount",
54+
"operator_id": "isEqualTo",
55+
"argument": 42
56+
},
57+
],
58+
},
59+
columns: {
4360
targets: [
4461
{
4562
target_id: 'article.title',

packages/ui-predicate-vue/jest.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ module.exports = {
2323
collectCoverage: true,
2424
coverageReporters: ['html', 'text-summary'],
2525
collectCoverageFrom: ['**/*.{js,vue}', '!**/node_modules/**'],
26+
verbose: true,
27+
testURL: 'http://localhost/',
2628
};

0 commit comments

Comments
 (0)