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

Fix #1537 export a serviceUrl function #1538

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
89 changes: 0 additions & 89 deletions src/main/resources/lib/enonic/react4xp/asset/assetUrl.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/resources/lib/enonic/react4xp/assetUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { AssetUrlParams } from '@enonic-types/lib-portal'; // Might be deprecated in XP8.

import { getUrlType } from '/lib/enonic/react4xp/React4xp/utils/getUrlType';
import { serviceUrl } from '/lib/enonic/react4xp/serviceUrl';


export interface R4xAssetUrlParams extends AssetUrlParams {
service?: string;
}


export function assetUrl({
application = app.name,
params,
path = '/',
service = 'asset',
type = getUrlType()
}: R4xAssetUrlParams): string {
return serviceUrl({
application,
params,
path,
service,
type
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,22 @@ import type { UrlType } from '@enonic-types/lib-react4xp';

import { getUrlType } from '/lib/enonic/react4xp/React4xp/utils/getUrlType';

interface ServiceUrlBuilder {
setApplication(value: string): void;

setPath(value: string): void;

setType(value: string): void;

setServiceName(value: string): void;

createUrl(): string;
}
import { serviceUrl } from '/lib/enonic/react4xp/serviceUrl';

/*
* Initialize the root path of a service URL for a site mount.
*/
export function initServiceUrlRoot({
serviceName = '',
urlType // default is app.config['react4xp.urlType'] || 'server'
urlType = getUrlType()
}: {
serviceName?: string,
urlType?: UrlType
} = {}) {
const bean: ServiceUrlBuilder = __.newBean('com.enonic.lib.react4xp.url.ServiceUrlBuilder');

bean.setApplication(app.name);
bean.setPath('/');
bean.setType(getUrlType(urlType));
bean.setServiceName(serviceName);

return bean.createUrl();
return serviceUrl({
application: app.name,
path: '/',
service: serviceName,
type: urlType
});
}
2 changes: 2 additions & 0 deletions src/main/resources/lib/enonic/react4xp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export {
getExecutorUrl,
render,
} from '/lib/enonic/react4xp/React4xp';
export {assetUrl} from '/lib/enonic/react4xp/assetUrl';
export {DataFetcher} from '/lib/enonic/react4xp/DataFetcher';
export {serviceUrl} from '/lib/enonic/react4xp/serviceUrl';
37 changes: 37 additions & 0 deletions src/main/resources/lib/enonic/react4xp/serviceUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ServiceUrlParams } from '@enonic-types/lib-portal'; // Might be deprecated in XP8.

import { getUrlType } from '/lib/enonic/react4xp/React4xp/utils/getUrlType';


interface ServiceUrlBuilder {
setApplication(value: string): void;
setParams(value: object): void;
setPath(value: string): void;
setType(value: string): void;
setServiceName(value: string): void;
createUrl(): string;
}


export interface R4xServiceUrlParams extends ServiceUrlParams {
path?: string;
}


export function serviceUrl({
application = app.name,
params,
path = '/',
service,
type = getUrlType()
}: R4xServiceUrlParams): string {
const bean: ServiceUrlBuilder = __.newBean('com.enonic.lib.react4xp.url.ServiceUrlBuilder');

bean.setApplication(application);
bean.setParams(params);
bean.setPath(path);
bean.setType(type);
bean.setServiceName(service);

return bean.createUrl();
}
2 changes: 1 addition & 1 deletion src/main/resources/types/React4xp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
PageContributions,
Request
} from '@enonic-types/core';
import type { AssetUrlParams } from '@enonic-types/lib-portal';
import type { AssetUrlParams } from '@enonic-types/lib-portal'; // Might be deprecated in XP8.
import type { Cache } from './Cache';

type OneOrMore<T> = T | T[]
Expand Down
Loading