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

Add getPathParams, getCoreSearchParams, getClientPermissions #3390

Merged
merged 58 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c3c89b1
Add links
ndricimrr Aug 8, 2023
4090925
Merge branch 'main' into 3387-add-more-apis
ndricimrr Aug 8, 2023
952ee5c
search params
ndricimrr Aug 8, 2023
a0a8e83
Merge branch 'main' into 3387-add-more-apis
ndricimrr Aug 21, 2023
7d965c0
Merge branch 'main' into 3387-add-more-apis
ndricimrr Aug 22, 2023
60a64e7
Fix bundle error
ndricimrr Aug 22, 2023
0f17466
Merge branch 'main' into 3387-add-more-apis
ndricimrr Aug 23, 2023
93682f5
add docu
ndricimrr Aug 23, 2023
c8d2490
add second fn and docu
ndricimrr Aug 23, 2023
7f3bab5
Add third
ndricimrr Aug 23, 2023
cb19e9b
Add container 1
ndricimrr Aug 24, 2023
22323d1
Add container 2
ndricimrr Aug 24, 2023
c6a7a2c
Add test 1
ndricimrr Aug 25, 2023
ac9c3f6
Add docu
ndricimrr Aug 25, 2023
e76c9b5
Add e2e tests container
ndricimrr Aug 25, 2023
b378fc8
Add tests
ndricimrr Aug 25, 2023
d209038
Update core/src/services/web-components.js
ndricimrr Aug 28, 2023
e02ea87
Merge branch 'main' into 3387-add-more-apis
ndricimrr Aug 28, 2023
fb5f003
Merge branch 'main' into 3387-add-more-apis
JohannesDoberer Aug 28, 2023
818e70d
fix issue 1
ndricimrr Aug 29, 2023
3371348
Fix issue 2
ndricimrr Aug 29, 2023
656e640
Merge branch 'main' into 3387-add-more-apis
ndricimrr Aug 29, 2023
6e49d51
Fix unit test
ndricimrr Aug 29, 2023
a0b352d
fix container unti tests
ndricimrr Aug 29, 2023
ac78181
Merge branch 'main' into 3387-add-more-apis
ndricimrr Aug 30, 2023
54887ce
sync client permissions
ndricimrr Aug 30, 2023
120c042
json parse and fix test
ndricimrr Aug 30, 2023
440e8d4
set empty object scenario
ndricimrr Aug 30, 2023
55b244f
Fix clientpermissions
ndricimrr Aug 30, 2023
a9c25a1
tabheader
ndricimrr Aug 30, 2023
6e9aade
Merge branch 'main' into 3387-add-more-apis
ndricimrr Sep 7, 2023
9b6f567
fix
ndricimrr Sep 7, 2023
18c18ee
fix 2
ndricimrr Sep 7, 2023
d1177ed
fix 3
ndricimrr Sep 7, 2023
c9cb37a
fix 4
ndricimrr Sep 7, 2023
367e877
fix 5
ndricimrr Sep 7, 2023
c13c2c1
fix 6
ndricimrr Sep 7, 2023
521fbfe
Apply code suggestions
ndricimrr Sep 7, 2023
9d6f501
fix 7
ndricimrr Sep 7, 2023
ad17fec
fix test
ndricimrr Sep 7, 2023
5a08187
prettier
ndricimrr Sep 11, 2023
bacf8ce
Merge branch 'main' into 3387-add-more-apis
JohannesDoberer Sep 18, 2023
436b54b
Merge branch 'main' into 3387-add-more-apis
ndricimrr Sep 27, 2023
0716999
fix tst
ndricimrr Sep 27, 2023
ea3f1d8
Merge branch 'main' into 3387-add-more-apis
ndricimrr Sep 27, 2023
7b1ee08
Update container/src/LuigiCompoundContainer.svelte
ndricimrr Sep 28, 2023
6ae9a77
Update core/src/services/web-components.js
ndricimrr Sep 28, 2023
e0d5640
clean
ndricimrr Sep 28, 2023
e583bf1
Apply suggestions
ndricimrr Sep 28, 2023
7636c2f
add fix
ndricimrr Oct 2, 2023
e7fe4ef
add fix 2
ndricimrr Oct 2, 2023
896ab37
clean
ndricimrr Oct 4, 2023
1134af2
param
ndricimrr Oct 5, 2023
4062492
modal adapt
ndricimrr Oct 6, 2023
2c9a53f
Tab header adjust
ndricimrr Oct 6, 2023
5dd2870
Tab header adjust
ndricimrr Oct 6, 2023
daef5d6
Merge branch 'main' into 3387-add-more-apis
ndricimrr Oct 6, 2023
94e1a1d
move nodeData inside if expensive
ndricimrr Oct 6, 2023
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
22 changes: 22 additions & 0 deletions client/luigi-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,26 @@ export interface LuigiClient {
* @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;
}
24 changes: 24 additions & 0 deletions container/cypress/e2e/wc-container.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,29 @@ describe('Web Container Test', () => {
expect(stub.getCall(1)).to.be.calledWith('LuigiClient.getActiveFeatureToggles()=["ft1","ft2"]');
expect(stub.getCall(2)).to.be.calledWith('LuigiClient.uxManager().getCurrentTheme()=sap_fiori_3');
});

