Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tsm/expose enigma #923

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions apis/enigma-mocker/src/from-generic-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,7 @@ import CreateSessionObjectMock from './mocks/create-session-object-mock';
import GetObjectMock from './mocks/get-object-mock';
import GetAppLayoutMock from './mocks/get-app-layout-mock';

/**
* @interface EnigmaMockerOptions
* @property {number} delay Simulate delay (in ms) for calls in enigma-mocker.
*/

/**
* Mocks Engima app functionality. It accepts one / many generic objects as input argument and returns the mocked Enigma app. Each generic object represents one visulization and specifies how it behaves. For example, what layout to use the data to present.
*
* The generic object is represented with a Javascript object with a number of properties. The name of the property correlates to the name in the Enigma model for `app.getObject(id)`. For example, the property `getLayout` in the generic object is used to define `app.getObject(id).getLayout()`. Any property can be added to the fixture (just make sure it exists and behaves as in the Enigma model!).
*
* The value for each property is either fixed (string / boolean / number / object) or a function. Arguments are forwarded to the function to allow for greater flexibility. For example, this can be used to return different hypercube data when scrolling in the chart.
*
* @param {Array<object>} genericObjects Generic objects controling behaviour of visualizations.
* @param {EnigmaMockerOptions} options Options
* @returns {Promise<enigma.Doc>}
* @example
* const genericObject = {
* getLayout() {
* return {
* qInfo: {
* qId: 'qqj4zx',
* qType: 'sn-grid-chart'
* },
* ...
* }
* },
* getHyperCubeData(path, page) {
* return [ ... ];
* }
* };
* const app = await EnigmaMocker.fromGenericObjects([genericObject]);
*/
export default (genericObjects, options = {}) => {
export default function fromGenericObjects(genericObjects, options = {}) {
const session = new SessionMock();
const createSessionObject = new CreateSessionObjectMock();
const getObject = new GetObjectMock(genericObjects, options);
Expand All @@ -50,4 +18,4 @@ export default (genericObjects, options = {}) => {
};

return Promise.resolve(app);
};
}
51 changes: 48 additions & 3 deletions apis/enigma-mocker/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
import fromGenericObjects from './from-generic-objects';
import fGO from './from-generic-objects';

