-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(filter-form): fix operator not valid in block templates (#4390)
* fix(filter-form): fix operator not valid in block templates * test: add e2e test * test: clear data templates * chore: fix e2e tests * chore: stash * chore: change import path to fix unit tests * chore: change import path to fix unit tests * chore: fix build
- Loading branch information
1 parent
a5ede09
commit ef8e4ae
Showing
84 changed files
with
851 additions
and
746 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
packages/core/client/src/application/schema-settings/context/index.ts
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages/core/client/src/application/schema-settings/hooks/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/core/client/src/block-provider/CollectOperators.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* This file is part of the NocoBase (R) project. | ||
* Copyright (c) 2020-2024 NocoBase Co., Ltd. | ||
* Authors: NocoBase Team. | ||
* | ||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. | ||
* For more information, please refer to: https://www.nocobase.com/agreement. | ||
*/ | ||
|
||
import React, { FC, createContext, useCallback, useRef } from 'react'; | ||
|
||
const NOOP = () => {}; | ||
|
||
const CollectOperatorsContext = createContext<{ | ||
/** 手机单个字段的操作符 */ | ||
collectOperator: (name: string | number, operator: string) => void; | ||
/** 获取所有字段的操作符 */ | ||
getOperators: () => Record<string, string>; | ||
/** 获取单个字段的操作符 */ | ||
getOperator: (name: string | number) => string; | ||
/** 移除单个字段的操作符 */ | ||
removeOperator: (name: string | number) => void; | ||
}>(null); | ||
|
||
export const CollectOperators: FC<{ defaultOperators: Record<string, string> }> = (props) => { | ||
const operators = useRef(props.defaultOperators || {}); | ||
|
||
const collectOperator = useCallback((name: string, operator: string) => { | ||
operators.current[name] = operator; | ||
}, []); | ||
|
||
const getOperators = useCallback(() => { | ||
return { ...operators.current }; | ||
}, []); | ||
|
||
const getOperator = useCallback((name: string) => { | ||
return operators.current[name]; | ||
}, []); | ||
|
||
const removeOperator = useCallback((name: string) => { | ||
delete operators.current[name]; | ||
}, []); | ||
|
||
return ( | ||
<CollectOperatorsContext.Provider | ||
value={{ | ||
collectOperator, | ||
getOperators, | ||
getOperator, | ||
removeOperator, | ||
}} | ||
> | ||
{props.children} | ||
</CollectOperatorsContext.Provider> | ||
); | ||
}; | ||
|
||
export const useOperators = () => { | ||
const { | ||
getOperator = NOOP, | ||
getOperators = NOOP, | ||
collectOperator = NOOP, | ||
removeOperator = NOOP, | ||
} = React.useContext(CollectOperatorsContext) || {}; | ||
return { | ||
getOperator, | ||
getOperators: getOperators as () => Record<string, string> | undefined, | ||
collectOperator, | ||
removeOperator, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/core/client/src/block-provider/__tests__/CollectOperators.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* This file is part of the NocoBase (R) project. | ||
* Copyright (c) 2020-2024 NocoBase Co., Ltd. | ||
* Authors: NocoBase Team. | ||
* | ||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. | ||
* For more information, please refer to: https://www.nocobase.com/agreement. | ||
*/ | ||
|
||
import { render } from '@nocobase/test/client'; | ||
import React from 'react'; | ||
import { CollectOperators, useOperators } from '../CollectOperators'; | ||
|
||
describe('CollectOperators', () => { | ||
it('should collect and get operators correctly', () => { | ||
const defaultOperators = { | ||
field1: 'operator1', | ||
field2: 'operator2', | ||
}; | ||
|
||
const TestComponent = () => { | ||
const { collectOperator, getOperators, getOperator } = useOperators(); | ||
|
||
collectOperator('field3', 'operator3'); | ||
|
||
const operators = getOperators(); | ||
const operator = getOperator('field1') as string; | ||
|
||
return ( | ||
<div> | ||
<span data-testid="operators">{JSON.stringify(operators)}</span> | ||
<span data-testid="operator">{operator}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
const { getByTestId } = render( | ||
<CollectOperators defaultOperators={defaultOperators}> | ||
<TestComponent /> | ||
</CollectOperators>, | ||
); | ||
|
||
const operatorsElement = getByTestId('operators'); | ||
const operatorElement = getByTestId('operator'); | ||
|
||
expect(JSON.parse(operatorsElement.textContent)).toEqual({ | ||
...defaultOperators, | ||
field3: 'operator3', | ||
}); | ||
expect(operatorElement.textContent).toBe('operator1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.