cy.get('[data-test-id="luigi-client-api-test-01"]')
.shadow()
.contains('getCoreSearchParams')
.click()
.then(() => {
expect(stub.getCall(3)).to.be.calledWith('{"test":"searchParam1"}');
});

cy.get('[data-test-id="luigi-client-api-test-01"]')
.shadow()
.contains('getPathParams')
.click()
.then(() => {
expect(stub.getCall(4)).to.be.calledWith('{"path":"param"}');
});

cy.get('[data-test-id="luigi-client-api-test-01"]')
.shadow()
.contains('getClientPermissions')
.click()
.then(() => {
expect(stub.getCall(5)).to.be.calledWith('{"permission":"testPermission"}');
});
});
});
2 changes: 1 addition & 1 deletion container/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"serve": "npm run build && npm run copyLuigiElement && npm run copyBundle && sirv -D test-app --no-clear",
"bundle:watch": "chokidar \"src/**/*.*\" -c \"npm run build && npm run copyBundle\"",
"start": "concurrently -k \"npm run serve\" \"npm run bundle:watch\"",
"cypress-headless": "cypress run",
"cypress-browser": "cypress open --e2e --browser chrome"
"cypress-headless": "cypress run -c video=false",
"cypress-browser": "cypress open --e2e --browser chrome -c video=false"
},
"devDependencies": {
"@babel/node": "7.22.10",
Expand Down Expand Up @@ -52,4 +52,4 @@
"engines": {
"node": ">=18"
}
}
}
15 changes: 15 additions & 0 deletions container/public/LuigiCompoundContainer.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,19 @@ export default class LuigiCompoundContainer extends HTMLElement {
* Manually triggers the micro frontend rendering process when using defer-init attribute
*/
init(): Function;

/**
* The search parameters to be passed to the web-component-based micro frontend.
*/
searchParams: any;

/**
* The path parameters to be passed to the web-component-based micro frontend.
*/
pathParams: any;

/**
* The clientPermissions to be passed to the web-component-based micro frontend.
*/
clientPermissions: any;
ndricimrr marked this conversation as resolved.
Show resolved Hide resolved
}
23 changes: 23 additions & 0 deletions container/public/LuigiContainer.svelte.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
export declare interface NodeParams {
[key: string]: string;
}

export declare interface ClientPermissions {
clientPermissions: {
changeCurrentLocale: string;
urlParameters: Object;
};
}

