feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
20
frontend/packages/workflow/test-run/src/hooks/index.ts
Normal file
20
frontend/packages/workflow/test-run/src/hooks/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { useTestRunService } from './use-test-run-service';
|
||||
export { useFormSubmitting } from './use-form-submitting';
|
||||
export { useDocumentContentChange } from './use-document-content-change';
|
||||
export { useTestRunReporterService } from './use-test-run-reporter-service';
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useService } from '@flowgram-adapter/free-layout-editor';
|
||||
import {
|
||||
WorkflowDocument,
|
||||
type WorkflowContentChangeEvent,
|
||||
type WorkflowContentChangeType,
|
||||
} from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
type Listener = (e: WorkflowContentChangeEvent) => void;
|
||||
|
||||
/**
|
||||
* 监听 document content 变动的 hook
|
||||
*/
|
||||
export const useDocumentContentChange = (
|
||||
/** 监听器 */
|
||||
listener: Listener,
|
||||
/** 监听类型,默认监听所有 */
|
||||
listenType?: WorkflowContentChangeType,
|
||||
) => {
|
||||
const workflowDocument = useService<WorkflowDocument>(WorkflowDocument);
|
||||
|
||||
useEffect(() => {
|
||||
const disposable = workflowDocument.onContentChange(e => {
|
||||
if (!listenType || listenType === e.type) {
|
||||
listener(e);
|
||||
}
|
||||
});
|
||||
|
||||
return () => disposable.dispose();
|
||||
}, [workflowDocument, listener, listenType]);
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import { type Form } from '@formily/core';
|
||||
|
||||
export const useFormSubmitting = (form: Form<any> | null) => {
|
||||
const [submitting, setSubmitting] = useState(!!form?.submitting);
|
||||
|
||||
useEffect(() => {
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
const unsubscribe = form.subscribe(payload => {
|
||||
if (payload.type === 'onFormSubmitStart') {
|
||||
setSubmitting(true);
|
||||
} else if (payload.type === 'onFormSubmitEnd') {
|
||||
setSubmitting(false);
|
||||
}
|
||||
});
|
||||
return () => form.unsubscribe(unsubscribe);
|
||||
}, [form]);
|
||||
|
||||
return submitting;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useService } from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
import { TestRunReporterService } from '../plugins/test-run-plugin';
|
||||
|
||||
export const useTestRunReporterService = () =>
|
||||
useService<TestRunReporterService>(TestRunReporterService);
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useService } from '@flowgram-adapter/free-layout-editor';
|
||||
|
||||
import { TestRunService } from '../plugins/test-run-plugin';
|
||||
|
||||
export const useTestRunService = () =>
|
||||
useService<TestRunService>(TestRunService);
|
||||
Reference in New Issue
Block a user