Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoBingyu committed May 29, 2023
2 parents f72d6df + 8384aff commit e4c83a3
Show file tree
Hide file tree
Showing 79 changed files with 1,506 additions and 417 deletions.
7 changes: 4 additions & 3 deletions clients/components/data-filter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type FieldCondition = {

export type RefProps = {
empty: () => void;
getDataValues: () => FilterConfig;
getDataValues: (data?: any) => FilterConfig;
validate: () => Promise<boolean>;
}

Expand Down Expand Up @@ -158,9 +158,9 @@ function DataFilter({
setConditions(conditions.filter(({ id }) => _id !== id));
};

const getDataValues = (): FilterConfig => {
const getDataValues = (data = {}): FilterConfig => {
if (conditions.length === 0) {
return { condition: [], tag };
return { condition: [], tag, ...data };
}

const formData = getValues();
Expand Down Expand Up @@ -191,6 +191,7 @@ function DataFilter({
return {
condition: _conditions,
tag,
...data,
};
};

Expand Down
7 changes: 5 additions & 2 deletions clients/components/file-upload/uploader/useFileStore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import FileStore from './store';
import type { FileStoreProps } from './store';

export default function useFileStore(props: FileStoreProps): FileStore {
const [store] = useState<FileStore>(new FileStore(props));
const [store, setStore] = useState<FileStore>(new FileStore(props));
useEffect(()=>{
setStore(new FileStore(props));
}, [props.files.length]);
return store;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';

import Modal from '@c/modal';
import Button from '@c/button';
import Checkbox from '@c/checkbox';
import PageLoading from '@c/page-loading';
import DataFilter, { RefProps } from '@c/data-filter';
import { FILTER_FIELD } from '@c/data-filter/utils';
Expand All @@ -18,6 +19,7 @@ type Props = {
currentFormSchema?: ISchema;
customSchemaFields?: SchemaFieldItem[];
filterFunc?: (field: SchemaFieldItem) => boolean;
showSelectAll?: any;
}

type FieldsProps = {
Expand Down Expand Up @@ -56,13 +58,13 @@ function FilterConfig({
const [schemaFields, setSchemaFields] = useState<SchemaFieldItem[]>([]);
const [currentFields, setCurrentFields] = useState<SchemaFieldItem[]>([]);
const dataFilterRef = useRef<RefProps>(null);

const [selectAll, setSelectAll] = useState(value?.selectAll);
const allowSelect = (!!tableID && !!appID) || (customSchemaFields && customSchemaFields.length);

const handleSave = (): void => {
dataFilterRef.current?.validate().then((flag) => {
if (flag) {
onChange(dataFilterRef.current?.getDataValues() as FilterConfig);
onChange(dataFilterRef.current?.getDataValues({ selectAll }) as FilterConfig);
setVisible(false);
}
});
Expand Down Expand Up @@ -92,6 +94,10 @@ function FilterConfig({
}
}, [allowSelect, visible, customSchemaFields]);

const handleSelectAll = ()=>{
setSelectAll(!selectAll);
};

return (
<>
<Button onClick={() => setVisible(true)}>设置过滤规则</Button>
Expand Down Expand Up @@ -119,6 +125,17 @@ function FilterConfig({
<div className='p-20'>
{!allowSelect && (<div>请选择关联表</div>)}
{loading && allowSelect && (<PageLoading />)}
{
value?.showSelectAll &&
(<div className='flex mb-10'>
<Checkbox
checked={selectAll}
onChange={handleSelectAll}
onClick={(e) => e.stopPropagation()}
/>
<span className='ml-6'>默认选择全部</span>
</div>)
}
{!loading && allowSelect && (
<DataFilter
initConditions={value?.condition}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import React, { useEffect, useState } from 'react';
import { Column } from 'react-table';
import { get } from 'lodash';
import cs from 'classnames';
Expand All @@ -13,6 +14,8 @@ import { schemaToMap } from '@lib/schema-convert';
import { ISchemaFieldComponentProps } from '@formily/react-schema-renderer';

import SelectRecordsModal from './select-records-modal';
import { fetchFormDataList } from '@lib/http-client-form';
import { toEs } from '@c/data-filter/utils';

type Props = {
defaultValues: Record<string, any>[];
Expand Down Expand Up @@ -60,9 +63,12 @@ function AssociatedRecords({
readOnly,
className,
}: Props): JSX.Element {
const { selectAll = false } = filterConfig || {};
const [showSelectModal, setShowSelectModal] = useState(false);
const [selectedValue, setSelectValue] = useState(multiple ? '' : defaultValues[0]?._id);
const [index, setIndex] = useState(0);
const [selectedValue, setSelectValue] = useState((multiple || selectAll) ? '' : defaultValues[0]?._id);
const tableColumns = computeTableColumns(associatedTable, columns);

!readOnly && tableColumns.push({
id: 'remove',
Header: '操作',
Expand All @@ -82,6 +88,14 @@ function AssociatedRecords({
},
});

useEffect(()=>{
if (index > 1) return;
if (selectAll && index === 1) {
onChange(value);
}
setIndex(index + 1);
}, [JSON.stringify(value)]);

return (
<div className={cs('w-full', className)}>
<Table
Expand All @@ -102,12 +116,12 @@ function AssociatedRecords({
appID={appID}
tableID={tableID}
filterConfig={filterConfig}
multiple={multiple}
multiple={multiple || selectAll}
associatedTable={associatedTable}
columns={columns}
selectedValue={selectedValue}
onSubmit={(newSelectedRecords) => {
if (multiple) {
if (multiple || selectAll) {
const selecteds = value.concat(
newSelectedRecords.filter(({ _id }) => value.findIndex(({ _id: id }) => _id === id) < 0),
);
Expand All @@ -127,20 +141,45 @@ function AssociatedRecords({
function AssociatedRecordsFields(props: Partial<ISchemaFieldComponentProps>): JSX.Element {
const componentProps = props.props['x-component-props'];
// todo handle error case
const [selectAllData, setSelectAllData] = useState<any>([]);
const [hasChanged, setHasChanged] = useState<any>(false);
const { selectAll = false } = componentProps?.filterConfig || {};
const { appID, tableID, isNew } = componentProps;
const { condition = [], tag = 'must' } = componentProps.filterConfig || {};
const getSelectAllData = async ()=>{
const res = await fetchFormDataList(appID, tableID, {
sort: ['-created_at'],
page: 1,
size: 1000,
query: toEs({ tag, condition: [...condition] }),
}).catch((e) => {
console.log(e);
});
setSelectAllData(res?.entities || []);
};

useEffect(()=>{
selectAll && getSelectAllData();
}, []);

return (
<AssociatedRecords
className={props.props.className}
defaultValues={props.value || []}
defaultValues={(selectAll && !hasChanged && isNew) ? selectAllData : (props.value || [])}
// defaultValues={props.value || []}
readOnly={props.props.readOnly}
appID={componentProps.appID}
tableID={componentProps.tableID}
columns={componentProps.columns || []}
multiple={componentProps.multiple || false}
filterConfig={componentProps.filterConfig}
value={props.value}
value={(selectAll && !hasChanged && isNew) ? selectAllData : props.value}
// value={props.value}
associatedTable={componentProps.associatedTable}
onChange={(selectedKeys) => props?.mutators?.change(selectedKeys)}
onChange={(selectedKeys) => {
setHasChanged(true);
props?.mutators?.change(selectedKeys);
}}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export default function SelectRecordsModal({
const tableRef: React.Ref<any> = useRef<Ref>();
const [selected, setSelected] = useState<Record<string, any>[]>(defaultValues || []);
const defaultSelectIDs = selected.map(({ _id }) => _id);

const handleSubmit = (): void => {
if (!tableRef.current) {
return;
}

onSubmit(selected);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,22 @@ function AssociatedRecordsConfig({ initialValue, onChange }: Props): JSX.Element

return (
<SchemaForm
initialValues={initialValue}
initialValues={{
...initialValue,
filterConfig: {
...initialValue.filterConfig,
showSelectAll: true,
},
}}
actions={actions}
effects={formModelEffect}
onChange={(values) => onChange({ ...initialValue, ...values })}
onChange={(values) => {
const _initialValue = JSON.parse(JSON.stringify(initialValue));
const _values = JSON.parse(JSON.stringify(values));
delete _initialValue?.filterConfig?.showSelectAll;
delete _values?.filterConfig?.showSelectAll;
onChange({ ..._initialValue, ..._values });
}}
components={COMPONENTS}
schema={configSchema}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const Picker = ({ value = [], onChange, isMy, rangeList }: Props) => {

const handleChange = useCallback((list: EmployeeOrDepartmentOfRole[]) => {
valueListRef.current = list;
onChange(list);
// onChange(list);
}, [onChange]);

const handleSubmit = useCallback(() => {
onChange(valueListRef.current);
const list = JSON.parse(JSON.stringify(valueListRef.current));
onChange(list);
setDefaultValue(valueListRef.current);
close();
}, [onChange, close]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,22 @@ const UserPicker = ({

const { options } = componentsProps;

const handleValue = ()=>{
const data = value?.filter((item: any)=>{
return options?.find((option: any)=>option.value === item.value);
});
if (!data?.length) {
onChange && onChange(data);
}
return data;
};

return (
<Select
{...componentsProps}
labelInValue
allowClear
value={value}
value={handleValue()}
options={undefined}
disabled={!editable}
onChange={handleChange}
Expand Down
3 changes: 3 additions & 0 deletions clients/components/form-builder/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type DragPosition = 'up' | 'down' | 'left' | 'right';
type FilterConfig = {
condition: Condition[];
tag: FilterTag;
showSelectAll?: boolean;
selectAll?: boolean;
}

type FilterTag = 'should' | 'must';
Expand All @@ -52,6 +54,7 @@ type IteratISchema = ISchema & { id: string; componentName?: string; }
type LabelValue = {
label: string;
value: string;
count?: number;
}

type FormDataValue =
Expand Down
3 changes: 2 additions & 1 deletion clients/components/process-node-status/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
&-review-write,
&-in_review-write,
&-review-read,
&-in_review-read {
&-in_review-read,
&-todo_fill_in {
background: var(--yellow-600)
}

Expand Down
4 changes: 4 additions & 0 deletions clients/components/process-node-status/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable quote-props */
import React from 'react';
import cs from 'classnames';

Expand All @@ -14,6 +15,8 @@ interface Props {
}

const statusMap = {
Pending: '进行中',
Finish: '已完成',
REVIEW: '进行中',
IN_REVIEW: '进行中',
AGREE: '通过',
Expand All @@ -30,6 +33,7 @@ const statusMap = {
'REVIEW-READ': '待阅示',
'IN_REVIEW-READ': '待阅示',
'SEND_BACK-SEND_BACK': '待补充',
'TODO_FILL_IN': '待填写',
};

function Status({ label, value, className }: Props): JSX.Element {
Expand Down
8 changes: 7 additions & 1 deletion clients/components/radio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, {
import cs from 'classnames';

import { uuid } from '@lib/utils';
import BtnBadge from '@c/btn-badge';

export type Props = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
onChange?: (value: string | number | boolean) => void;
Expand All @@ -19,11 +20,12 @@ export type Props = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTM
disabled?: boolean;
radioClass?: string;
className?: string;
count?: number ;
};

function InternalRadio(props: Props, ref?: Ref<HTMLInputElement>): JSX.Element {
const {
defaultChecked, error, className, radioClass, onChange, label, checked: isChecked, disabled, ...inputProps
defaultChecked, error, className, radioClass, onChange, label, checked: isChecked, disabled, count, ...inputProps
} = props;
const [checked, setChecked] = useState(defaultChecked);
const id = uuid();
Expand Down Expand Up @@ -85,6 +87,10 @@ function InternalRadio(props: Props, ref?: Ref<HTMLInputElement>): JSX.Element {
'cursor-not-allowed': disabled,
})
}>{label}</label>
{
!!count &&
<BtnBadge count={count} className="radio-btnBadge relative text-white" />
}
</div>
);
}
Expand Down
13 changes: 12 additions & 1 deletion clients/components/radio/radio-button-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@
padding: 5px 16px;
color: var(--gray-600);
}

.radio-btnBadge{
margin-right: 5px;
font-size: 12px;
border-radius: 8px 8px 8px 2px;
padding: 4px;
border: none;
height: 16px;
}

}

.radio-group-btn-active{
border: 1px solid var(--blue-600);
label{
color: var(--blue-600);
}
}
}

Loading

0 comments on commit e4c83a3

Please sign in to comment.