Skip to content

Commit

Permalink
feat: update to WorkspaceVisibility
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Apr 9, 2024
1 parent feca487 commit 00682b2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
InternalApplicationStart,
Mounter,
NavigateToAppOptions,
WorkspaceAccessibility,
} from './types';
import { getLeaveAction, isConfirmAction } from './application_leave';
import { appendAppPath, parseAppUrl, relativeToAbsolute, getAppInfo } from './utils';
Expand Down Expand Up @@ -262,8 +263,11 @@ export class ApplicationService {

if (shouldNavigate) {
const targetApp = applications$.value.get(appId);
if (workspaces.currentWorkspaceId$.value && targetApp?.workspaceless) {
// If user is inside a workspace and the target app is workspaceless
if (
workspaces.currentWorkspaceId$.value &&
targetApp?.workspaceAccessibility === WorkspaceAccessibility.NO
) {
// If user is inside a workspace and the target app is not accessible within a workspace
// refresh the page by doing a hard navigation
window.location.assign(
http.basePath.prepend(getAppUrl(availableMounters, appId, path), {
Expand Down Expand Up @@ -310,7 +314,7 @@ export class ApplicationService {
) => {
const targetApp = applications$.value.get(appId);
const relUrl = http.basePath.prepend(getAppUrl(availableMounters, appId, path), {
withoutClientBasePath: targetApp?.workspaceless,
withoutClientBasePath: targetApp?.workspaceAccessibility === WorkspaceAccessibility.NO,
});
return absolute ? relativeToAbsolute(relUrl) : relUrl;
},
Expand Down
1 change: 1 addition & 0 deletions src/core/public/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export {
// Internal types
InternalApplicationSetup,
InternalApplicationStart,
WorkspaceAccessibility,
} from './types';
18 changes: 17 additions & 1 deletion src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ export type AppUpdatableFields = Pick<App, 'status' | 'navLinkStatus' | 'tooltip
*/
export type AppUpdater = (app: App) => Partial<AppUpdatableFields> | undefined;

/**
* Visibilities of the application based on if user is within a workspace
*
* @public
*/
export enum WorkspaceAccessibility {
/**
* The application is not accessible when user is in a workspace.
*/
NO = 0,
/**
* The application is only accessible when user is in a workspace.
*/
YES = 1,
}

/**
* @public
*/
Expand Down Expand Up @@ -249,7 +265,7 @@ export interface App<HistoryLocationState = unknown> {
/**
* Prevent the page to be accessible when inside a workspace. Defaults to `false`.
*/
workspaceless?: boolean;
workspaceAccessibility?: WorkspaceAccessibility;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/core/public/chrome/nav_links/to_nav_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@
* under the License.
*/

import { PublicAppInfo, AppNavLinkStatus, AppStatus } from '../../application';
import {
PublicAppInfo,
AppNavLinkStatus,
AppStatus,
WorkspaceAccessibility,
} from '../../application';
import { IBasePath } from '../../http';
import { NavLinkWrapper } from './nav_link';
import { appendAppPath } from '../../application/utils';

export function toNavLink(app: PublicAppInfo, basePath: IBasePath): NavLinkWrapper {
const useAppStatus = app.navLinkStatus === AppNavLinkStatus.default;
let relativeBaseUrl = basePath.prepend(app.appRoute!);
if (app.workspaceless) {
if (app.workspaceAccessibility === WorkspaceAccessibility.NO) {
relativeBaseUrl = basePath.prepend(app.appRoute!, { withoutClientBasePath: true });
}
const url = relativeToAbsolute(appendAppPath(relativeBaseUrl, app.defaultPath));
Expand Down
1 change: 1 addition & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export {
AppUpdater,
ScopedHistory,
NavigateToAppOptions,
WorkspaceAccessibility,
} from './application';

export {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { DataPublicPluginStart } from '../../data/public';
import { TelemetryPluginStart } from '../../telemetry/public';
import { UsageCollectionSetup } from '../../usage_collection/public';
import { UrlForwardingSetup, UrlForwardingStart } from '../../url_forwarding/public';
import { AppNavLinkStatus, AppVisibility } from '../../../core/public';
import { AppNavLinkStatus, WorkspaceAccessibility } from '../../../core/public';
import { PLUGIN_ID, HOME_APP_BASE_PATH } from '../common/constants';
import { DataSourcePluginStart } from '../../data_source/public';

Expand Down Expand Up @@ -130,7 +130,7 @@ export class HomePublicPlugin
const { renderApp } = await import('./application');
return await renderApp(params.element, coreStart, params.history);
},
workspaceless: true,
workspaceAccessibility: WorkspaceAccessibility.NO,
});
urlForwarding.forwardApp('home', 'home');

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CoreStart,
LinksUpdater,
Plugin,
WorkspaceAccessibility,
WorkspaceObject,
} from '../../../core/public';
import {
Expand Down Expand Up @@ -162,7 +163,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
const { renderListApp } = await import('./application');
return mountWorkspaceApp(params, renderListApp);
},
workspaceless: true,
workspaceAccessibility: WorkspaceAccessibility.NO,
});

// create
Expand All @@ -176,7 +177,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> {
const { renderCreatorApp } = await import('./application');
return mountWorkspaceApp(params, renderCreatorApp);
},
workspaceless: true,
workspaceAccessibility: WorkspaceAccessibility.NO,
});

// update
Expand Down

0 comments on commit 00682b2

Please sign in to comment.