-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checkbox data object data type (#818)
- Loading branch information
1 parent
8a16e49
commit d11c5a7
Showing
36 changed files
with
2,071 additions
and
1,967 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
64 changes: 64 additions & 0 deletions
64
...lement/dynamic-types/defintinitions/objects/data-related/components/checkbox/checkbox.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,64 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React, { useContext, useEffect, useState } from 'react' | ||
import { Checkbox as AntCheckbox, type CheckboxProps as AntCheckboxProps, Tooltip } from 'antd' | ||
import { useDataObjectDraft } from '@Pimcore/modules/data-object/hooks/use-data-object-draft' | ||
import { DataObjectContext } from '@Pimcore/modules/data-object/data-object-provider' | ||
import { Flex } from '@Pimcore/components/flex/flex' | ||
import { IconButton } from '@Pimcore/components/icon-button/icon-button' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
export interface CheckboxProps extends Omit<AntCheckboxProps, 'value' | 'onChange'> { | ||
value?: boolean | null | ||
onChange?: (value?: boolean | null) => void | ||
} | ||
|
||
export const Checkbox = (props: CheckboxProps): React.JSX.Element => { | ||
const [value, setValue] = useState<boolean | null>(props.value ?? null) | ||
const { id } = useContext(DataObjectContext) | ||
const { dataObject } = useDataObjectDraft(id) | ||
const { t } = useTranslation() | ||
|
||
useEffect(() => { | ||
if (props.onChange !== undefined) { | ||
props.onChange(value) | ||
} | ||
}, [value]) | ||
|
||
const onChange = (e): void => { | ||
const newValue = Boolean(e.nativeEvent.target.checked) | ||
setValue(newValue ?? null) | ||
props.onChange?.(newValue) | ||
} | ||
|
||
const showClearButton = value !== null && dataObject?.allowInheritance === true && props.disabled !== true | ||
|
||
return ( | ||
<Flex gap="extra-small"> | ||
<AntCheckbox | ||
{ ...props } | ||
checked={ value ?? false } | ||
onChange={ onChange } | ||
/> | ||
{ showClearButton && ( | ||
<Tooltip title={ t('set-to-null') }> | ||
<IconButton | ||
icon={ { value: 'trash' } } | ||
onClick={ () => { setValue(null) } } | ||
/> | ||
</Tooltip> | ||
)} | ||
</Flex> | ||
) | ||
} |
34 changes: 34 additions & 0 deletions
34
...mic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-checkbox.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,34 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React from 'react' | ||
import { | ||
type AbstractObjectDataDefinition, DynamicTypeObjectDataAbstract | ||
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/dynamic-type-object-data-abstract' | ||
import { | ||
Checkbox | ||
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/components/checkbox/checkbox' | ||
|
||
export type CheckboxObjectDataDefinition = AbstractObjectDataDefinition | ||
|
||
export class DynamicTypeObjectDataCheckbox extends DynamicTypeObjectDataAbstract { | ||
id: string = 'checkbox' | ||
|
||
getObjectDataComponent (props: CheckboxObjectDataDefinition): React.ReactElement<AbstractObjectDataDefinition> { | ||
return ( | ||
<Checkbox | ||
disabled={ props.noteditable === true } | ||
/> | ||
) | ||
} | ||
} |
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
9 changes: 0 additions & 9 deletions
9
public/build/148fe31c-4497-4d59-a2a2-0258933183c4/entrypoints.json
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
public/build/148fe31c-4497-4d59-a2a2-0258933183c4/manifest.json
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
public/build/41c305ca-0743-480f-b594-68a48854a039/entrypoints.json
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,9 @@ | ||
{ | ||
"entrypoints": { | ||
"vendor": { | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/41c305ca-0743-480f-b594-68a48854a039/vendor.js" | ||
] | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
public/build/41c305ca-0743-480f-b594-68a48854a039/manifest.json
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 @@ | ||
{ | ||
"bundles/pimcorestudioui/build/41c305ca-0743-480f-b594-68a48854a039/vendor.js": "/bundles/pimcorestudioui/build/41c305ca-0743-480f-b594-68a48854a039/vendor.js" | ||
} |
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions
9
public/build/81fa6fd1-84a1-4982-b7e5-ae857ea82cd9/entrypoints.json
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
public/build/81fa6fd1-84a1-4982-b7e5-ae857ea82cd9/manifest.json
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
public/build/b6cb9a55-1aa8-45e5-86ae-a94677be0726/entrypoints.json
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,9 @@ | ||
{ | ||
"entrypoints": { | ||
"main": { | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/b6cb9a55-1aa8-45e5-86ae-a94677be0726/main.js" | ||
] | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
public/build/b6cb9a55-1aa8-45e5-86ae-a94677be0726/manifest.json
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 @@ | ||
{ | ||
"bundles/pimcorestudioui/build/b6cb9a55-1aa8-45e5-86ae-a94677be0726/main.js": "/bundles/pimcorestudioui/build/b6cb9a55-1aa8-45e5-86ae-a94677be0726/main.js" | ||
} |
2 changes: 0 additions & 2 deletions
2
public/build/e7b5d703-4178-4660-8486-d48e24bc69cb/core-dll.js
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
public/build/e7b5d703-4178-4660-8486-d48e24bc69cb/entrypoints.json
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...-4178-4660-8486-d48e24bc69cb/core-dll.css → ...-67db-489a-bd70-1ad2e2ea76c2/core-dll.css
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
public/build/ed594057-67db-489a-bd70-1ad2e2ea76c2/core-dll.js
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
public/build/ed594057-67db-489a-bd70-1ad2e2ea76c2/entrypoints.json
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,12 @@ | ||
{ | ||
"entrypoints": { | ||
"core-dll": { | ||
"css": [ | ||
"/bundles/pimcorestudioui/build/ed594057-67db-489a-bd70-1ad2e2ea76c2/core-dll.css" | ||
], | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/ed594057-67db-489a-bd70-1ad2e2ea76c2/core-dll.js" | ||
] | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.