Skip to content

Commit

Permalink
temp: save
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 4, 2024
1 parent 55d9b82 commit 01dbbc1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ import {
AppStatus,
AppUpdatableFields,
AppUpdater,
AppVisibility,
InternalApplicationSetup,
InternalApplicationStart,
Mounter,
NavigateToAppOptions,
} from './types';
import { getLeaveAction, isConfirmAction } from './application_leave';
import { appendAppPath, parseAppUrl, relativeToAbsolute, getAppInfo } from './utils';
import { WorkspacesStart } from '../workspace';

interface SetupDeps {
context: ContextSetup;
Expand All @@ -69,6 +71,7 @@ interface SetupDeps {
interface StartDeps {
http: HttpStart;
overlays: OverlayStart;
workspaces: WorkspacesStart;
}

// Mount functions with two arguments are assumed to expect deprecated `context` object.
Expand Down Expand Up @@ -213,7 +216,7 @@ export class ApplicationService {
};
}

public async start({ http, overlays }: StartDeps): Promise<InternalApplicationStart> {
public async start({ http, overlays, workspaces }: StartDeps): Promise<InternalApplicationStart> {
if (!this.mountContext) {
throw new Error('ApplicationService#setup() must be invoked before start.');
}
Expand Down Expand Up @@ -257,6 +260,13 @@ export class ApplicationService {
const currentAppId = this.currentAppId$.value;
const navigatingToSameApp = currentAppId === appId;
const shouldNavigate = navigatingToSameApp ? true : await this.shouldNavigate(overlays);
const targetApp = applications$.value.get(appId);
if (
workspaces.currentWorkspaceId$.value &&
targetApp?.visibility === AppVisibility.homeOnly
) {
window.location.assign(getAppUrl(availableMounters, appId, path));
}

if (shouldNavigate) {
if (path === undefined) {
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 @@ -51,6 +51,7 @@ export {
AppLeaveConfirmAction,
NavigateToAppOptions,
PublicAppInfo,
AppVisibility,
// Internal types
InternalApplicationSetup,
InternalApplicationStart,
Expand Down
28 changes: 28 additions & 0 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ export enum AppNavLinkStatus {
hidden = 3,
}

/**
* Visibilities of the application
*
* @public
*/
export enum AppVisibility {
/**
* The application visibility will be `both` if the application's {@link AppVisibility} is set to `default` or not set
* which means the application is visible within / out of workspace.
*/
default = 0,
/**
* The application is only visible when user is inside a workspace.
*/
workspaceOnly = 1,
/**
* The application is only visible when user is not in any workspace.
*/
homeOnly = 2,
}

/**
* Defines the list of fields that can be updated via an {@link AppUpdater}.
* @public
Expand Down Expand Up @@ -245,6 +266,13 @@ export interface App<HistoryLocationState = unknown> {
* ```
*/
exactRoute?: boolean;

/**
* The visibility of the application based on workspace.
* Defaulting to `both`
* See {@link AppVisibility}
*/
visibility: AppVisibility;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export class CoreSystem {
overlays,
targetDomElement: notificationsTargetDomElement,
});
const application = await this.application.start({ http, overlays });
const workspaces = this.workspaces.start();
const application = await this.application.start({ http, overlays, workspaces });
const chrome = await this.chrome.start({
application,
docLinks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export class WorkspaceConflictSavedObjectsClientWrapper {
options: SavedObjectsCreateOptions = {}
) => {
const { workspaces, id, overwrite } = options;
if (!id || !overwrite) {
return await wrapperOptions.client.create(type, attributes, options);
}
let savedObjectWorkspaces = options?.workspaces;

/**
Expand Down Expand Up @@ -90,6 +93,9 @@ export class WorkspaceConflictSavedObjectsClientWrapper {
options: SavedObjectsCreateOptions = {}
): Promise<SavedObjectsBulkResponse<T>> => {
const { overwrite, namespace } = options;
if (!overwrite) {
return await wrapperOptions.client.bulkCreate(objects, options);
}
/**
* When overwrite, filter out all the objects that have ids
*/
Expand Down

0 comments on commit 01dbbc1

Please sign in to comment.