Skip to content

Commit 6ff449d

Browse files
committed
feat(ui-component-overriding): add possibility to override ui default components
1 parent db48541 commit 6ff449d

25 files changed

+18965
-136
lines changed

Diff for: .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

Diff for: 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

Diff for: packages/ui-predicate-core/src/PredicateCore.js

+14-2
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
@@ -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,7 @@ module.exports = function({ dataclasses, invariants, errors, rules }) {
683694
setArgumentValue: _afterPromise(setArgumentValue, _afterWrite),
684695

685696
getArgumentTypeComponentById,
697+
getUIComponent,
686698
toJSON,
687699

688700
/**

Diff for: 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);

Diff for: packages/ui-predicate-core/src/UITypes.js

+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+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Array [
3030
"setPredicateLogicalType_id",
3131
"setArgumentValue",
3232
"getArgumentTypeComponentById",
33+
"getUIComponent",
3334
"toJSON",
3435
"root",
3536
"columns",

Diff for: packages/ui-predicate-core/src/index.js

+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 };

Diff for: 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

Diff for: 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',

0 commit comments

Comments
 (0)