Skip to content

Commit

Permalink
Merge pull request #106 from axonivy/hide-type-on-hd
Browse files Browse the repository at this point in the history
XIVY-15662 Hide type switch on hd data editor
  • Loading branch information
ivy-lli authored Dec 20, 2024
2 parents 62c16af + 4d1049c commit 2d27199
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/dataclass-editor/src/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const appContext = createContext<AppContext>({
export const AppProvider = appContext.Provider;

export const useAppContext = () => {
return useContext(appContext);
const context = useContext(appContext);
return { ...context, isHdData: context.context.file.includes('src_hd') };
};

type EntityClassContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ContextHelperProps = {

const ContextHelper = (props: ContextHelperProps & { children: ReactNode }) => {
const appContext = {
context: props.appContext?.context ?? ({} as DataClassEditorDataContext),
context: props.appContext?.context ?? ({ file: '' } as DataClassEditorDataContext),
dataClass: props.appContext?.dataClass ?? ({} as DataClass),
setDataClass: props.appContext?.setDataClass ?? (() => {}),
selectedField: props.appContext?.selectedField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EntityClassDatabaseTable } from './entity/EntityClassDatabaseTable';
import { useDataClassProperty } from './useDataClassProperty';

export const DataClassDetailContent = () => {
const { dataClass, setDataClass } = useAppContext();
const { dataClass, setDataClass, isHdData } = useAppContext();
const { setProperty } = useDataClassProperty();

return (
Expand All @@ -22,7 +22,7 @@ export const DataClassDetailContent = () => {
annotations={dataClass.annotations}
setAnnotations={(newAnnotations: Array<string>) => setProperty('annotations', newAnnotations)}
/>
<DataClassType />
{!isHdData && <DataClassType />}
</Flex>
</AccordionContent>
</AccordionItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { FieldEntityDatabaseField } from './entity/FieldEntityDatabaseField';
import { FieldNameTypeComment } from './FieldNameTypeComment';
import { FieldProperties } from './FieldProperties';
import { useFieldProperty } from './useFieldProperty';
import { useAppContext } from '../../context/AppContext';

export const FieldDetailContent = () => {
const { isHdData } = useAppContext();
const { field, setField } = useField();
const { setProperty } = useFieldProperty();

Expand All @@ -19,7 +21,7 @@ export const FieldDetailContent = () => {
<AccordionContent>
<Flex direction='column' gap={4}>
<FieldNameTypeComment />
<FieldProperties />
{!isHdData && <FieldProperties />}
<AnnotationsTable
annotations={field.annotations}
setAnnotations={(annotations: Array<string>) => setProperty('annotations', annotations)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ type DataClassMasterToolbarProps = {
};

export const DataClassMasterToolbar = ({ title }: DataClassMasterToolbarProps) => {
const { context, detail, setDetail } = useAppContext();
const { detail, setDetail, isHdData } = useAppContext();
const { theme, setTheme, disabled } = useTheme();
const isFormData = context.file.includes('src_hd');
const openForm = useAction('openForm');
const openProcess = useAction('openProcess');

return (
<Toolbar className='master-toolbar'>
<ToolbarTitle className='master-header'>{title}</ToolbarTitle>
<Flex gap={1}>
{isFormData && (
{isHdData && (
<>
<Button icon={IvyIcons.File} size='large' title='Open Form' aria-label='Open Form' onClick={() => openForm()} />
<Button icon={IvyIcons.Process} size='large' title='Open Process' aria-label='Open Process' onClick={() => openProcess()} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { expect, test } from '@playwright/test';
import { DataClassEditor } from '../pageobjects/DataClassEditor';

test('not visible in normal data class', async ({ page }) => {
test('normal data class', async ({ page }) => {
const editor = await DataClassEditor.openDataClass(page, 'dataclasses/dataclass/Data.d.json');
await expect(editor.title).toHaveText('Data Class - Data');
await expect(editor.toolbar.getByRole('button', { name: 'Open Process' })).toBeHidden();
await expect(editor.toolbar.getByRole('button', { name: 'Open Form' })).toBeHidden();
});

test('visible in form data class', async ({ page }) => {
test('hd data class', async ({ page }) => {
const editor = await DataClassEditor.openDataClass(page, 'src_hd/dataclass/form/formData.d.json');
await expect(editor.title).toHaveText('Data Class - formData');
await expect(editor.toolbar.getByRole('button', { name: 'Open Process' })).toBeVisible();
await expect(editor.toolbar.getByRole('button', { name: 'Open Form' })).toBeVisible();

await editor.detailToggle.locator.click();
await expect(editor.detail.dataClass.general.classType.collapsible.locator).toBeHidden();

await editor.table.row(0).locator.click();
await expect(editor.detail.field.general.properties.collapsible.locator).toBeHidden();
});

0 comments on commit 2d27199

Please sign in to comment.