-
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.
feat: add some e2e test for linkage style in table, extract linkage
style logic to hooks
- Loading branch information
Showing
14 changed files
with
448 additions
and
86 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
16 changes: 16 additions & 0 deletions
16
packages/core/client/src/modules/blocks/data-blocks/form/hooks/useDataFormItemProps.ts
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,16 @@ | ||
/** | ||
* 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 { useForm } from '@formily/react'; | ||
import { useSatisfiedActionValues } from '../../../../../schema-settings/LinkageRules/useActionValues'; | ||
export function useDataFormItemProps() { | ||
const form = useForm(); | ||
const { valueMap: style } = useSatisfiedActionValues({ category: 'style', formValues: form?.values }); | ||
return { style }; | ||
} |
36 changes: 36 additions & 0 deletions
36
...ges/core/client/src/modules/blocks/data-blocks/table/__e2e__/linkageStyleSettings.test.ts
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,36 @@ | ||
/** | ||
* 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 { expect, test, oneTableBlockWithIntegerAndIDColumn } from '@nocobase/test/e2e'; | ||
|
||
test.describe('view', () => { | ||
test('linkage style', async ({ page, mockPage, mockRecord }) => { | ||
const nocoPage = await mockPage(oneTableBlockWithIntegerAndIDColumn).waitForInit(); | ||
await mockRecord('general', { integer: '423' }); | ||
await nocoPage.goto(); | ||
await page.getByText('integer', { exact: true }).hover(); | ||
|
||
await page | ||
.getByRole('button', { | ||
name: 'designer-schema-settings-TableV2.Column-fieldSettings:TableColumn-general', | ||
}) | ||
.click(); | ||
await page.getByRole('menuitem', { name: 'Style' }).click(); | ||
await page.getByRole('button', { name: 'plus Add linkage rule' }).click(); | ||
await page.getByText('Add property').click(); | ||
await page.locator('#rc_select_2').click(); | ||
await page.getByText('Color', { exact: true }).click(); | ||
await page.getByLabel('color-picker-normal').click(); | ||
await page.locator('input[type="text"]').fill('A34FCC'); | ||
await page.getByRole('button', { name: 'OK' }).click(); | ||
const cell = await page.getByRole('button', { name: '423' }); | ||
const color = await cell.evaluate((el) => getComputedStyle(el).color); | ||
await expect(color).toBe('rgb(163, 79, 204)'); | ||
}); | ||
}); |
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
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
53 changes: 53 additions & 0 deletions
53
packages/core/client/src/schema-settings/LinkageRules/useActionValues.ts
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,53 @@ | ||
/** | ||
* 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 { useState, useEffect } from 'react'; | ||
import { useVariables, useLocalVariables } from '../../variables'; | ||
import { useFieldSchema } from '@formily/react'; | ||
import { LinkageRuleCategory, LinkageRuleDataKeyMap } from './type'; | ||
import { getSatisfiedValueMap } from './compute-rules'; | ||
import { useContextVariable } from '../../variables'; | ||
import { isEmpty } from 'lodash'; | ||
export function useSatisfiedActionValues({ | ||
formValues, | ||
category = 'default', | ||
rules, | ||
schema, | ||
}: { | ||
category: `${LinkageRuleCategory}`; | ||
formValues: Record<string, any>; | ||
rules?: any; | ||
schema?: any; | ||
}) { | ||
const [valueMap, setValueMap] = useState({}); | ||
const fieldSchema = useFieldSchema(); | ||
const variables = useVariables(); | ||
const localVariables = useLocalVariables({ currentForm: { values: formValues } as any }); | ||
const contextVariable = useContextVariable(); | ||
const localSchema = schema ?? fieldSchema; | ||
const linkageRules = rules ?? localSchema[LinkageRuleDataKeyMap[category]]; | ||
useEffect(() => { | ||
variables?.registerVariable(contextVariable); | ||
}, [contextVariable, variables]); | ||
|
||
useEffect(() => { | ||
if (linkageRules && formValues) { | ||
getSatisfiedValueMap({ rules: linkageRules, variables, localVariables }) | ||
.then((valueMap) => { | ||
if (!isEmpty(valueMap)) { | ||
setValueMap(valueMap); | ||
} else setValueMap({}); | ||
}) | ||
.catch((err) => { | ||
throw new Error(err.message); | ||
}); | ||
} | ||
}, [variables, localVariables, formValues, linkageRules]); | ||
return { valueMap }; | ||
} |
Oops, something went wrong.