fix(plugin-workflow): fix minors ui issues (#1635)

* fix(plugin-workflow): fix minors ui issues

* fix(plugin-workflow): add refresh after title changed back

* fix(plugin-workflow): fix collection fields variable
This commit is contained in:
Junyi 2023-04-02 12:24:25 +07:00 committed by GitHub
parent 3f81d7cd7d
commit 822099271a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 63 deletions

View File

@ -141,22 +141,21 @@ export function WorkflowCanvas() {
onClick={onSwitchVersion} onClick={onSwitchVersion}
defaultSelectedKeys={[`${workflow.id}`]} defaultSelectedKeys={[`${workflow.id}`]}
className={cx(workflowVersionDropdownClass)} className={cx(workflowVersionDropdownClass)}
> items={revisions.sort((a, b) => b.id - a.id).map((item, index) => ({
{revisions.sort((a, b) => b.id - a.id).map((item, index) => ( key: `${item.id}`,
<Menu.Item icon: item.current ? <RightOutlined /> : null,
key={`${item.id}`} label: (
icon={item.current ? <RightOutlined /> : null} <span className={classnames({
className={classnames({
executed: item.executed, executed: item.executed,
unexecuted: !item.executed, unexecuted: !item.executed,
enabled: item.enabled, enabled: item.enabled,
})} })}>
> <strong>{`#${item.id}`}</strong>
<strong>{`#${item.id}`}</strong> <time>{(new Date(item.createdAt)).toLocaleString()}</time>
<time>{(new Date(item.createdAt)).toLocaleString()}</time> </span>
</Menu.Item> )
))} }))}
</Menu> />
} }
> >
<Button type="text"> <Button type="text">

View File

@ -276,9 +276,9 @@ export const workflowSchema: ISchema = {
type: 'primary', type: 'primary',
}, },
properties: { properties: {
modal: { drawer: {
type: 'void', type: 'void',
'x-component': 'Action.Modal', 'x-component': 'Action.Drawer',
'x-decorator': 'Form', 'x-decorator': 'Form',
'x-decorator-props': { 'x-decorator-props': {
useValues: '{{ cm.useValuesFromRecord }}', useValues: '{{ cm.useValuesFromRecord }}',
@ -299,7 +299,7 @@ export const workflowSchema: ISchema = {
}, },
footer: { footer: {
type: 'void', type: 'void',
'x-component': 'Action.Modal.Footer', 'x-component': 'Action.Drawer.Footer',
properties: { properties: {
cancel: { cancel: {
title: '{{ t("Cancel") }}', title: '{{ t("Cancel") }}',

View File

@ -47,23 +47,6 @@ export const workflowPageClass = css`
export const workflowVersionDropdownClass = css` export const workflowVersionDropdownClass = css`
.ant-dropdown-menu-item{ .ant-dropdown-menu-item{
strong{
font-weight: normal;
}
&.enabled{
strong{
font-weight: bold;
}
}
&.unexecuted{
strong{
font-style: italic;
}
}
.ant-dropdown-menu-title-content{ .ant-dropdown-menu-title-content{
text-align: right; text-align: right;
@ -72,6 +55,22 @@ export const workflowVersionDropdownClass = css`
color: #999; color: #999;
font-size: 80%; font-size: 80%;
} }
strong{
font-weight: normal;
}
> .enabled{
strong{
font-weight: bold;
}
}
> .unexecuted{
strong{
font-style: italic;
}
}
} }
} }
`; `;

View File

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import { css, cx } from "@emotion/css"; import { css, cx } from "@emotion/css";
import { ISchema, useForm } from "@formily/react"; import { ISchema, useForm } from "@formily/react";
import { Registry } from "@nocobase/utils/client"; import { Registry } from "@nocobase/utils/client";
@ -131,6 +131,12 @@ export const TriggerConfig = () => {
const api = useAPIClient(); const api = useAPIClient();
const compile = useCompile(); const compile = useCompile();
const { workflow, refresh } = useFlowContext(); const { workflow, refresh } = useFlowContext();
const [editingTitle, setEditingTitle] = useState<string>('');
const [editingConfig, setEditingConfig] = useState(false);
useEffect(() => {
setEditingTitle(workflow.title ?? typeTitle);
}, [workflow]);
if (!workflow || !workflow.type) { if (!workflow || !workflow.type) {
return null; return null;
} }
@ -139,9 +145,6 @@ export const TriggerConfig = () => {
const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}'; const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}';
const titleText = `${lang('Trigger')}: ${compile(typeTitle)}`; const titleText = `${lang('Trigger')}: ${compile(typeTitle)}`;
const [editingTitle, setEditingTitle] = useState<string>(title ?? typeTitle);
const [editingConfig, setEditingConfig] = useState(false);
async function onChangeTitle(next) { async function onChangeTitle(next) {
const t = next || typeTitle; const t = next || typeTitle;
setEditingTitle(t); setEditingTitle(t);

View File

@ -8,7 +8,7 @@ export type VariableOption = {
key: string; key: string;
value: string; value: string;
label: string; label: string;
children?: VariableOption[]; children?: VariableOption[] | null;
}; };
const VariableTypes = [ const VariableTypes = [
@ -97,32 +97,35 @@ export function useWorkflowVariableOptions() {
return options; return options;
} }
export function useCollectionFieldOptions(props) { function useCollectionNormalFields(collection) {
const { fields, collection, types } = props;
const compile = useCompile();
const { getCollectionFields } = useCollectionManager(); const { getCollectionFields } = useCollectionManager();
const result = filterTypedFields(fields ?? getCollectionFields(collection), types).map((field) => ({ const fields = getCollectionFields(collection);
label: compile(field.uiSchema?.title || field.name), return fields.filter(field => field.interface);
key: field.name, }
value: field.name,
children: ['linkTo', 'belongsTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(field.type) export function useCollectionFieldOptions(options, depth = 1): VariableOption[] {
? getCollectionFields(field.target) const { fields, collection, types } = options;
?.filter((subField) => subField.interface && (!subField.target || subField.type === 'belongsTo')) const compile = useCompile();
.map((subField) => const result: VariableOption[] = [];
subField.type === 'belongsTo' filterTypedFields((fields ?? useCollectionNormalFields(collection)), types)
? { .forEach(field => {
label: `${compile(subField.uiSchema?.title || subField.name)} ID`, const label = compile(field.uiSchema?.title || field.name);
key: subField.foreignKey, if (field.type === 'belongsTo') {
value: subField.foreignKey, result.push({
} label: `${label} ID`,
: { key: field.foreignKey,
label: compile(subField.uiSchema?.title || subField.name), value: field.foreignKey,
key: subField.name, });
value: subField.name, }
}, result.push({
) label,
: null, key: field.name,
})); value: field.name,
children: ['linkTo', 'belongsTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(field.type) && depth > 0
? useCollectionFieldOptions({ collection: field.target, types }, depth - 1)
: null
});
});
return result; return result;
} }