export default class LuigiContainer extends HTMLElement {
/**
* The URL of the microfrontend to be rendered
Expand Down Expand Up @@ -42,6 +50,21 @@ export default class LuigiContainer extends HTMLElement {
*/
nodeParams: NodeParams;

/**
* The search parameters to be passed to the web-component-based micro frontend.
*/
searchParams: any;

/**
* The path parameters to be passed to the web-component-based micro frontend.
*/
pathParams: any;

/**
* The clientPermissions to be passed to the web-component-based micro frontend.
*/
clientPermissions: ClientPermissions;

/**
* Updates the context of the microfrontend
* @param contextObj The context object to be updated
Expand Down
53 changes: 36 additions & 17 deletions container/src/LuigiCompoundContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,40 +1,59 @@
<svelte:options customElement={{
tag: null,
props: {
viewurl: { type: 'String', reflect: false, attribute: 'viewurl' },
deferInit: { type: 'Boolean', attribute: 'defer-init' },
context: { type: 'String', reflect: false, attribute: 'context' },
compoundConfig: { type: 'Object', reflect: false, attribute: 'compound-config' },
nodeParams: { type: 'Object', reflect: false, attribute: 'node-params' }
}
}} />
<svelte:options
customElement={{
tag: null,
props: {
viewurl: { type: 'String', reflect: false, attribute: 'viewurl' },
deferInit: { type: 'Boolean', attribute: 'defer-init' },
context: { type: 'String', reflect: false, attribute: 'context' },
compoundConfig: {
type: 'Object',
reflect: false,
attribute: 'compound-config'
},
nodeParams: { type: 'Object', reflect: false, attribute: 'node-params' },
searchParams: {
type: 'Object',
reflect: false,
attribute: 'search-params'
},
pathParams: { type: 'Object', reflect: false, attribute: 'path-params' },
clientPermissions: {
type: 'Object',
reflect: false,
attribute: 'client-permissions'
}
}
}}
/>

<script lang="ts">
<script lang="ts">
import { onMount } from 'svelte';
import { ContainerService } from './services/container.service';
import { WebComponentService } from './services/webcomponents.service';
import { Events } from './constants/communication';

export let viewurl: string;
export let context: string;
export let deferInit: boolean;
export let deferInit: boolean;
export let compoundConfig: any;
export let nodeParams: any;
export let searchParams: any;
export let pathParams: any;
export let clientPermissions: any;

ndricimrr marked this conversation as resolved.
Show resolved Hide resolved
let containerInitialized = false;
let mainComponent: HTMLElement;
let eventBusElement: HTMLElement;


const containerService = new ContainerService();
const webcomponentService = new WebComponentService();

// Only needed for get rid of "unused export property" svelte compiler warnings
export const unwarn = () => {
return nodeParams;
}
return nodeParams && searchParams && pathParams && clientPermissions;
};

const initialize = (thisComponent: any) => {
const initialize = (thisComponent: any) => {
if (!compoundConfig || containerInitialized) {
return;
}
Expand Down Expand Up @@ -63,7 +82,7 @@
}
});
containerInitialized = true;
}
};

onMount(async () => {
const thisComponent: any = (mainComponent.getRootNode() as ShadowRoot).host;
Expand Down
85 changes: 62 additions & 23 deletions container/src/LuigiContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
<svelte:options customElement={{
tag: null,
props: {
viewurl: { type: 'String', reflect: false, attribute: 'viewurl' },
deferInit: { type: 'Boolean', attribute: 'defer-init' },
context: { type: 'String', reflect: false, attribute: 'context' },
label: { type: 'String', reflect: false, attribute: 'label' },
webcomponent: { type: 'String', reflect: false, attribute: 'webcomponent' },
locale: { type: 'String', reflect: false, attribute: 'locale' },
theme: { type: 'String', reflect: false, attribute: 'theme' },
activeFeatureToggleList: { type: 'Array', reflect: false, attribute: 'active-feature-toggle-list' },
skipInitCheck: { type: 'Boolean', reflect: false, attribute: 'skip-init-check' },
nodeParams: { type: 'Object', reflect: false, attribute: 'node-params' }
},
extend: (customElementConstructor) => {
let notInitFn = (name) => {
return () => console.warn(name + ' can\'t be called on luigi-container before its micro frontend is attached to the DOM.');
<svelte:options
customElement={{
tag: null,
props: {
viewurl: { type: 'String', reflect: false, attribute: 'viewurl' },
deferInit: { type: 'Boolean', attribute: 'defer-init' },
context: { type: 'String', reflect: false, attribute: 'context' },
label: { type: 'String', reflect: false, attribute: 'label' },
webcomponent: {
type: 'String',
reflect: false,
attribute: 'webcomponent'
},
locale: { type: 'String', reflect: false, attribute: 'locale' },
theme: { type: 'String', reflect: false, attribute: 'theme' },
activeFeatureToggleList: {
type: 'Array',
reflect: false,
attribute: 'active-feature-toggle-list'
},
skipInitCheck: {
type: 'Boolean',
reflect: false,
attribute: 'skip-init-check'
},
nodeParams: { type: 'Object', reflect: false, attribute: 'node-params' },
searchParams: {
type: 'Object',
reflect: false,
attribute: 'search-params'
},
pathParams: { type: 'Object', reflect: false, attribute: 'path-params' },
clientPermissions: {
type: 'Object',
reflect: false,
attribute: 'client-permissions'
}
},
extend: customElementConstructor => {
let notInitFn = name => {
return () =>
console.warn(
name +
" can't be called on luigi-container before its micro frontend is attached to the DOM."
);
};
return class extends customElementConstructor {
sendCustomMessage = notInitFn('sendCustomMessage');
updateContext = notInitFn('updateContext');
Expand All @@ -26,8 +54,8 @@
}
};
}
}} />

}}
/>

<script lang="ts">
import { onMount, onDestroy } from 'svelte';
Expand All @@ -40,12 +68,15 @@
export let context: string;
export let label: string;
export let webcomponent: string;
export let deferInit: boolean;
export let deferInit: boolean;
export let locale: string;
export let theme: string;
export let activeFeatureToggleList: string[];
export let skipInitCheck: boolean;
export let nodeParams: any;
export let searchParams: any;
export let pathParams: any;
export let clientPermissions: any;

let iframeHandle:
| {
Expand All @@ -60,10 +91,18 @@

// Only needed for get rid of "unused export property" svelte compiler warnings
export const unwarn = () => {
return locale && theme && activeFeatureToggleList && nodeParams;
}
return (
locale &&
theme &&
activeFeatureToggleList &&
nodeParams &&
searchParams &&
pathParams &&
clientPermissions
);
};

const initialize = (thisComponent: any) => {
const initialize = (thisComponent: any) => {
if (!containerInitialized) {
thisComponent.sendCustomMessage = (id: string, data?: any) => {
ContainerAPI.sendCustomMessage(
Expand Down
15 changes: 15 additions & 0 deletions container/src/services/webcomponents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ export class WebComponentService {
return;
}
this.dispatchLuigiEvent(Events.SET_ANCHOR_LINK_REQUEST, anchor);
},
getCoreSearchParams: () => {
let result = this.thisComponent.getAttribute('search-params') || {};
ndricimrr marked this conversation as resolved.
Show resolved Hide resolved
result = JSON.parse(result);
return result;
},
getPathParams: () => {
let result = this.thisComponent.getAttribute('path-params') || {};
result = JSON.parse(result);
return result;
},
getClientPermissions: () => {
let result = this.thisComponent.getAttribute('client-permissions') || {};
result = JSON.parse(result);
return result;
}
};
}
Expand Down
Loading