mirror of
https://github.com/NetEase/tango.git
synced 2026-09-03 06:33:51 +08:00
fix: allow reload state tree & display pageStore in variable tree (#135)
* fix: update state tree display * fix: allow reload state tree * fix: update action props * fix: display pageStore in variable tree
This commit is contained in:
@@ -35,8 +35,14 @@ export const useWorkspaceData = () => {
|
||||
const modelVariables: IVariableTreeNode[] = []; // 绑定变量列表
|
||||
const storeActionVariables: IVariableTreeNode[] = []; // 模型中的所有 actions
|
||||
const storeVariables: IVariableTreeNode[] = []; // 模型中的所有变量
|
||||
const pageStoreVariables: IVariableTreeNode[] = []; // 页面中的组件实例变量
|
||||
const serviceVariables: IVariableTreeNode[] = []; // 服务中的所有变量
|
||||
|
||||
pageStoreVariables.push({
|
||||
title: 'pageStore',
|
||||
key: 'pageStore',
|
||||
});
|
||||
|
||||
Object.values(workspace.storeModules).forEach((file) => {
|
||||
const prefix = `stores.${file.name}`;
|
||||
const states: IVariableTreeNode[] = file.states.map((item) => ({
|
||||
@@ -109,6 +115,7 @@ export const useWorkspaceData = () => {
|
||||
}
|
||||
|
||||
let expressionVariables: IVariableTreeNode[] = [
|
||||
buildVariableOptions('当前页面组件实例', '$pageStore', pageStoreVariables),
|
||||
buildVariableOptions('数据模型', '$stores', storeVariables),
|
||||
buildVariableOptions('服务函数', '$services', serviceVariables),
|
||||
];
|
||||
|
||||
@@ -23,11 +23,7 @@ export function OutlinePanel({ showStateView = true, ...treeProps }: OutlineView
|
||||
>
|
||||
<ComponentsTree {...treeProps} />
|
||||
</CollapsePanel>
|
||||
{showStateView && (
|
||||
<CollapsePanel title="页面状态" stickyHeader maxHeight="90%" overflowY="auto">
|
||||
<StateTree />
|
||||
</CollapsePanel>
|
||||
)}
|
||||
{showStateView && <StateTree />}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import React, { useEffect, useReducer } from 'react';
|
||||
import { observer } from '@music163/tango-context';
|
||||
import { isFunction, isObject, pick } from '@music163/tango-helpers';
|
||||
import { JsonView } from '@music163/tango-ui';
|
||||
import { CollapsePanel, IconButton, JsonView } from '@music163/tango-ui';
|
||||
import { ReloadOutlined } from '@ant-design/icons';
|
||||
import { useSandboxQuery } from '../../context';
|
||||
|
||||
function processTango(obj: any = {}, index = 0) {
|
||||
@@ -26,7 +27,7 @@ export const StateTree = observer(() => {
|
||||
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
||||
const tangoContext = pick(sandboxQuery.window['tango'] || {}, [
|
||||
'stores',
|
||||
'page',
|
||||
'pageStore',
|
||||
'services',
|
||||
'config',
|
||||
]);
|
||||
@@ -34,6 +35,7 @@ export const StateTree = observer(() => {
|
||||
forceUpdate();
|
||||
};
|
||||
useEffect(() => {
|
||||
// FIXME: 优化这段代码,应该监听 tangoContext 的变化,来刷新
|
||||
const settingForm = document.querySelector('.SettingPanel');
|
||||
const ob = new MutationObserver(callback);
|
||||
if (settingForm) {
|
||||
@@ -48,13 +50,31 @@ export const StateTree = observer(() => {
|
||||
};
|
||||
}, []);
|
||||
return (
|
||||
<JsonView
|
||||
src={processTango(tangoContext)}
|
||||
collapsed={1}
|
||||
name="tango"
|
||||
displayObjectSize={false}
|
||||
indentWidth={2}
|
||||
enableCopy
|
||||
/>
|
||||
<CollapsePanel
|
||||
title="页面状态"
|
||||
stickyHeader
|
||||
maxHeight="90%"
|
||||
overflowY="auto"
|
||||
extra={
|
||||
<IconButton
|
||||
tooltip="同步状态"
|
||||
size="small"
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
forceUpdate();
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<JsonView
|
||||
src={processTango(tangoContext)}
|
||||
collapsed={1}
|
||||
name="tango"
|
||||
displayObjectSize={false}
|
||||
indentWidth={2}
|
||||
enableCopy
|
||||
/>
|
||||
</CollapsePanel>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ export function isNil(val: any) {
|
||||
* @returns
|
||||
*/
|
||||
export function isStoreVariablePath(key: string) {
|
||||
return /^stores\.[a-zA-Z0-9]+\.\w+$/.test(key);
|
||||
return key === 'pageStore' || /^stores\.[a-zA-Z0-9]+\.\w+$/.test(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,6 +68,7 @@ export interface ActionProps extends HTMLCoralProps<any> {
|
||||
*/
|
||||
className?: string;
|
||||
children?: React.ReactNode;
|
||||
onClick?: React.MouseEventHandler;
|
||||
}
|
||||
|
||||
export function Action({
|
||||
|
||||
Reference in New Issue
Block a user