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

feat: introduces the new api endpoint applicationName #1791

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
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
49 changes: 43 additions & 6 deletions src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@
}
};

const getApplicationConfigurationByName = async (shogunClient: SHOGunAPIClient, applicationName: string) => {
try {
Logger.info(`Loading application with name: ${applicationName}`);

const application = await shogunClient.application().findOneByName(applicationName);

Check failure on line 190 in src/bootstrap.tsx

View workflow job for this annotation

GitHub Actions / build

Property 'findOneByName' does not exist on type 'ApplicationService<Application<DefaultApplicationClientConfig<DefaultMapView, DefaultLegalConfig, DefaultApplicationTheme>, DefaultLayerTree, DefaultApplicationLayerConfig<...>, DefaultApplicationToolConfig>>'.

Logger.info(`Successfully loaded application with name: ${applicationName}`);

return application;
} catch (error) {
if ((error as Error).message.indexOf('401') > -1) {
throw new Error(LoadingErrorCode.APP_UNAUTHORIZED);
}
Logger.error(`Error while loading application with name: ${applicationName}: ${error}`);
}
};

const getStaticApplicationConfiguration = async (staticAppContextUrl: string) => {
try {
Logger.info('Loading static application');
Expand Down Expand Up @@ -678,13 +695,18 @@
}

const applicationIdString = UrlUtil.getQueryParam(window.location.href, 'applicationId');
const applicationName = UrlUtil.getQueryParam(window.location.href, 'applicationName');

const applicationId = applicationIdString ? parseInt(applicationIdString, 10) : undefined;

if (!applicationId && !ClientConfiguration.enableFallbackConfig && !ClientConfiguration.staticAppConfigUrl) {
if (!applicationId && !applicationName && !ClientConfiguration.enableFallbackConfig && !ClientConfiguration.staticAppConfigUrl) {
throw new Error(LoadingErrorCode.APP_ID_NOT_SET);
}
let appConfig;
if (applicationId && client) {
if (applicationName && client) {
appConfig = await getApplicationConfigurationByName(client, applicationName);
setLoadingImage(applicationName, appConfig?.clientConfig?.theme?.logoPath);
} else if (applicationId && client) {
appConfig = await getApplicationConfiguration(client, applicationId);
setLoadingImage(applicationId, appConfig?.clientConfig?.theme?.logoPath);
} else if (ClientConfiguration.staticAppConfigUrl) {
Expand Down Expand Up @@ -760,14 +782,22 @@

const plugins = await loadPlugins(map, appConfig?.toolConfig);

if (!appConfig) {
if (!appConfig && applicationId) {
notification.error({
message: i18n.t('Index.applicationLoadErrorMessage'),
description: i18n.t('Index.applicationLoadErrorDescription', {
applicationId: applicationId
}),
duration: 0
});
} else if (!appConfig && applicationName) {
notification.error({
message: i18n.t('Index.applicationLoadErrorMessage'),
description: i18n.t('Index.applicationLoadByNameErrorDescription', {
applicationName: applicationName
}),
duration: 0
});
}

root.render(
Expand Down Expand Up @@ -843,10 +873,17 @@

if ((error as Error)?.message === LoadingErrorCode.APP_CONFIG_NOT_FOUND) {
const appId = UrlUtil.getQueryParam(window.location.href, 'applicationId');
const appName = UrlUtil.getQueryParam(window.location.href, 'applicationName');

errorDescription = i18n.t('Index.errorDescriptionAppConfigNotFound', {
applicationId: appId
});
if (appId) {
errorDescription = i18n.t('Index.errorDescriptionAppConfigNotFound', {
applicationId: appId
});
} else if (appName) {
errorDescription = i18n.t('Index.errorDescriptionAppConfigByNameNotFound', {
applicationName: appName
});
}
}

if ((error as Error)?.message === LoadingErrorCode.APP_CONFIG_STATIC_NOT_FOUND) {
Expand Down
12 changes: 8 additions & 4 deletions src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ export default {
Index: {
applicationLoadErrorMessage: 'Fehler beim Laden der Applikation',
applicationLoadErrorDescription:
'Die Applikation mit der ID {{applicationId}} konnte nicht geladen werden. ' +
'Die Standardkonfiguration wird stattdessen geladen.',
'Die Applikation mit der ID {{applicationId}} konnte nicht geladen werden.',
applicationLoadByNameErrorMessage:
'Die Applikation mit dem Namen {{applicationName}} konnte nicht geladen werden.',
errorMessage: 'Fehler beim Laden der Applikation',
errorDescription: 'Aufgrund eines unerwarteten Fehlers konnte die Applikation nicht geladen werden.',
errorDescriptionAppIdNotSet: 'Keine Applikations-ID angegeben. Bitte geben Sie die ID als Abfrageparameter an, z.B. ?applicationId=1909',
errorDescriptionAppConfigNotFound: 'Die Applikation mit der ID {{applicationId}} konnte nicht geladen werden.',
errorDescriptionAppConfigByNameNotFound: 'Die Applikation mit dem Namen {{applicationName}} konnte nicht geladen werden.',
errorDescriptionAppConfigStaticNotFound: 'Die Konfiguration der Applikation konnte nicht geladen werden.',
permissionDeniedUnauthorized: 'Dies ist keine öffentliche Applikation. Anmeldung erforderlich.',
rerouteToLoginPage: 'Zur Anmeldeseite.'
Expand Down Expand Up @@ -456,12 +458,14 @@ export default {
Index: {
applicationLoadErrorMessage: 'Error while loading the application',
applicationLoadErrorDescription:
'The application with ID {{applicationId}} could not be loaded correctly. ' +
'You\'re seeing the default application configuration.',
'The application with ID {{applicationId}} could not be loaded correctly.',
applicationLoadByNameErrorMessage:
'The application with the name {{applicationName}} could not be loaded correctly.',
errorMessage: 'Error while loading the application',
errorDescription: 'An unexpected error occurred while loading the application.',
errorDescriptionAppIdNotSet: 'No application ID given. Please provide the ID as query parameter, e.g. ?applicationId=1909',
errorDescriptionAppConfigNotFound: 'The application with ID {{applicationId}} could not be loaded correctly.',
errorDescriptionAppConfigByNameNotFound: 'The application with the name {{applicationName}} could not be loaded correctly.',
errorDescriptionAppConfigStaticNotFound: 'The configuration of the application could not be loaded correctly.',
permissionDeniedUnauthorized: 'This application is not public. Authentication required.',
rerouteToLoginPage: 'To login page.'
Expand Down
Loading