-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from axonivy/add-combobox-to-addDataClass
XIVY-15045 Add Type-Combobox to Add DataClass-Dialog
- Loading branch information
Showing
9 changed files
with
148 additions
and
22 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
27 changes: 27 additions & 0 deletions
27
integrations/standalone/tests/pageobjects/abstract/Combobox.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,27 @@ | ||
import { expect, type Locator } from '@playwright/test'; | ||
|
||
export class Combobox { | ||
readonly locator: Locator; | ||
|
||
constructor(parentLocator: Locator, options?: { label?: string; nth?: number }) { | ||
if (options?.label) { | ||
this.locator = parentLocator.getByRole('combobox', { name: options.label, exact: true }); | ||
} else { | ||
this.locator = parentLocator.getByRole('combobox').nth(options?.nth ?? 0); | ||
} | ||
} | ||
|
||
async fill(value: string) { | ||
await this.locator.fill(value); | ||
await this.locator.blur(); | ||
} | ||
|
||
async clear() { | ||
await this.locator.fill(''); | ||
await this.locator.blur(); | ||
} | ||
|
||
async expectToHavePlaceholder(palceholder: string) { | ||
await expect(this.locator).toHaveAttribute('placeholder', palceholder); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
3 changes: 3 additions & 0 deletions
3
packages/dataclass-editor/src/detail/field/ComboboxFieldWithTypeBrowser.css
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,3 @@ | ||
.combobox-with-type-browser .ui-combobox { | ||
flex: 1; | ||
} |
91 changes: 91 additions & 0 deletions
91
packages/dataclass-editor/src/detail/field/ComboboxFieldWithTypeBrowser.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,91 @@ | ||
import { | ||
BasicCheckbox, | ||
BasicField, | ||
Button, | ||
Combobox, | ||
Dialog, | ||
DialogContent, | ||
DialogTrigger, | ||
Flex, | ||
IvyIcon, | ||
type BrowserNode, | ||
type MessageData | ||
} from '@axonivy/ui-components'; | ||
import { IvyIcons } from '@axonivy/ui-icons'; | ||
import { useMemo, useState } from 'react'; | ||
import { Browser } from './browser/Browser'; | ||
import { useAppContext } from '../../context/AppContext'; | ||
import { useMeta } from '../../context/useMeta'; | ||
import { typeData } from '../../data/type-data'; | ||
import './ComboboxFieldWithTypeBrowser.css'; | ||
import type { DataclassType } from '../../protocol/types'; | ||
|
||
export type InputFieldProps = { | ||
value: string; | ||
onChange: (value: string) => void; | ||
message?: MessageData; | ||
}; | ||
|
||
export const ComboboxFieldWithTypeBrowser = ({ value, onChange, message }: InputFieldProps) => { | ||
const [open, setOpen] = useState(false); | ||
const { context } = useAppContext(); | ||
const [typeAsList, setTypeAsList] = useState<boolean>(false); | ||
const dataClasses = useMeta('meta/scripting/dataClasses', context, []).data; | ||
const ivyTypes = useMeta('meta/scripting/ivyTypes', undefined, []).data; | ||
const types = useMemo(() => typeData(dataClasses, ivyTypes, [], [], false), [dataClasses, ivyTypes]); | ||
|
||
const typeAsListChange = (change: boolean) => { | ||
setTypeAsList(!typeAsList); | ||
if (change && !(value.startsWith('List<') && value.endsWith('>'))) { | ||
onChange(`List<${value}>`); | ||
} else if (!change && value.startsWith('List<') && value.endsWith('>')) { | ||
const removeListFromValue = value.slice(5, -1); | ||
onChange(removeListFromValue); | ||
} | ||
}; | ||
|
||
const ExtendedComboboxItem = ({ icon, value, info }: BrowserNode<DataclassType>) => ( | ||
<Flex gap={1} alignItems='center'> | ||
<IvyIcon icon={icon} /> | ||
<span>{value}</span> | ||
<span style={{ color: 'var(--N700)' }}>{info}</span> | ||
</Flex> | ||
); | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<BasicField label='Type' message={message} aria-label='Type'> | ||
<Flex direction='row' gap={2} alignItems='center' className='combobox-with-type-browser'> | ||
<Combobox | ||
onChange={value => { | ||
const foundDataclassType = dataClasses.find(type => type.name === value); | ||
if (foundDataclassType) { | ||
onChange(foundDataclassType.fullQualifiedName); | ||
} else { | ||
onChange(value); | ||
} | ||
}} | ||
value={value} | ||
options={types} | ||
itemRender={option => <ExtendedComboboxItem {...option} />} | ||
/> | ||
<DialogTrigger asChild> | ||
<Button icon={IvyIcons.ListSearch} aria-label='Browser' /> | ||
</DialogTrigger> | ||
</Flex> | ||
<BasicCheckbox label='Type as List' checked={typeAsList} onCheckedChange={change => typeAsListChange(change as boolean)} /> | ||
</BasicField> | ||
<DialogContent style={{ height: '80vh' }}> | ||
<Browser | ||
onChange={value => { | ||
onChange(value); | ||
if (value.startsWith('List<') && value.endsWith('>')) { | ||
setTypeAsList(true); | ||
} | ||
}} | ||
close={() => setOpen(false)} | ||
/> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
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