Skip to content

Commit

Permalink
refactor: defaultViewType renamed to defaultViewName
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Aug 14, 2023
1 parent 8117b45 commit 89b666d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/shell/src/model/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Window implements IPublicModelWindow {
}

changeViewType(viewName: string) {
this[windowSymbol].changeViewType(viewName, false);
this[windowSymbol].changeViewName(viewName, false);
}

onChangeViewType(fun: (viewName: string) => void): IPublicTypeDisposable {
Expand Down
8 changes: 7 additions & 1 deletion packages/types/src/shell/type/resource-type-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ export interface IPublicResourceTypeConfig {
/** 资源 icon 标识 */
icon?: React.ReactElement;

/**
* 默认视图类型
* @deprecated
*/
defaultViewType?: string;

/** 默认视图类型 */
defaultViewType: string;
defaultViewName: string;

/** 资源视图 */
editorViews: IPublicTypeEditorView[];
Expand Down
8 changes: 4 additions & 4 deletions packages/workspace/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface IBaseResource<T> extends IBaseModelResource<T> {

get editorViews(): IPublicTypeEditorView[];

get defaultViewType(): string;
get defaultViewName(): string | undefined;

getEditorView(name: string): IPublicTypeEditorView | undefined;

Expand All @@ -41,7 +41,7 @@ export class Resource implements IResource {
}

get viewName() {
return this.resourceData.viewName || (this.resourceData as any).viewType || this.defaultViewType;
return this.resourceData.viewName || (this.resourceData as any).viewType || this.defaultViewName;
}

get description() {
Expand Down Expand Up @@ -116,8 +116,8 @@ export class Resource implements IResource {
return this.resourceTypeInstance.editorViews;
}

get defaultViewType() {
return this.resourceTypeInstance.defaultViewType;
get defaultViewName() {
return this.resourceTypeInstance.defaultViewName || this.resourceTypeInstance.defaultViewType;
}

getEditorView(name: string) {
Expand Down
16 changes: 8 additions & 8 deletions packages/workspace/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types'
interface IWindowCOnfig {
title: string | undefined;
options?: Object;
viewType?: string | undefined;
viewName?: string | undefined;
sleep?: boolean;
}

Expand All @@ -19,7 +19,7 @@ export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'chan

editorView: IViewContext;

changeViewType: (name: string, ignoreEmit?: boolean) => void;
changeViewName: (name: string, ignoreEmit?: boolean) => void;

initReady: boolean;

Expand Down Expand Up @@ -130,7 +130,7 @@ export class EditorWindow implements IEditorWindow {
this.workspace.emitWindowRendererReady();
});
this.url = await this.resource.url();
this.setDefaultViewType();
this.setDefaultViewName();
this.initReady = true;
this.workspace.checkWindowQueue();
this.sleep = false;
Expand All @@ -146,7 +146,7 @@ export class EditorWindow implements IEditorWindow {
const name = editorViews[i].viewName;
await this.initViewType(name);
if (!this.editorView) {
this.changeViewType(name);
this.changeViewName(name);
}
}
};
Expand All @@ -166,13 +166,13 @@ export class EditorWindow implements IEditorWindow {
}
for (let i = 0; i < editorViews.length; i++) {
const name = editorViews[i].viewName;
this.changeViewType(name);
this.changeViewName(name);
await this.editorViews.get(name)?.init();
}
};

setDefaultViewType = () => {
this.changeViewType(this.config.viewType ?? this.resource.defaultViewType);
setDefaultViewName = () => {
this.changeViewName(this.config.viewName ?? this.resource.defaultViewName!);
};

get resourceType() {
Expand All @@ -188,7 +188,7 @@ export class EditorWindow implements IEditorWindow {
this.editorViews.set(name, editorView);
};

changeViewType = (name: string, ignoreEmit: boolean = true) => {
changeViewName = (name: string, ignoreEmit: boolean = true) => {
this.editorView?.setActivate(false);
this.editorView = this.editorViews.get(name)!;

Expand Down
10 changes: 5 additions & 5 deletions packages/workspace/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Workspace implements IWorkspace {
name: string;
title: string;
options: Object;
viewType?: string;
viewName?: string;
}[] = [];

constructor(
Expand All @@ -114,7 +114,7 @@ export class Workspace implements IWorkspace {

const windowInfo = this.windowQueue.shift();
if (windowInfo) {
this.openEditorWindow(windowInfo.name, windowInfo.title, windowInfo.options, windowInfo.viewType);
this.openEditorWindow(windowInfo.name, windowInfo.title, windowInfo.options, windowInfo.viewName);
}
}

Expand Down Expand Up @@ -228,10 +228,10 @@ export class Workspace implements IWorkspace {
this.window?.updateState(WINDOW_STATE.active);
}

async openEditorWindow(name: string, title: string, options: Object, viewType?: string, sleep?: boolean) {
async openEditorWindow(name: string, title: string, options: Object, viewName?: string, sleep?: boolean) {
if (this.window && !this.window?.initReady && !sleep) {
this.windowQueue.push({
name, title, options, viewType,
name, title, options, viewName,
});
return;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ export class Workspace implements IWorkspace {
const window = new EditorWindow(resource, this, {
title,
options,
viewType,
viewName,
sleep,
});
this.windows = [...this.windows, window];
Expand Down

0 comments on commit 89b666d

Please sign in to comment.