feat: add theme to galaxy and getPropertyPanelDefinition to viz (#1736)

* feat: add theme to galaxy and getPropertyPanelDefinition to viz

* chore: fix spec

* chore: fix test

* fix: return correct def

* chore: lint
This commit is contained in:
Tobias Åström
2025-05-07 15:28:11 +02:00
committed by GitHub
parent d5742dae8a
commit 51fbdd1f7d
7 changed files with 85 additions and 51 deletions

View File

@@ -26,7 +26,7 @@ describe('nucleus', () => {
createObjectMock = jest.fn().mockReturnValue('created object');
getObjectMock = jest.fn().mockReturnValue('got object');
setThemeMock = jest.fn();
appThemeFnMock = jest.fn().mockReturnValue({ externalAPI: 'internal', setTheme: setThemeMock });
appThemeFnMock = jest.fn().mockReturnValue({ externalAPI: 'external', setTheme: setThemeMock });
deviceTypeFnMock = jest.fn().mockReturnValue('desktop');
rootAppMock = jest.fn().mockReturnValue([{}]);
translatorAddMock = jest.fn();
@@ -127,6 +127,7 @@ describe('nucleus', () => {
some: 'thing',
},
flags: 'flags',
theme: 'external',
deviceType: 'desktop',
hostConfig: 'HOST',
translator,

View File

@@ -29,12 +29,14 @@ describe('viz', () => {
let mockElement;
let definitionName = 'props';
beforeAll(() => {
unmountMock = jest.fn();
setSnOptions = jest.fn();
setSnContext = jest.fn();
setSnPlugins = jest.fn();
getExtensionDefinition = jest.fn();
getExtensionDefinition = jest.fn().mockImplementation(() => ({ definition: { name: definitionName } }));
setModel = jest.fn();
takeSnapshot = jest.fn();
exportImage = jest.fn();
@@ -79,7 +81,7 @@ describe('viz', () => {
model,
halo: {
public: {},
config: { context: { dataViewType: 'sn-table' } },
context: { dataViewType: 'sn-table', enablePrivateExperimental: true },
app: { createSessionObject: createSessionObjectMock, destroySessionObject: destroySessionObjectMock },
types: { getSupportedVersion: () => true },
},
@@ -282,4 +284,31 @@ describe('viz', () => {
expect(handle.api).toEqual('api');
});
});
describe('getPropertyPanelDefinition', () => {
test('should fetch the definition.ext.definition', async () => {
const opts = { myops: 'myopts', onInitialRender: jest.fn() };
api.__DO_NOT_USE__.options(opts);
await mounted;
const args = cellRef.current.setSnOptions.mock.lastCall[0];
args.onInitialRender();
const panelDef = api.getPropertyPanelDefinition();
expect(panelDef.name).toEqual('props');
});
test('should return original after data view toggle the definition.ext.definition', async () => {
const opts = { myops: 'myopts', onInitialRender: jest.fn() };
api.__DO_NOT_USE__.options(opts);
await mounted;
const args = cellRef.current.setSnOptions.mock.lastCall[0];
args.onInitialRender();
let panelDef = api.getPropertyPanelDefinition();
expect(panelDef.name).toEqual('props');
definitionName = 'old';
await api.toggleDataView(); // locks in the "old" definition
definitionName = 'new';
panelDef = api.getPropertyPanelDefinition();
expect(panelDef.name).toEqual('old');
});
});
});

View File

@@ -237,6 +237,8 @@ function nuked(configuration = {}) {
galaxy: /** @lends Galaxy */ {
/** @type {Translator} */
translator: locale.translator,
/** @type {Theme} */
theme: appTheme.externalAPI,
// TODO - validate flags input
/** @type {Flags} */
flags: flagsFn(configuration.flags),

View File

@@ -1,13 +1,3 @@
/**
* Escape a script field name. Will add surrounding brackets if the field name contains special characters.
* Examples:
* Field1 -> Field1
* My field -> [My field]
* My] field -> [My]] field]
*
* @param field
* @returns {*}
*/
const escapeField = (field) => {
if (!field || field === ']') {
return field;

View File

@@ -104,6 +104,14 @@ export default function viz({
}
return false;
},
getPropertyPanelDefinition() {
if (mountedReference && successfulRender) {
return originalExtensionDef
? originalExtensionDef.definition
: cellRef.current.getExtensionDefinition().definition;
}
return false;
},
toggleFocus(focus) {
cellRef.current.toggleFocus(focus);
},
@@ -204,7 +212,7 @@ export default function viz({
async toggleDataView(showDataView) {
let newModel;
if (!viewDataObjectId && showDataView !== false) {
let newType = halo.config.context.dataViewType;
let newType = halo.context.dataViewType;
const oldProperties = await model.getEffectiveProperties();
// Check if dataViewType is registered. Otherwise potentially fallback to table
if (!halo.types.getSupportedVersion(newType)) {

View File

@@ -801,6 +801,9 @@
"translator": {
"type": "#/definitions/Translator"
},
"theme": {
"type": "#/definitions/Theme"
},
"flags": {
"type": "#/definitions/Flags"
},
@@ -1727,6 +1730,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};"
]
},
"Field": {
"kind": "alias",
"items": {
@@ -1878,33 +1908,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};"
]
},
"LoadType": {
"kind": "interface",
"params": [

View File

@@ -274,6 +274,7 @@ declare namespace stardust {
interface Galaxy {
translator: stardust.Translator;
theme: stardust.Theme;
flags: stardust.Flags;
deviceType: string;
hostConfig: object;
@@ -558,6 +559,16 @@ declare namespace stardust {
}
/**
* An object literal containing meta information about the plugin and a function containing the plugin implementation.
*/
interface Plugin {
info: {
name: string;
};
fn: ()=>void;
}
type Field = string | qix.NxDimension | qix.NxMeasure | stardust.LibraryField;
/**
@@ -599,16 +610,6 @@ declare namespace stardust {
type: "dimension" | "measure";
}
/**
* An object literal containing meta information about the plugin and a function containing the plugin implementation.
*/
interface Plugin {
info: {
name: string;
};
fn: ()=>void;
}
interface LoadType {
(type: {
name: string;