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

Sync LuigiClient API on LuigiElement Typescript declaration with actual implementation #3880

Open
ndricimrr opened this issue Aug 29, 2024 · 0 comments
Labels
documentation documentation tasks

Comments

@ndricimrr
Copy link
Contributor

Typescript declarations for LuigiElement do not seem to include all the implemented LuigiClient API that we have added for WC based Luigi Client (for example in Container ClientAPI or also for Core WC clientAPI)

In particular, the following does not include all of the functionality that we added into clientAPI

export interface LuigiClient {
/**
* @returns {Object} node parameters, where the object property name is the node parameter name without the prefix, and its value is the value of the node parameter. For example `{sort: 'asc', page: 3}`
* @memberof LuigiClient
*/
getActiveFeatureToggles: () => Array<String>;
/**
* Gets the current locale.
* @returns {string} current locale
* @memberof LuigiClient
*/
getCurrentLocale: () => string;
linkManager: () => LinkManager;
uxManager: () => UxManager;
publishEvent: (event: Event) => void;
/**
* Sets node parameters in Luigi Core. The parameters will be added to the URL.
* @param {Object} params
* @param {boolean} keepBrowserHistory
* @memberof LuigiClient
*/
addNodeParams: (params: Object, keepBrowserHistory: boolean) => void;
/**
* Returns the node parameters of the active URL.
* Node parameters are defined like URL query parameters but with a specific prefix allowing Luigi to pass them to the micro frontend view. The default prefix is **~** and you can use it in the following way: `https://my.luigi.app/home/products?~sort=asc&~page=3`.
* <!-- add-attribute:class:warning -->
* > **NOTE:** some special characters (`<`, `>`, `"`, `'`, `/`) in node parameters are HTML-encoded.
* @param {boolean} shouldDesanitise defines whether the specially encoded characters should be desanitised
* @returns {Object} node parameters, where the object property name is the node parameter name without the prefix, and its value is the value of the node parameter. For example `{sort: 'asc', page: 3}`
* @memberof LuigiClient
*/
getNodeParams: (shouldDesanitise: boolean) => Object;
/**
* Sends anchor to Luigi Core. The anchor will be added to the URL.
* @param {string} anchor
* @memberof LuigiClient
*/
setAnchor: (anchor: string) => void;
/**
* Retrieves the search params from the active URL
* @returns {Object} containing the search params
* @memberof LuigiClient
*/
getCoreSearchParams: () => Object;
/**
* Returns the dynamic path parameters of the active URL.
* Path parameters are defined by navigation nodes with a dynamic **pathSegment** value starting with **:**, such as **productId**.
* All path parameters in the current navigation path (as defined by the active URL) are returned.
* <!-- add-attribute:class:warning -->
* > **NOTE:** some special characters (`<`, `>`, `"`, `'`, `/`) in path parameters are HTML-encoded.
* @returns {Object} path parameters, where the object property name is the path parameter name without the prefix, and its value is the actual value of the path parameter. For example ` {productId: 1234, ...}`
* @memberof LuigiClient
*/
getPathParams: () => Object;
/**
* Returns the current client permissions as specified in the navigation node or an empty object. For details, see [Node parameters](navigation-parameters-reference.md).
* @returns {Object} client permissions as specified in the navigation node
* @memberof LuigiClient
*/
getClientPermissions(): () => Object;
}

Compare it against Container implementation at least.

getCurrentLocale: (): string | undefined => {
return this.thisComponent.locale;
},
getActiveFeatureToggles: (): string[] => {
return this.thisComponent.activeFeatureToggleList || [];
},
publishEvent: ev => {
if (eventBusElement && eventBusElement.eventBus) {
eventBusElement.eventBus.onPublishEvent(ev, nodeId, wc_id);
}
const payload = {
id: ev.type,
_metaData: {
nodeId,
wc_id,
src: component
},
data: ev.detail
};
this.dispatchLuigiEvent(Events.CUSTOM_MESSAGE, payload);
},
luigiClientInit: () => {
this.dispatchLuigiEvent(Events.INITIALIZED, {});
},
addNodeParams: (params, keepBrowserHistory) => {
if (isCompoundChild) {
return;
}
this.dispatchLuigiEvent(Events.ADD_NODE_PARAMS_REQUEST, {
params,
keepBrowserHistory
});
},
getNodeParams: (shouldDesanitise: boolean): Object => {
if (isCompoundChild) {
return {};
}
if (shouldDesanitise) {
return deSanitizeParamsMap(this.thisComponent.nodeParams);
}
return this.thisComponent.nodeParams || {};
},
setAnchor: anchor => {
if (isCompoundChild) {
return;
}
this.dispatchLuigiEvent(Events.SET_ANCHOR_LINK_REQUEST, anchor);
},
getAnchor: (): string => {
return this.thisComponent.anchor || '';
},
getCoreSearchParams: (): Object => {
return this.thisComponent.searchParams || {};
},
getPathParams: (): Object => {
return this.thisComponent.pathParams || {};
},
getClientPermissions: (): Object => {
return this.thisComponent.clientPermissions || {};
},
getUserSettings: (): Object => {
return this.thisComponent.userSettings || {};
},
setViewGroupData: data => {
this.dispatchLuigiEvent(Events.SET_VIEW_GROUP_DATA_REQUEST, data);
}

Discuss first if this is actually needed, as they may have been reasons not to do it in the first place.

@ndricimrr ndricimrr added the documentation documentation tasks label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation documentation tasks
Projects
None yet
Development

No branches or pull requests

1 participant