fix: add displayName (#3628)

* fix: context add displayName

* fix: observer add displayName

* fix: memo component add displayName

* fix: forwordRef component add displayName
This commit is contained in:
jack zhang 2024-03-06 18:22:31 +08:00 committed by GitHub
parent bccde967cc
commit 454d1d34ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
135 changed files with 1089 additions and 868 deletions

View File

@ -14,6 +14,7 @@ import { useApp } from '../application';
import { useDataSourceKey } from '../data-source/data-source/DataSourceProvider';
export const ACLContext = createContext<any>({});
ACLContext.displayName = 'ACLContext';
// TODO: delete thisreplace by `ACLPlugin`
export const ACLProvider = (props) => {
@ -90,6 +91,7 @@ export const useACLContext = () => {
};
export const ACLActionParamsContext = createContext<any>({});
ACLActionParamsContext.displayName = 'ACLActionParamsContext';
export const useACLRolesCheck = () => {
const ctx = useContext(ACLContext);

View File

@ -31,6 +31,7 @@ const getChildrenKeys = (data = [], arr = []) => {
};
const SettingMenuContext = createContext(null);
SettingMenuContext.displayName = 'SettingMenuContext';
export const SettingCenterProvider = (props) => {
const configureItems = useContext(SettingsCenterContext);

View File

@ -4,6 +4,7 @@ import { useRequest } from '../../api-client';
import { useAdminSchemaUid } from '../../hooks';
const MenuItemsContext = createContext(null);
MenuItemsContext.displayName = 'MenuItemsContext';
export const toItems = (properties = {}) => {
const items = [];

View File

@ -14,6 +14,7 @@ export const SettingCenterPermissionProvider = (props) => {
};
export const PermissionContext = createContext<any>(null);
PermissionContext.displayName = 'PermissionContext';
export const PermissionProvider = (props) => {
const api = useAPIClient();

View File

@ -7,6 +7,7 @@ import { PermissionProvider, SettingCenterPermissionProvider } from '../Configur
import { roleSchema } from './schemas/roles';
const AvailableActionsContext = createContext([]);
AvailableActionsContext.displayName = 'AvailableActionsContext';
const AvailableActionsProver: React.FC = (props) => {
const { data, loading } = useRequest<{

View File

@ -22,6 +22,7 @@ const toActionMap = (arr: any[]) => {
};
export const RoleResourceCollectionContext = createContext<any>({});
RoleResourceCollectionContext.displayName = 'RoleResourceCollectionContext';
export const RolesResourcesActions = connect((props) => {
const { styles } = useStyles();

View File

@ -4,6 +4,7 @@ import { FormProvider, SchemaComponent } from '../../schema-component';
import { scopesSchema } from './schemas/scopes';
const RolesResourcesScopesSelectedRowKeysContext = createContext(null);
RolesResourcesScopesSelectedRowKeysContext.displayName = 'RolesResourcesScopesSelectedRowKeysContext';
const RolesResourcesScopesSelectedRowKeysProvider: React.FC = (props) => {
const [keys, setKeys] = useState([]);

View File

@ -7,6 +7,7 @@ import { Plugin } from '../application/Plugin';
import { loadConstrueLocale } from './loadConstrueLocale';
export const AppLangContext = createContext<any>({});
AppLangContext.displayName = 'AppLangContext';
export const useAppLangContext = () => {
return useContext(AppLangContext);

View File

@ -2,3 +2,4 @@ import { createContext } from 'react';
import { APIClient } from './APIClient';
export const APIClientContext = createContext<APIClient>(new APIClient());
APIClientContext.displayName = 'APIClientContext';

View File

@ -3,6 +3,7 @@ import { useRequest } from '../api-client';
import { useAppSpin } from '../application/hooks/useAppSpin';
export const CurrentAppInfoContext = createContext(null);
CurrentAppInfoContext.displayName = 'CurrentAppInfoContext';
export const useCurrentAppInfo = () => {
return useContext<{

View File

@ -45,6 +45,7 @@ export class PluginSettingsManager {
protected settings: Record<string, PluginSettingOptions> = {};
protected aclSnippets: string[] = [];
public app: Application;
private cachedList = {};
constructor(_pluginSettings: Record<string, PluginSettingOptions>, app: Application) {
this.app = app;
@ -141,11 +142,16 @@ export class PluginSettingsManager {
}
getList(filterAuth = true): PluginSettingsPageType[] {
return Array.from(new Set(Object.values(this.settings).map((item) => item.topLevelName)))
const cacheKey = JSON.stringify(filterAuth);
if (this.cachedList[cacheKey]) return this.cachedList[cacheKey];
return (this.cachedList[cacheKey] = Array.from(
new Set(Object.values(this.settings).map((item) => item.topLevelName)),
)
.sort((a, b) => a.localeCompare(b)) // sort by name
.map((name) => this.get(name, filterAuth))
.filter(Boolean)
.sort((a, b) => (a.sort || 0) - (b.sort || 0));
.sort((a, b) => (a.sort || 0) - (b.sort || 0)));
}
getAclSnippets() {

View File

@ -8,7 +8,8 @@ export interface AppComponentProps {
app: Application;
}
export const AppComponent: FC<AppComponentProps> = observer((props) => {
export const AppComponent: FC<AppComponentProps> = observer(
(props) => {
const { app } = props;
const handleErrors = useCallback((error: Error, info: { componentStack: string }) => {
console.error(error);
@ -36,4 +37,6 @@ export const AppComponent: FC<AppComponentProps> = observer((props) => {
</ApplicationContext.Provider>
</ErrorBoundary>
);
});
},
{ displayName: 'AppComponent' },
);

View File

@ -2,3 +2,4 @@ import { createContext } from 'react';
import { Application } from './Application';
export const ApplicationContext = createContext<Application>(null);
ApplicationContext.displayName = 'ApplicationContext';

View File

@ -13,7 +13,8 @@ import { SchemaInitializerOptions } from '../types';
const defaultWrap = (s: ISchema) => s;
export function withInitializer<T>(C: ComponentType<T>) {
const WithInitializer = observer((props: SchemaInitializerOptions<T>) => {
const WithInitializer = observer(
(props: SchemaInitializerOptions<T>) => {
const { designable, insertAdjacent } = useDesignable();
const { isInSubTable } = useFlag() || {};
const {
@ -118,8 +119,8 @@ export function withInitializer<T>(C: ComponentType<T>) {
)}
</SchemaInitializerContext.Provider>
);
});
WithInitializer.displayName = `WithInitializer(${C.displayName || C.name})`;
},
{ displayName: `WithInitializer(${C.displayName || C.name})` },
);
return WithInitializer;
}

View File

@ -11,7 +11,7 @@ export * from './useAriaAttributeOfMenuItem';
export function useSchemaInitializerMenuItems(items: any[], name?: string, onClick?: (args: any) => void) {
const getMenuItems = useGetSchemaInitializerMenuItems(onClick);
return getMenuItems(items, name);
return useMemo(() => getMenuItems(items, name), [getMenuItems, items, name]);
}
export function useGetSchemaInitializerMenuItems(onClick?: (args: any) => void) {

View File

@ -13,3 +13,4 @@ export const SchemaSettingsIcon: FC<SchemaSettingOptions> = React.memo((props) =
const style = useMemo(() => ({ cursor: 'pointer', fontSize: 12 }), []);
return <MenuOutlined role="button" style={style} aria-label={getAriaLabel('schema-settings', name)} />;
});
SchemaSettingsIcon.displayName = 'SchemaSettingsIcon';

View File

@ -3,6 +3,7 @@ import React, { createContext, useContext } from 'react';
import { useRequest } from '../api-client';
export const AsyncDataContext = createContext<Result<any, any> & { state?: any; setState?: any }>(null);
AsyncDataContext.displayName = 'AsyncDataContext';
export interface AsyncDataProviderProps {
value?: any;

View File

@ -35,7 +35,9 @@ import { useDataBlockSourceId } from './hooks/useDataBlockSourceId';
* @deprecated
*/
export const BlockResourceContext = createContext(null);
BlockResourceContext.displayName = 'BlockResourceContext';
export const BlockAssociationContext = createContext(null);
BlockAssociationContext.displayName = 'BlockAssociationContext';
/**
* @deprecated
@ -50,6 +52,7 @@ export const BlockRequestContext_deprecated = createContext<{
__parent?: any;
updateAssociationValues?: any[];
}>({});
BlockRequestContext_deprecated.displayName = 'BlockRequestContext_deprecated';
export const useBlockResource = () => {
const resource = useDataBlockResource();
@ -209,6 +212,7 @@ const BlockContext = createContext<{
/** 用以区分区块的标识 */
name: string;
}>(null);
BlockContext.displayName = 'BlockContext';
export const useBlockContext = () => {
return useContext(BlockContext);

View File

@ -9,6 +9,7 @@ import { BlockProvider, useBlockRequestContext } from './BlockProvider';
import { useParsedFilter } from './hooks';
export const DetailsBlockContext = createContext<any>({});
DetailsBlockContext.displayName = 'DetailsBlockContext';
const InternalDetailsBlockProvider = (props) => {
const { action, readPretty } = props;

View File

@ -12,6 +12,7 @@ import { TemplateBlockProvider } from './TemplateBlockProvider';
import { FormActiveFieldsProvider } from './hooks/useFormActiveFields';
export const FormBlockContext = createContext<any>({});
FormBlockContext.displayName = 'FormBlockContext';
const InternalFormBlockProvider = (props) => {
const ctx = useFormBlockContext();

View File

@ -10,6 +10,7 @@ import { BlockProvider, useBlockRequestContext } from './BlockProvider';
import { useFormBlockContext } from './FormBlockProvider';
export const FormFieldContext = createContext<any>({});
FormFieldContext.displayName = 'FormFieldContext';
const InternalFormFieldProvider = (props) => {
const { action, readPretty, fieldName } = props;
@ -75,6 +76,7 @@ const InternalFormFieldProvider = (props) => {
};
export const WithoutFormFieldResource = createContext(null);
WithoutFormFieldResource.displayName = 'WithoutFormFieldResource';
export const FormFieldProvider = (props) => {
return (

View File

@ -9,6 +9,8 @@ import { BlockProvider, RenderChildrenWithAssociationFilter, useBlockRequestCont
import { findFilterTargets, useParsedFilter } from './hooks';
export const TableBlockContext = createContext<any>({});
TableBlockContext.displayName = 'TableBlockContext';
export function getIdsWithChildren(nodes) {
const ids = [];
if (nodes) {

View File

@ -7,6 +7,7 @@ import { useFormBlockContext } from './FormBlockProvider';
import { useFormFieldContext } from './FormFieldProvider';
export const TableFieldContext = createContext<any>({});
TableFieldContext.displayName = 'TableFieldContext';
const InternalTableFieldProvider = (props) => {
const { params = {}, showIndex, dragSort, fieldName } = props;
@ -122,6 +123,7 @@ export class TableFieldResource {
}
export const WithoutTableFieldResource = createContext(null);
WithoutTableFieldResource.displayName = 'WithoutTableFieldResource';
export const TableFieldProvider = (props) => {
return (

View File

@ -20,7 +20,9 @@ type Params = {
};
export const TableSelectorContext = createContext<any>({});
TableSelectorContext.displayName = 'TableSelectorContext';
const TableSelectorParamsContext = createContext<Params>({}); // 用于传递参数
TableSelectorParamsContext.displayName = 'TableSelectorParamsContext';
type TableSelectorProviderProps = {
params: Record<string, any>;

View File

@ -5,6 +5,7 @@ const TemplateBlockContext = createContext<{
templateFinshed?: boolean;
onTemplateSuccess?: Function;
}>({});
TemplateBlockContext.displayName = 'TemplateBlockContext';
export const useTemplateBlockContext = () => {
return useContext(TemplateBlockContext);

View File

@ -12,6 +12,7 @@ const CollectionHistoryContext = createContext<CollectionHistoryContextValue>({
historyCollections: [],
refreshCH: () => undefined,
});
CollectionHistoryContext.displayName = 'CollectionHistoryContext';
export const CollectionHistoryProvider: React.FC = (props) => {
const api = useAPIClient();

View File

@ -51,6 +51,4 @@ const Summary = observer(
{ displayName: 'Summary' },
);
Summary.displayName = 'Summary';
export default Summary;

View File

@ -8,6 +8,7 @@ import { useAPIClient, useRequest } from '../api-client';
export const ResourceActionContext = createContext<
Result<any, any> & { state?: any; setState?: any; dragSort?: boolean; defaultRequest?: any }
>(null);
ResourceActionContext.displayName = 'ResourceActionContext';
interface ResourceActionProviderProps {
type?: 'association' | 'collection';
@ -18,6 +19,7 @@ interface ResourceActionProviderProps {
}
const ResourceContext = createContext<any>(null);
ResourceContext.displayName = 'ResourceContext';
const CollectionResourceActionProvider = (props) => {
const { collection, request, uid, dragSort } = props;

View File

@ -1,3 +1,4 @@
import { createContext } from 'react';
export const CollectionCategroriesContext = createContext({ data: [], refresh: () => {} });
CollectionCategroriesContext.displayName = 'CollectionCategroriesContext';

View File

@ -69,6 +69,7 @@ const collection: CollectionOptions = {
};
export const DataSourceContext_deprecated = createContext(null);
DataSourceContext_deprecated.displayName = 'DataSourceContext_deprecated';
const useSelectedRowKeys = () => {
const ctx = useContext(DataSourceContext_deprecated);

View File

@ -100,7 +100,8 @@ const getDefaultCollectionFields = (presetFields, values) => {
// 其他
return defaults;
};
export const PresetFields = observer((props: any) => {
export const PresetFields = observer(
(props: any) => {
const { getInterface } = useCollectionManager_deprecated();
const form = useForm();
const compile = useCompile();
@ -211,4 +212,6 @@ export const PresetFields = observer((props: any) => {
}}
/>
);
});
},
{ displayName: 'PresetFields' },
);

View File

@ -73,7 +73,8 @@ const useSourceFieldsOptions = () => {
return data;
};
export const FieldsConfigure = observer(() => {
export const FieldsConfigure = observer(
() => {
const { t } = useTranslation();
const [dataSource, setDataSource] = useState([]);
const { data: res, error, loading } = useAsyncData();
@ -291,4 +292,6 @@ export const FieldsConfigure = observer(() => {
rowKey="name"
/>
);
});
},
{ displayName: 'FieldsConfigure' },
);

View File

@ -4,7 +4,8 @@ import { Table } from 'antd';
import { Schema, observer, useForm } from '@formily/react';
import { useTranslation } from 'react-i18next';
export const PreviewTable = observer(() => {
export const PreviewTable = observer(
() => {
const { data: res, loading, error } = useAsyncData();
const { data } = res || {};
const { t } = useTranslation();
@ -55,4 +56,6 @@ export const PreviewTable = observer(() => {
rowKey="key"
/>
);
});
},
{ displayName: 'PreviewTable' },
);

View File

@ -12,6 +12,7 @@ export interface AssociationProviderProps {
}
const ParentCollectionContext = createContext<Collection>(null);
ParentCollectionContext.displayName = 'ParentCollectionContext';
const ParentCollectionProvider = (props) => {
const collection = useCollection();

View File

@ -13,6 +13,7 @@ export const DocumentTitleContext = createContext<DocumentTitleContextProps>({
title: null,
setTitle() {},
});
DocumentTitleContext.displayName = 'DocumentTitleContext';
export const DocumentTitleProvider: React.FC<{ addonBefore?: string; addonAfter?: string }> = (props) => {
const { addonBefore, addonAfter } = props;

View File

@ -58,6 +58,7 @@ interface FilterContextValue {
}
const FilterContext = createContext<FilterContextValue>(null);
FilterContext.displayName = 'FilterContext';
/**
* 使

View File

@ -15,6 +15,7 @@ const AppInner = memo(({ children }: { children: React.ReactNode }) => {
return <>{children}</>;
});
AppInner.displayName = 'AppInner';
const AntdAppProvider = ({ children }: { children: React.ReactNode }) => {
return (

View File

@ -25,6 +25,7 @@ interface GlobalThemeContextProps {
}
const GlobalThemeContext = createContext<GlobalThemeContextProps>(null);
GlobalThemeContext.displayName = 'GlobalThemeContext';
export const useGlobalTheme = () => {
return React.useContext(GlobalThemeContext) || ({ theme: {}, isDarkTheme: false } as GlobalThemeContextProps);

View File

@ -10,7 +10,9 @@ type Item = MenuProps['items'][0] & {
};
export const GetMenuItemContext = createContext<{ collectMenuItem?(item: Item): void; onChange?: () => void }>(null);
GetMenuItemContext.displayName = 'GetMenuItemContext';
export const GetMenuItemsContext = createContext<{ pushMenuItem?(item: Item): void }>(null);
GetMenuItemsContext.displayName = 'GetMenuItemsContext';
/**
* SchemaInitializer.Item

View File

@ -65,7 +65,8 @@ const useErrorProps = (app: Application, error: any) => {
}
};
const AppError: FC<{ error: Error; app: Application }> = observer(({ app, error }) => {
const AppError: FC<{ error: Error; app: Application }> = observer(
({ app, error }) => {
const props = useErrorProps(app, error);
return (
<div>
@ -88,7 +89,9 @@ const AppError: FC<{ error: Error; app: Application }> = observer(({ app, error
/>
</div>
);
});
},
{ displayName: 'AppError' },
);
const getProps = (app: Application) => {
if (app.ws.serverDown) {
@ -195,7 +198,8 @@ const getProps = (app: Application) => {
return {};
};
const AppMaintaining: FC<{ app: Application; error: Error }> = observer(({ app }) => {
const AppMaintaining: FC<{ app: Application; error: Error }> = observer(
({ app }) => {
const { icon, status, title, subTitle } = getProps(app);
return (
<div>
@ -218,16 +222,21 @@ const AppMaintaining: FC<{ app: Application; error: Error }> = observer(({ app }
/>
</div>
);
});
},
{ displayName: 'AppMaintaining' },
);
const AppMaintainingDialog: FC<{ app: Application; error: Error }> = observer(({ app }) => {
const AppMaintainingDialog: FC<{ app: Application; error: Error }> = observer(
({ app }) => {
const { icon, status, title, subTitle } = getProps(app);
return (
<Modal open={true} footer={null} closable={false}>
<Result icon={icon} status={status} title={app.i18n.t(title)} subTitle={app.i18n.t(subTitle)} />
</Modal>
);
});
},
{ displayName: 'AppMaintainingDialog' },
);
const AppNotFound = () => {
const navigate = useNavigate();

View File

@ -1,3 +1,4 @@
import { createContext } from 'react';
export const PinnedPluginListContext = createContext({ items: {} });
PinnedPluginListContext.displayName = 'PinnedPluginListContext';

View File

@ -73,3 +73,4 @@ export const PluginDocument: React.FC<PluginDocumentProps> = memo((props) => {
</div>
);
});
PluginDocument.displayName = 'PluginDocument';

View File

@ -9,6 +9,7 @@ import { ADMIN_SETTINGS_PATH, PluginSettingsPageType, useApp } from '../applicat
import { useCompile } from '../schema-component';
export const SettingsCenterContext = createContext<any>({});
SettingsCenterContext.displayName = 'SettingsCenterContext';
function getMenuItems(list: PluginSettingsPageType[]) {
return list.map((item) => {

View File

@ -4,7 +4,9 @@ import { CollectionRecordProvider } from '../data-source';
import { useCurrentUserContext } from '../user';
export const RecordContext_deprecated = createContext({});
RecordContext_deprecated.displayName = 'RecordContext_deprecated';
export const RecordIndexContext = createContext(null);
RecordIndexContext.displayName = 'RecordIndexContext';
/**
* @deprecated use `CollectionRecordProvider` instead

View File

@ -54,6 +54,7 @@ const filterByACL = (schema, options) => {
};
const SchemaIdContext = createContext(null);
SchemaIdContext.displayName = 'SchemaIdContext';
const useMenuProps = () => {
const defaultSelectedUid = useContext(SchemaIdContext);
return {

View File

@ -4,6 +4,7 @@ import React, { createContext } from 'react';
import { useActionContext } from './hooks';
export const ActionContext = createContext<ActionContextProps>({});
ActionContext.displayName = 'ActionContext';
export const ActionContextProvider: React.FC<ActionContextProps & { value?: ActionContextProps }> = (props) => {
const contextProps = useActionContext();

View File

@ -40,7 +40,8 @@ export const filterAnalyses = (filters): any[] => {
return results;
};
const InternalAssociationSelect = observer((props: AssociationSelectProps) => {
const InternalAssociationSelect = observer(
(props: AssociationSelectProps) => {
const { objectValue = true } = props;
const field: any = useField();
const fieldSchema = useFieldSchema();
@ -149,7 +150,9 @@ const InternalAssociationSelect = observer((props: AssociationSelectProps) => {
</Space.Compact>
</div>
);
});
},
{ displayName: 'AssociationSelect' },
);
interface AssociationSelectInterface {
(props: any): React.ReactElement;

View File

@ -10,3 +10,4 @@ export interface AssociationFieldContextProps {
}
export const AssociationFieldContext = createContext<AssociationFieldContextProps>({});
AssociationFieldContext.displayName = 'AssociationFieldContext';

View File

@ -179,6 +179,7 @@ export const useFieldNames = (props) => {
};
const SubFormContext = createContext<Record<string, any>>(null);
SubFormContext.displayName = 'SubFormContext';
export const SubFormProvider = SubFormContext.Provider;
/**

View File

@ -12,6 +12,7 @@ import { Action } from '../action';
import { StablePopover } from '../popover';
export const FilterActionContext = createContext<any>(null);
FilterActionContext.displayName = 'FilterActionContext';
export const FilterAction = observer(
(props: any) => {

View File

@ -12,5 +12,8 @@ export interface FilterContextProps {
}
export const RemoveConditionContext = createContext(null);
RemoveConditionContext.displayName = 'RemoveConditionContext';
export const FilterContext = createContext<FilterContextProps>(null);
FilterContext.displayName = 'FilterContext';
export const FilterLogicContext = createContext(null);
FilterLogicContext.displayName = 'FilterLogicContext';

View File

@ -1,5 +1,6 @@
import { useFieldSchema } from '@formily/react';
import { useCollection_deprecated, useCollectionManager_deprecated } from '../../../collection-manager';
import { useMemo } from 'react';
/**
*
@ -7,15 +8,17 @@ import { useCollection_deprecated, useCollectionManager_deprecated } from '../..
*/
export const useOperatorList = (): any[] => {
const schema = useFieldSchema();
const fieldInterface = schema['x-designer-props']?.interface;
const { name } = useCollection_deprecated();
const { getCollectionFields, getInterface } = useCollectionManager_deprecated();
const collectionFields = getCollectionFields(name);
const res = useMemo(() => {
const fieldInterface = schema['x-designer-props']?.interface;
const collectionFields = getCollectionFields(name);
if (fieldInterface) {
return getInterface(fieldInterface)?.filterable?.operators || [];
}
const field = collectionFields.find((item) => item.name === schema.name);
return getInterface(field?.interface)?.filterable?.operators || [];
}, [schema.name]);
return res;
};

View File

@ -78,9 +78,12 @@ export function FormDialog(title: any, id: any, renderer?: any, theme?: any): IF
root.unmount();
},
};
const DialogContent = observer(() => {
const DialogContent = observer(
() => {
return <Fragment>{isFn(renderer) ? renderer(env.form) : renderer}</Fragment>;
});
},
{ displayName: 'DialogContent' },
);
const renderDialog = (open = true, resolve?: () => any, reject?: () => any) => {
const { form } = env;
if (!form) return null;

View File

@ -87,6 +87,7 @@ const useDefaultValues = (opts: any = {}, props: FormProps = {}) => {
};
const FormBlockContext = createContext<any>(null);
FormBlockContext.displayName = 'FormBlockContext';
export const Form: React.FC<FormProps> & { Designer?: any } = observer(
(props) => {

View File

@ -126,6 +126,7 @@ export const G2PlotRenderer = forwardRef(function <O = any>(props: ReactG2PlotPr
return <div className={cls(['g2plot', className])} ref={containerRef} />;
});
G2PlotRenderer.displayName = 'G2PlotRenderer';
export const G2Plot: any = observer(
(props: any) => {
@ -140,12 +141,14 @@ export const G2Plot: any = observer(
if (typeof fn === 'function') {
const result = fn.bind({ api })();
if (result?.then) {
result.then((data) => {
result
.then((data) => {
if (Array.isArray(data)) {
field.componentProps.config.data = data;
}
field.data.loading = false;
});
})
.catch(console.error);
} else {
field.data.loading = false;
}

View File

@ -5,6 +5,7 @@ import React, { createContext, useContext, useEffect, useMemo } from 'react';
import { BlockProvider, useBlockRequestContext, useParsedFilter } from '../../../block-provider';
import useStyles from './GridCard.Decorator.style';
export const GridCardBlockContext = createContext<any>({});
GridCardBlockContext.displayName = 'GridCardBlockContext';
const InternalGridCardBlockProvider = (props) => {
const { resource, service } = useBlockRequestContext();

View File

@ -11,8 +11,11 @@ import { useToken } from '../__builtins__';
import useStyles from './Grid.style';
const GridRowContext = createContext<any>({});
GridRowContext.displayName = 'GridRowContext';
const GridColContext = createContext<any>({});
GridColContext.displayName = 'GridColContext';
const GridContext = createContext<any>({});
GridContext.displayName = 'GridContext';
const breakRemoveOnGrid = (s: Schema) => s['x-component'] === 'Grid';
const breakRemoveOnRow = (s: Schema) => s['x-component'] === 'Grid.Row';

View File

@ -77,3 +77,4 @@ export const EllipsisWithTooltip = forwardRef((props: Partial<IEllipsisWithToolt
</Popover>
);
});
EllipsisWithTooltip.displayName = 'EllipsisWithTooltip';

View File

@ -67,3 +67,4 @@ export const Json = React.forwardRef<typeof Input.TextArea, JSONTextAreaProps>(
);
},
);
Json.displayName = 'Json';

View File

@ -7,6 +7,7 @@ import React, { createContext, useContext, useEffect, useMemo } from 'react';
import { BlockProvider, useBlockRequestContext, useParsedFilter } from '../../../block-provider';
export const ListBlockContext = createContext<any>({});
ListBlockContext.displayName = 'ListBlockContext';
const InternalListBlockProvider = (props) => {
const { resource, service } = useBlockRequestContext();

View File

@ -350,7 +350,6 @@ const SideMenu = ({
};
const MenuModeContext = createContext(null);
MenuModeContext.displayName = 'MenuModeContext';
const useSideMenuRef = () => {

View File

@ -6,7 +6,8 @@ import React, { useMemo, useRef } from 'react';
import { useCollectionManager_deprecated } from '../../../collection-manager';
import { StablePopover } from '../popover';
export const Editable = observer((props) => {
export const Editable = observer(
(props) => {
const field: any = useField();
const containerRef = useRef(null);
const fieldSchema = useFieldSchema();
@ -65,9 +66,12 @@ export const Editable = observer((props) => {
</StablePopover>
</FormItem>
);
});
},
{ displayName: 'Editable' },
);
export const QuickEdit = observer((props) => {
export const QuickEdit = observer(
(props) => {
const field = useField<Field>();
const { getCollectionJoinField } = useCollectionManager_deprecated();
const fieldSchema = useFieldSchema();
@ -76,4 +80,6 @@ export const QuickEdit = observer((props) => {
return null;
}
return field.editable ? <Editable {...props} /> : <FormItem {...props} style={{ padding: '0 8px' }} />;
});
},
{ displayName: 'QuickEdit' },
);

View File

@ -16,6 +16,7 @@ import { useFieldNames } from './useFieldNames';
import { getLabelFormatValue, useLabelUiSchema } from './util';
export const RecordPickerContext = createContext(null);
RecordPickerContext.displayName = 'RecordPickerContext';
function flatData(data) {
const newArr = [];

View File

@ -13,6 +13,7 @@ import {
import React, { createContext, useContext, useState } from 'react';
const DataSourceContext = createContext(null);
DataSourceContext.displayName = 'DataSourceContext';
const useSelectedRowKeys = () => {
const ctx = useContext(DataSourceContext);

View File

@ -7,6 +7,7 @@ import { RawTextArea } from './RawTextArea';
import { TextArea } from './TextArea';
const VariableScopeContext = createContext([]);
VariableScopeContext.displayName = 'VariableScopeContext';
export function VariableScopeProvider({ scope = [], children }) {
return <VariableScopeContext.Provider value={scope}>{children}</VariableScopeContext.Provider>;

View File

@ -15,3 +15,4 @@ export const XButton = forwardRef((props: ButtonProps, ref: any) => {
</Button>
);
});
XButton.displayName = 'XButton';

View File

@ -2,11 +2,13 @@ import { TinyColor } from '@ctrl/tinycolor';
import { useDraggable, useDroppable } from '@dnd-kit/core';
import { cx } from '@emotion/css';
import { Schema, observer, useField, useFieldSchema } from '@formily/react';
import React, { HTMLAttributes, createContext, useContext } from 'react';
import React, { HTMLAttributes, createContext, useContext, useMemo } from 'react';
import { useToken } from '../../antd/__builtins__';
export const DraggableContext = createContext(null);
DraggableContext.displayName = 'DraggableContext';
export const SortableContext = createContext(null);
SortableContext.displayName = 'SortableContext';
export const SortableProvider = (props) => {
const { id, data, children } = props;
@ -74,15 +76,17 @@ interface SortableItemProps extends HTMLAttributes<HTMLDivElement> {
export const SortableItem: React.FC<SortableItemProps> = observer(
(props) => {
const { schema, id, eid, removeParentsIfNoChildren, ...others } = useSortableItemProps(props);
return (
<SortableProvider
id={id}
data={{
const data = useMemo(() => {
return {
insertAdjacent: 'afterEnd',
schema: schema,
removeParentsIfNoChildren: removeParentsIfNoChildren ?? true,
}}
>
};
}, [schema, removeParentsIfNoChildren]);
return (
<SortableProvider id={id} data={data}>
<Sortable id={eid} {...others}>
{props.children}
</Sortable>

View File

@ -2,3 +2,4 @@ import { createContext } from 'react';
import { ISchemaComponentContext } from './types';
export const SchemaComponentContext = createContext<ISchemaComponentContext>({});
SchemaComponentContext.displayName = 'SchemaComponentContext.Provider';

View File

@ -1,5 +1,5 @@
import { ExpressionScope, SchemaComponentsContext, SchemaOptionsContext } from '@formily/react';
import React, { useContext } from 'react';
import React, { memo, useContext, useMemo } from 'react';
import { ISchemaComponentOptionsProps } from '../types';
export const useSchemaOptionsContext = () => {
@ -7,16 +7,28 @@ export const useSchemaOptionsContext = () => {
return options || {};
};
export const SchemaComponentOptions: React.FC<ISchemaComponentOptionsProps> = (props) => {
export const SchemaComponentOptions: React.FC<ISchemaComponentOptionsProps> = memo((props) => {
const { children } = props;
const options = useSchemaOptionsContext();
const components = { ...options.components, ...props.components };
const scope = { ...options.scope, ...props.scope };
const components = useMemo(() => {
return { ...options.components, ...props.components };
}, [options.components, props.components]);
const scope = useMemo(() => {
return { ...options.scope, ...props.scope };
}, [options.scope, props.scope]);
const schemaOptionsContextValue = useMemo(() => {
return { scope, components };
}, [scope, components]);
return (
<SchemaOptionsContext.Provider value={{ scope, components }}>
<SchemaOptionsContext.Provider value={schemaOptionsContextValue}>
<SchemaComponentsContext.Provider value={components}>
<ExpressionScope value={scope}>{children}</ExpressionScope>
</SchemaComponentsContext.Provider>
</SchemaOptionsContext.Provider>
);
};
});
SchemaComponentOptions.displayName = 'SchemaComponentOptions';

View File

@ -44,19 +44,23 @@ Schema.registerCompiler(Registry.compile);
export const SchemaComponentProvider: React.FC<ISchemaComponentProvider> = (props) => {
const { designable, onDesignableChange, components, children } = props;
const [, setUid] = useState(uid());
const [uidValue, setUid] = useState(uid());
const [formId, setFormId] = useState(uid());
const form = useMemo(() => props.form || createForm(), [formId]);
const { t } = useTranslation();
const scope = { ...props.scope, t, randomString };
const scope = useMemo(() => {
return { ...props.scope, t, randomString };
}, [props.scope, t]);
const [active, setActive] = useState(designable);
return (
<SchemaComponentContext.Provider
value={{
const schemaComponentContextValue = useMemo(
() => ({
scope,
components,
reset: () => setFormId(uid()),
refresh: () => setUid(uid()),
refresh: () => {
setUid(uid());
},
designable: typeof designable === 'boolean' ? designable : active,
setDesignable: (value) => {
if (typeof designable !== 'boolean') {
@ -64,8 +68,12 @@ export const SchemaComponentProvider: React.FC<ISchemaComponentProvider> = (prop
}
onDesignableChange?.(value);
},
}}
>
}),
[uidValue, scope, components, designable, active],
);
return (
<SchemaComponentContext.Provider value={schemaComponentContextValue}>
<FormProvider form={form}>
<SchemaComponentOptions inherit scope={scope} components={components}>
{children}

View File

@ -36,3 +36,4 @@ export const AsDefaultTemplate = React.forwardRef((props: any, ref) => {
/>
);
});
AsDefaultTemplate.displayName = 'AsDefaultTemplate';

View File

@ -276,3 +276,4 @@ ArrayCollapse.Copy = React.forwardRef((props: any, ref) => {
/>
);
});
(ArrayCollapse as any).Copy.displayName = 'ArrayCollapse.Copy';

View File

@ -32,3 +32,4 @@ export const EnableLinkage = React.forwardRef((props: any, ref) => {
/>
);
});
EnableLinkage.displayName = 'EnableLinkage';

View File

@ -266,3 +266,4 @@ ArrayCollapse.Copy = React.forwardRef((props: any, ref) => {
/>
);
});
(ArrayCollapse as any).Copy.displayName = 'ArrayCollapse.Copy';

View File

@ -11,5 +11,8 @@ export interface FilterContextProps {
}
export const RemoveActionContext = createContext(null);
RemoveActionContext.displayName = 'RemoveActionContext';
export const FilterContext = createContext<FilterContextProps>(null);
FilterContext.displayName = 'FilterContext';
export const LinkageLogicContext = createContext(null);
LinkageLogicContext.displayName = 'LinkageLogicContext';

View File

@ -124,6 +124,7 @@ interface SchemaSettingsContextProps<T = any> {
}
const SchemaSettingsContext = createContext<SchemaSettingsContextProps>(null);
SchemaSettingsContext.displayName = 'SchemaSettingsContext';
export function useSchemaSettings<T = any>() {
return useContext(SchemaSettingsContext) as SchemaSettingsContextProps<T>;

View File

@ -5,6 +5,7 @@ import { useSchemaTemplateManager } from './SchemaTemplateManagerProvider';
import { useTemplateBlockContext } from '../block-provider/TemplateBlockProvider';
const BlockTemplateContext = createContext<any>({});
BlockTemplateContext.displayName = 'BlockTemplateContext';
export const useBlockTemplateContext = () => {
return useContext(BlockTemplateContext);

View File

@ -11,6 +11,7 @@ import { BlockTemplate } from './BlockTemplate';
import { DEFAULT_DATA_SOURCE_KEY } from '../data-source';
export const SchemaTemplateManagerContext = createContext<any>({});
SchemaTemplateManagerContext.displayName = 'SchemaTemplateManagerContext';
export const SchemaTemplateManagerProvider: React.FC<any> = (props) => {
const { templates, refresh } = props;

View File

@ -4,6 +4,7 @@ import { useRequest } from '../api-client';
import { useAppSpin } from '../application/hooks/useAppSpin';
export const SystemSettingsContext = createContext<Result<any, any>>(null);
SystemSettingsContext.displayName = 'SystemSettingsContext';
export const useSystemSettings = () => {
return useContext(SystemSettingsContext);

View File

@ -162,6 +162,8 @@ export const SettingsMenu: React.FC<{
};
export const DropdownVisibleContext = createContext(null);
DropdownVisibleContext.displayName = 'DropdownVisibleContext';
export const CurrentUser = () => {
const [visible, setVisible] = useState(false);
const { token } = useToken();

View File

@ -6,6 +6,7 @@ import { useAppSpin } from '../application/hooks/useAppSpin';
import { useCompile } from '../schema-component';
export const CurrentUserContext = createContext<ReturnTypeOfUseRequest>(null);
CurrentUserContext.displayName = 'CurrentUserContext';
export const useCurrentUserContext = () => {
return useContext(CurrentUserContext);

View File

@ -24,6 +24,7 @@ interface OptionsOfAddMenuItem {
type Item = ItemType & { _options?: OptionsOfAddMenuItem };
const CurrentUserSettingsMenuContext = createContext<{ menuItems: React.MutableRefObject<Item[]> }>(null);
CurrentUserSettingsMenuContext.displayName = 'CurrentUserSettingsMenuContext';
export const useCurrentUserSettingsMenu = () => {
const { menuItems } = useContext(CurrentUserSettingsMenuContext) || {};

View File

@ -16,6 +16,7 @@ import { isVariable } from './utils/isVariable';
import { uniq } from './utils/uniq';
export const VariablesContext = createContext<VariablesContextType>(null);
VariablesContext.displayName = 'VariablesContext';
const variableToCollectionName = {};

View File

@ -6,3 +6,4 @@ export const RolesManagerContext = createContext<{
}>({
role: null,
} as any);
RolesManagerContext.displayName = 'RolesManagerContext';

View File

@ -3,6 +3,7 @@ import { Spin } from 'antd';
import React, { createContext, useContext } from 'react';
const AvailableActionsContext = createContext([]);
AvailableActionsContext.displayName = 'AvailableActionsContext';
export const AvailableActionsProvider: React.FC = (props) => {
const { data, loading } = useRequest<{

View File

@ -3,6 +3,7 @@ import { Spin } from 'antd';
import React, { createContext, useContext } from 'react';
const MenuItemsContext = createContext(null);
MenuItemsContext.displayName = 'MenuItemsContext';
export const toItems = (properties = {}) => {
const items = [];

View File

@ -28,6 +28,7 @@ const toActionMap = (arr: any[]) => {
};
export const RoleResourceCollectionContext = createContext<any>({});
RoleResourceCollectionContext.displayName = 'RoleResourceCollectionContext';
export const RolesResourcesActions = connect((props) => {
const { styles } = useStyles();

View File

@ -4,6 +4,7 @@ import { FormProvider, SchemaComponent } from '@nocobase/client';
import { scopesSchema } from '../schemas/scopes';
const RolesResourcesScopesSelectedRowKeysContext = createContext(null);
RolesResourcesScopesSelectedRowKeysContext.displayName = 'RolesResourcesScopesSelectedRowKeysContext';
const RolesResourcesScopesSelectedRowKeysProvider: React.FC = (props) => {
const [keys, setKeys] = useState([]);

View File

@ -103,6 +103,7 @@ const Value = observer(
);
const IsAssociationBlock = createContext(null);
IsAssociationBlock.displayName = 'IsAssociationBlock';
export const AuditLogs: any = () => {
const isAssoc = useContext(IsAssociationBlock);

View File

@ -12,6 +12,7 @@ export type Authenticator = {
};
export const AuthenticatorsContext = createContext<Authenticator[]>([]);
AuthenticatorsContext.displayName = 'AuthenticatorsContext';
export const useAuthenticator = (name: string) => {
const authenticators = useContext(AuthenticatorsContext);

View File

@ -11,6 +11,7 @@ export const SignupPageContext = createContext<{
}>;
};
}>({});
SignupPageContext.displayName = 'SignupPageContext';
export const SignupPageProvider: React.FC<{
authType: string;

View File

@ -34,9 +34,12 @@ export const useAdminSettingsForm = (authType: string) => {
return auth?.components?.AdminSettingsForm;
};
export const Options = observer(() => {
export const Options = observer(
() => {
const form = useForm();
const record = useRecord();
const Component = useAdminSettingsForm(form.values.authType || record.authType);
return Component ? <Component /> : null;
});
},
{ displayName: 'Options' },
);

View File

@ -3,6 +3,7 @@ import { createContext, useContext } from 'react';
export const AuthTypeContext = createContext<{
type: string;
}>({ type: '' });
AuthTypeContext.displayName = 'AuthTypeContext';
export const AuthTypesContext = createContext<{
types: {
@ -11,6 +12,7 @@ export const AuthTypesContext = createContext<{
value: string;
}[];
}>({ types: [] });
AuthTypesContext.displayName = 'AuthTypesContext';
export const useAuthTypes = () => {
const { types } = useContext(AuthTypesContext);

View File

@ -2,8 +2,11 @@ import { createContext, useContext } from 'react';
import type { ToolbarProps } from './types';
export const CalendarToolbarContext = createContext<ToolbarProps>(null);
CalendarToolbarContext.displayName = 'CalendarToolbarContext';
export const CalendarContext = createContext(null);
CalendarContext.displayName = 'CalendarContext';
export const DeleteEventContext = createContext(null);
DeleteEventContext.displayName = 'DeleteEventContext';
export const useDeleteEvent = () => {
return useContext(DeleteEventContext);

View File

@ -5,6 +5,7 @@ import _ from 'lodash';
import React, { createContext, useContext, useEffect, useMemo } from 'react';
export const CalendarBlockContext = createContext<any>({});
CalendarBlockContext.displayName = 'CalendarBlockContext';
const InternalCalendarBlockProvider = (props) => {
const { fieldNames, showLunar } = props;

View File

@ -7,6 +7,7 @@ export const ChartQueryMetadataContext = createContext({
refresh: () => {},
data: [] as any[],
});
ChartQueryMetadataContext.displayName = 'ChartQueryMetadataContext';
export const ChartQueryMetadataProvider: React.FC = (props) => {
const api = useAPIClient();

View File

@ -3,6 +3,7 @@ import React, { FC, useState, createContext } from 'react';
import * as hooks from './hooks';
export const DataSourceContext = createContext(null);
DataSourceContext.displayName = 'DataSourceContext';
export const DatabaseConnectionProvider: FC = (props) => {
const [dataSource, setDataSource] = useState(null);

View File

@ -33,6 +33,7 @@ const RemoteCollectionContext = createContext<{
refreshRM: Function;
titleField: string;
}>({ refreshRM: () => {}, titleField: null, targetCollection: null });
RemoteCollectionContext.displayName = 'RemoteCollectionContext';
export const useRemoteCollectionContext = () => {
return useContext(RemoteCollectionContext);
};

View File

@ -4,7 +4,8 @@ import { debounce } from 'lodash';
import React, { useState, useMemo, useEffect } from 'react';
import { useRecord } from '@nocobase/client';
export const FieldTitleInput = observer((props: any) => {
export const FieldTitleInput = observer(
(props: any) => {
const { value, handleFieldChange } = props;
const record = useRecord();
const [titleValue, setTitleValue] = useState(value);
@ -38,4 +39,6 @@ export const FieldTitleInput = observer((props: any) => {
setTitleValue(value);
}, [value]);
return <Input value={titleValue} onChange={handleChange} />;
});
},
{ displayName: 'FieldTitleInput' },
);

View File

@ -11,6 +11,7 @@ import { dataSourceSchema } from './schemas/dataSourceTable';
import { PermissionProvider } from './PermisionProvider';
const AvailableActionsContext = createContext([]);
AvailableActionsContext.displayName = 'AvailableActionsContext';
const AvailableActionsProver: React.FC = (props) => {
const { data, loading } = useRequest<{

Some files were not shown because too many files have changed in this diff Show More