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(editor): hide warning area & disable validator #716

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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
4 changes: 2 additions & 2 deletions packages/editor/src/components/WarningArea/ErrorLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DebugTable } from './Table';
import { Box } from '@chakra-ui/react';

export const ErrorLogs: React.FC<Props> = ({ services }) => {
const { validateResult, setSelectedComponentId } = services.editorStore;
const { setSelectedComponentId } = services.editorStore;
const errorColumns = [
{
title: 'Component Id',
Expand Down Expand Up @@ -37,7 +37,7 @@ export const ErrorLogs: React.FC<Props> = ({ services }) => {

return (
<DebugTable
data={validateResult}
data={[]}
pagination={{ hideOnSinglePage: true }}
columns={errorColumns}
emptyMessage="No Errors"
Expand Down
9 changes: 0 additions & 9 deletions packages/editor/src/components/WarningArea/WarningArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
HStack,
IconButton,
Tabs,
Text,
TabPanel,
TabPanels,
TabList,
Expand Down Expand Up @@ -150,14 +149,6 @@ export const WarningArea: React.FC<Props> = observer(({ services }) => {
>
<Tabs h="full" w="full" variant="soft-rounded" colorScheme="gray">
<TabList>
<Tab alignItems="baseline">
<Text fontSize="md" fontWeight="bold">
Errors
</Text>
<Badge ml="1" fontSize="0.8em" colorScheme="red">
{editorStore.validateResult.length}
</Badge>
</Tab>
<Tab>Logs</Tab>
<HStack w="full" justify="end">
{editorStore.isSaved ? savedBadge : unsaveBadge}
Expand Down
8 changes: 1 addition & 7 deletions packages/editor/src/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ export function initSunmaoUIEditor(props: SunmaoUIEditorProps = {}) {
appStorage.app.spec.components
);
const widgetManager = new WidgetManager();
const editorStore = new EditorStore(
eventBus,
registry,
stateManager,
appStorage,
appModelManager
);
const editorStore = new EditorStore(eventBus, registry, stateManager, appStorage);
editorStore.eleMap = ui.eleMap;

const services = {
Expand Down
36 changes: 1 addition & 35 deletions packages/editor/src/services/EditorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { isEqual } from 'lodash';

import { EventBusType } from './eventBus';
import { AppStorage } from './AppStorage';
import type { SchemaValidator, ValidateErrorResult } from '../validator';
import { ExplorerMenuTabs, ToolMenuTabs } from '../constants/enum';

import { AppModelManager } from '../operations/AppModelManager';
import type { Metadata } from '@sunmao-ui/core';

type EditingTarget = {
Expand All @@ -29,7 +27,6 @@ export class EditorStore {
explorerMenuTab = ExplorerMenuTabs.UI_TREE;
toolMenuTab = ToolMenuTabs.INSERT;
viewStateComponentId = '';
validateResult: ValidateErrorResult[] = [];
// current editor editing target(app or module)
currentEditingTarget: EditingTarget = {
kind: 'app',
Expand All @@ -45,31 +42,19 @@ export class EditorStore {
// when componentsChange event is triggered, currentComponentsVersion++
currentComponentsVersion = 0;
lastSavedComponentsVersion = 0;
schemaValidator?: SchemaValidator;

private isDataSourceTypeCache: Record<string, boolean> = {};

constructor(
private eventBus: EventBusType,
private registry: RegistryInterface,
private stateManager: StateManagerInterface,
public appStorage: AppStorage,
private appModelManager: AppModelManager
public appStorage: AppStorage
) {
this.globalDependencies = this.stateManager.dependencies;
const dependencyNames = Object.keys(this.globalDependencies);
// dynamic load validator
import('../validator').then(({ SchemaValidator: SchemaValidatorClass }) => {
this.setSchemaValidator(new SchemaValidatorClass(this.registry, dependencyNames));
// do first validation
this.setValidateResult(
this.schemaValidator!.validate(this.appModelManager.appModel)
);
});
makeAutoObservable(this, {
eleMap: false,
components: observable.shallow,
schemaValidator: observable.ref,
setComponents: action,
setHoverComponentId: action,
setDragOverComponentId: action,
Expand Down Expand Up @@ -133,17 +118,6 @@ export class EditorStore {
}
);

reaction(
() => this.components,
() => {
if (this.schemaValidator) {
this.setValidateResult(
this.schemaValidator.validate(this.appModelManager.appModel)
);
}
}
);

this.updateCurrentEditingTarget('app', this.app.version, this.app.metadata.name);
}

Expand Down Expand Up @@ -287,10 +261,6 @@ export class EditorStore {
this.lastSavedComponentsVersion = val;
};

setValidateResult = (validateResult: ValidateErrorResult[]) => {
this.validateResult = validateResult;
};

setExplorerMenuTab = (val: ExplorerMenuTabs) => {
this.explorerMenuTab = val;
};
Expand All @@ -307,10 +277,6 @@ export class EditorStore {
this.isDraggingNewComponent = val;
};

setSchemaValidator = (val: SchemaValidator) => {
this.schemaValidator = val;
};

setModuleDependencies = (exampleProperties?: Record<string, unknown>) => {
const evaledDependencies = this.stateManager.deepEval(exampleProperties || {}, {
fallbackWhenError: () => undefined,
Expand Down
Loading