Skip to content

Commit

Permalink
Fix #1537 export a serviceUrl function
Browse files Browse the repository at this point in the history
  • Loading branch information
ComLock committed Dec 13, 2024
1 parent 1006e7f commit c799be6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 110 deletions.
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

0 comments on commit c799be6

Please sign in to comment.