tachybase_todo/packages/plugins/map/src/client/components/Designer.tsx

148 lines
4.4 KiB
TypeScript
Raw Normal View History

import { Field } from '@formily/core';
import { ISchema, useField, useFieldSchema } from '@formily/react';
import {
GeneralSchemaDesigner,
feat: support List and Grid Card block (#1753) * feat: support details block * feat: rename to list * fix: imports * feat: improve list block * feat: support title hidden * fix: showTitle default value * feat: support table column actions * feat: support appendsOnDemand * feat: reuse same schema items * feat: shouldn't display pagination when pages only one * feat: block order * feat: support card list * fix: appends on demand * fix: remove unused code * fix: params * fix: improve default pageSize * feat: improve performance * feat: add title designer * feat: improve huge performance * fix: better key * feat: improve schema perf * feat: improve initializer * fix: improve grid perf * fix: avoid haven't properties * feat: support automatic run service when params changed * fix: revert params * fix: grid col width * refactor: improve CardList performance * fix: initializer related * feat: i18n supports * fix: improve get schema * fix: create new form * fix: revert code * feat: css improve * fix: i18n copy * refactor: the CardList rename to GridCard * feat: remove AssociationFilter item * fix: edit and view data is incorrect * feat: remove bulk actions * feat: improve action bar * feat: supports configuration of columns with different screen sizes * fix: incorrect place to save the template * feat: keep height in all card * fix: remove console * fix: rename * refactor: improve GridCard implementation * feat: support import/export actions * fix: remove padding when actions is empty * fix: remove incorrect import * fix: remove unused props * fix: action place * feat: improve column count * refactor: remove appendsOnDemand, and use useAssociationNames instated it * fix: incorrect component --------- Co-authored-by: chenos <chenlinxh@gmail.com>
2023-05-16 09:05:47 +08:00
GeneralSchemaItems,
SchemaSettings,
isPatternDisabled,
useCollection,
useCollectionManager,
useDesignable,
useFormBlockContext,
} from '@nocobase/client';
import set from 'lodash/set';
import React from 'react';
import { useMapTranslation } from '../locale';
const Designer = () => {
const { getCollectionJoinField } = useCollectionManager();
const { getField } = useCollection();
const { form } = useFormBlockContext();
const field = useField<Field>();
const fieldSchema = useFieldSchema();
const { t } = useMapTranslation();
const { dn, refresh } = useDesignable();
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
const originalTitle = collectionField?.uiSchema?.title;
const initialValue = {
title: field.title === originalTitle ? undefined : field.title,
};
if (!field.readPretty) {
initialValue['required'] = field.required;
}
let readOnlyMode = 'editable';
if (fieldSchema['x-disabled'] === true) {
readOnlyMode = 'readonly';
}
if (fieldSchema['x-read-pretty'] === true) {
readOnlyMode = 'read-pretty';
}
return (
<GeneralSchemaDesigner>
feat: support List and Grid Card block (#1753) * feat: support details block * feat: rename to list * fix: imports * feat: improve list block * feat: support title hidden * fix: showTitle default value * feat: support table column actions * feat: support appendsOnDemand * feat: reuse same schema items * feat: shouldn't display pagination when pages only one * feat: block order * feat: support card list * fix: appends on demand * fix: remove unused code * fix: params * fix: improve default pageSize * feat: improve performance * feat: add title designer * feat: improve huge performance * fix: better key * feat: improve schema perf * feat: improve initializer * fix: improve grid perf * fix: avoid haven't properties * feat: support automatic run service when params changed * fix: revert params * fix: grid col width * refactor: improve CardList performance * fix: initializer related * feat: i18n supports * fix: improve get schema * fix: create new form * fix: revert code * feat: css improve * fix: i18n copy * refactor: the CardList rename to GridCard * feat: remove AssociationFilter item * fix: edit and view data is incorrect * feat: remove bulk actions * feat: improve action bar * feat: supports configuration of columns with different screen sizes * fix: incorrect place to save the template * feat: keep height in all card * fix: remove console * fix: rename * refactor: improve GridCard implementation * feat: support import/export actions * fix: remove padding when actions is empty * fix: remove incorrect import * fix: remove unused props * fix: action place * feat: improve column count * refactor: remove appendsOnDemand, and use useAssociationNames instated it * fix: incorrect component --------- Co-authored-by: chenos <chenlinxh@gmail.com>
2023-05-16 09:05:47 +08:00
<GeneralSchemaItems />
{form && !form?.readPretty && !isPatternDisabled(fieldSchema) && (
<SchemaSettings.SelectItem
key="pattern"
title={t('Pattern')}
options={[
{ label: t('Editable'), value: 'editable' },
{ label: t('Readonly'), value: 'readonly' },
{ label: t('Easy-reading'), value: 'read-pretty' },
]}
value={readOnlyMode}
onChange={(v) => {
const schema: ISchema = {
['x-uid']: fieldSchema['x-uid'],
};
switch (v) {
case 'readonly': {
fieldSchema['x-read-pretty'] = false;
fieldSchema['x-disabled'] = true;
schema['x-read-pretty'] = false;
schema['x-disabled'] = true;
field.readPretty = false;
field.disabled = true;
break;
}
case 'read-pretty': {
fieldSchema['x-read-pretty'] = true;
fieldSchema['x-disabled'] = false;
schema['x-read-pretty'] = true;
schema['x-disabled'] = false;
field.readPretty = true;
break;
}
default: {
fieldSchema['x-read-pretty'] = false;
fieldSchema['x-disabled'] = false;
schema['x-read-pretty'] = false;
schema['x-disabled'] = false;
field.readPretty = false;
field.disabled = false;
break;
}
}
dn.emit('patch', {
schema,
});
dn.refresh();
}}
/>
)}
<SchemaSettings.ModalItem
key="map-zoom"
title={t('Set default zoom level')}
schema={
{
type: 'object',
title: t('Set default zoom level'),
properties: {
zoom: {
title: t('Zoom'),
default: field.componentProps.zoom || 13,
description: t('The default zoom level of the map'),
'x-decorator': 'FormItem',
'x-component': 'InputNumber',
'x-component-props': {
precision: 0,
},
},
},
} as ISchema
}
onSubmit={({ zoom }) => {
if (zoom) {
set(fieldSchema, 'x-component-props.zoom', zoom);
Object.assign(field.componentProps, fieldSchema['x-component-props']);
dn.emit('patch', {
schema: {
'x-uid': fieldSchema['x-uid'],
'x-component-props': field.componentProps,
},
});
}
dn.refresh();
}}
/>
<SchemaSettings.Remove
key="remove"
removeParentsIfNoChildren
confirm={{
title: t('Delete field'),
}}
breakRemoveOn={{
'x-component': 'Grid',
}}
/>
</GeneralSchemaDesigner>
);
};
export default Designer;