export default {
fromGenericObjects,
/**
* @interface EnigmaMockerOptions
* @property {number} delay Simulate delay (in ms) for calls in enigma-mocker.
* @experimental
* @since 3.0.0
*/

/**
* @entry
* @alias EnigmaMocker
* @description Mocks Engima app functionality for demo and testing purposes.
*/
const api = /** @lends EnigmaMocker# */ {
/**
* Mocks Engima app functionality. It accepts one / many generic objects as input argument and returns the mocked Enigma app. Each generic object represents one visulization and specifies how it behaves. For example, what layout to use the data to present.
*
* The generic object is represented with a Javascript object with a number of properties. The name of the property correlates to the name in the Enigma model for `app.getObject(id)`. For example, the property `getLayout` in the generic object is used to define `app.getObject(id).getLayout()`. Any property can be added to the fixture (just make sure it exists and behaves as in the Enigma model!).
*
* The value for each property is either fixed (string / boolean / number / object) or a function. Arguments are forwarded to the function to allow for greater flexibility. For example, this can be used to return different hypercube data when scrolling in the chart.
* @type function
* @experimental
* @since 3.0.0
* @param {Array<object>} genericObjects Generic objects controling behaviour of visualizations.
* @param {EnigmaMockerOptions} options Options
* @returns {Promise<EngineAPI.IApp>}
* @example
* const genericObject = {
* getLayout() {
* return {
* qInfo: {
* qId: 'qqj4zx',
* qType: 'sn-grid-chart'
* },
* ...
* }
* },
* getHyperCubeData(path, page) {
* return [ ... ];
* }
* };
* const app = await EnigmaMocker.fromGenericObjects([genericObject]);
*/
fromGenericObjects(genericObjects, options = {}) {
return fGO(genericObjects, options);
},
};

export default api;
8 changes: 8 additions & 0 deletions apis/enigma-mocker/src/mocks/get-object-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { getPropValue, getPropFn } from '../prop';

/**
* Properties on `getObject()` operating synchronously.
* @ignore
* @type Array
*/
const PROPS_SYNC = [
'addListener',
Expand All @@ -17,6 +19,7 @@ const PROPS_SYNC = [
/**
* Is property operating asynchrously.
* @param {string} name Property name.
* @ignore
* @returns `true` if property is operating asynchrously, otherwise `false`.
*/
function isPropAsync(name) {
Expand All @@ -26,6 +29,7 @@ function isPropAsync(name) {
/**
* Get `qId` for visualization.
* @param {object} genericObject Generic object describing behaviour of mock
* @ignore
* @returns The `qId`, undefined if not present
*/
function getQId(genericObject) {
Expand All @@ -37,6 +41,7 @@ function getQId(genericObject) {
* Create a mock of a generic object. Mandatory properties are added, functions returns async values where applicable etc.
* @param {object} genericObject Generic object describing behaviour of mock
* @param {EnigmaMockerOptions} options Options.
* @ignore
* @returns The mocked object
*/
function createMock(genericObject, options) {
Expand All @@ -63,6 +68,7 @@ function createMock(genericObject, options) {
* Create mocked objects from list of generic objects.
* @param {Array<object>} genericObjects Generic objects describing behaviour of mock
* @param {EnigmaMockerOptions} options options
* @ignore
* @returns Object with mocks where key is `qId` and value is the mocked object.
*/
function createMocks(genericObjects, options) {
Expand All @@ -78,6 +84,7 @@ function createMocks(genericObjects, options) {
/**
* Validates if mandatory information is available.
* @param {object} genericObject Generic object to validate
* @ignore
* @throws {}
* <ul>
* <li>{Error} If getLayout is missing</li>
Expand All @@ -98,6 +105,7 @@ function validate(genericObject) {
* Creates mock of `getObject(id)` based on an array of generic objects.
* @param {Array<object>} genericObjects Generic objects.
* @param {EnigmaMockerOptions} options Options.
* @ignore
* @returns Function to retrieve the mocked generic object with the corresponding id.
*/
function GetObjectMock(genericObjects = [], options = {}) {
Expand Down
10 changes: 6 additions & 4 deletions apis/enigma-mocker/src/prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* id: getValue(fixture.id, { defaultValue: 'object-id-${+Date.now()}'}),
* }
* ```
*
* @type function
* @ignore
* @param {any} prop Fixture property. Either a fixed value (string / object / boolean / ...) or a function invoked when the value is needed.
* @param {object} options Options.
* @param {Array<any>} options.args Arguments used to evaluate the property value.
* @param {any} options.defaultValue Default value in case not value is defined in fixture.
* @returns The property value.
* @returns {any} The property value.
*/
export const getPropValue = (prop, { args = [], defaultValue } = {}) => {
if (typeof prop === 'function') {
Expand Down Expand Up @@ -47,13 +48,14 @@ export const getPropValue = (prop, { args = [], defaultValue } = {}) => {
* getHyperCubeData: getPropFn(fixture.getHyperCubeData, { defaultValue: [], usePromise: true })
* };
* ```
*
* @type function
* @ignore
* @param {any} prop Fixture property. Either a fixed value (string / object / boolean / ...) or a function invoked when the value is needed.
* @param {object} options Options.
* @param {any} options.defaultValue Default value in case not value is defined in fixture.
* @param {boolean} options.async When `true` the returns value is wrapped in a promise, otherwise the value is directly returned.
* @param {number} options.number Delay before value is returned.
* @returns A fixture property function
* @returns {function} A fixture property function
*/
export const getPropFn =
(prop, { defaultValue, async = true, delay = 0 } = {}) =>
Expand Down
1 change: 1 addition & 0 deletions apis/nucleus/src/components/listbox/useConfirmUnfocus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRef, useEffect, useState } from 'react';
/**
* Hook that confirms selection when
* user interact outside of passed element ref.
* @ignore
*/

export default function useConfirmUnfocus(ref, selections, shouldConfirmOnBlur) {
Expand Down
1 change: 1 addition & 0 deletions apis/stardust/api-spec/spec.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'../locale/src/translator.js',
'../theme/src/**/*.js',
'../conversion/src/**/*.js',
'../enigma-mocker/src/**/*.js',
],
api: {
stability: 'stable',
Expand Down
107 changes: 80 additions & 27 deletions apis/stardust/api-spec/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,46 @@
"// configure nebula to enable navigation between charts\nembed(app, {\n context: {\n keyboardNavigation: true, // tell Nebula to handle navigation\n }\n}).render({ element, id: 'sdfsdf' });",
"import { useKeyboard } from '@nebula.js/stardust';\n// ...\nconst keyboard = useKeyboard();\nuseEffect(() => {\n // Set a tab stop on our button if in focus or if Nebulas navigation is disabled\n button.setAttribute('tabIndex', keyboard.active || !keyboard.enabled ? 0 : -1);\n // If navigation is enabled and focus has shifted, lets focus the button\n keyboard.enabled && keyboard.active && button.focus();\n}, [keyboard])"
]
},
"EnigmaMocker": {
"description": "Mocks Engima app functionality for demo and testing purposes.",
"kind": "object",
"entries": {
"fromGenericObjects": {
"description": "Mocks Engima app functionality. It accepts one / many generic objects as input argument and returns the mocked Enigma app. Each generic object represents one visulization and specifies how it behaves. For example, what layout to use the data to present.\n\nThe generic object is represented with a Javascript object with a number of properties. The name of the property correlates to the name in the Enigma model for `app.getObject(id)`. For example, the property `getLayout` in the generic object is used to define `app.getObject(id).getLayout()`. Any property can be added to the fixture (just make sure it exists and behaves as in the Enigma model!).\n\nThe value for each property is either fixed (string / boolean / number / object) or a function. Arguments are forwarded to the function to allow for greater flexibility. For example, this can be used to return different hypercube data when scrolling in the chart.",
"stability": "experimental",
"availability": {
"since": "3.0.0"
},
"kind": "function",
"params": [
{
"name": "genericObjects",
"description": "Generic objects controling behaviour of visualizations.",
"kind": "array",
"items": {
"type": "object"
}
},
{
"name": "options",
"description": "Options",
"type": "#/definitions/EnigmaMockerOptions"
}
],
"returns": {
"type": "Promise",
"generics": [
{
"type": "EngineAPI.IApp"
}
]
},
"examples": [
"const genericObject = {\n getLayout() {\n return {\n qInfo: {\n qId: 'qqj4zx',\n qType: 'sn-grid-chart'\n },\n ...\n }\n },\n getHyperCubeData(path, page) {\n return [ ... ];\n }\n};\nconst app = await EnigmaMocker.fromGenericObjects([genericObject]);"
]
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -1213,33 +1253,6 @@
}
}
},
"Plugin": {
"description": "An object literal containing meta information about the plugin and a function containing the plugin implementation.",
"stability": "experimental",
"availability": {
"since": "1.2.0"
},
"kind": "interface",
"entries": {
"info": {
"description": "Object that can hold various meta info about the plugin",
"kind": "object",
"entries": {
"name": {
"description": "The name of the plugin",
"type": "string"
}
}
},
"fn": {
"description": "The implementation of the plugin. Input and return value is up to the plugin implementation to decide based on its purpose.",
"type": "function"
}
},
"examples": [
"const plugin = {\n info: {\n name: \"example-plugin\",\n type: \"meta-type\",\n },\n fn: () => {\n // Plugin implementation goes here\n }\n};"
]
},
"Field": {
"kind": "alias",
"items": {
Expand Down Expand Up @@ -1349,6 +1362,33 @@
}
}
},
"Plugin": {
"description": "An object literal containing meta information about the plugin and a function containing the plugin implementation.",
"stability": "experimental",
"availability": {
"since": "1.2.0"
},
"kind": "interface",
"entries": {
"info": {
"description": "Object that can hold various meta info about the plugin",
"kind": "object",
"entries": {
"name": {
"description": "The name of the plugin",
"type": "string"
}
}
},
"fn": {
"description": "The implementation of the plugin. Input and return value is up to the plugin implementation to decide based on its purpose.",
"type": "function"
}
},
"examples": [
"const plugin = {\n info: {\n name: \"example-plugin\",\n type: \"meta-type\",\n },\n fn: () => {\n // Plugin implementation goes here\n }\n};"
]
},
"LoadType": {
"kind": "interface",
"params": [
Expand Down Expand Up @@ -2350,6 +2390,19 @@
],
"kind": "interface",
"entries": {}
},
"EnigmaMockerOptions": {
"stability": "experimental",
"availability": {
"since": "3.0.0"
},
"kind": "interface",
"entries": {
"delay": {
"description": "Simulate delay (in ms) for calls in enigma-mocker.",
"type": "number"
}
}
}
}
}
4 changes: 2 additions & 2 deletions apis/stardust/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import conversion from '@nebula.js/conversion';
import EnigmaMocker from '@nebula.js/enigma-mocker';

// mashup api
export { embed, conversion };
export { embed, conversion, EnigmaMocker };

// component api
export {
Expand Down Expand Up @@ -40,5 +40,5 @@ export {
} from '@nebula.js/supernova';

// component internals
const __DO_NOT_USE__ = { generator, hook, theme, locale, EnigmaMocker };
const __DO_NOT_USE__ = { generator, hook, theme, locale };
export { __DO_NOT_USE__ };
Loading