Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show tooltip on defined widget #3071

Merged
merged 8 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/extensibility/60-form-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ The `Text` widgets render a field as a text field. They are used by default for

These are the available `Text` widget parameters:

| Parameter | Required | Type | Description |
| --------------------- | -------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **enum[]** | No | an array of options | Generate an input field with a dropdown. Optionally can be a string containing a [JSONata](jsonata.md) expression returning an array of options. |
| **placeholder** | No | string | Specifies a short hint about the input field value. |
| **required** | No | boolean | Specifies if a field is required. The default value is taken from CustomResourceDefintion (CRD); if it doesn't exist in the CRD, then it defaults to `false`. |
| **inputInfo** | No | string | A string below the input field that shows how to fill in the input. You can use the {{ [`name`] (`link`) }} format to display a `name` instead of a `link. |
| **description** | No | string | A string displayed in a tooltip when you hover over a question mark icon, next to the input's label. The default value is taken from the CustomResourceDefintion (CRD). |
| **readOnly** | No | boolean | Specifies if a field is read-only. Defaults to `false`. |
| **decodable** | No | boolean | Specifies that the field is base64-encoded and can be decoded in the UI. It can't be used together with **enum**. |
| **decodedPlacehoder** | No | string | An optional alternative placeholder to use when the field is decoded. |
| Parameter | Required | Type | Description |
| --------------------- | -------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **enum[]** | No | an array of options | Generate an input field with a dropdown. Optionally can be a string containing a [JSONata](jsonata.md) expression returning an array of options. |
| **placeholder** | No | string | Specifies a short hint about the input field value. |
| **required** | No | boolean | Specifies if a field is required. The default value is taken from CustomResourceDefintion (CRD); if it doesn't exist in the CRD, then it defaults to `false`. |
| **inputInfo** | No | string | A string below the input field that shows how to fill in the input. You can use the {{ [`name`] (`link`) }} format to display a `name` instead of a `link. |
| **description** | No | string | A string displayed in a tooltip when you hover over a question mark icon, next to the input's label. The default value is taken from the CustomResourceDefintion (CRD). The tooltip can be disabled by placing empty string. |
mrCherry97 marked this conversation as resolved.
Show resolved Hide resolved
| **readOnly** | No | boolean | Specifies if a field is read-only. Defaults to `false`. |
| **decodable** | No | boolean | Specifies that the field is base64-encoded and can be decoded in the UI. It can't be used together with **enum**. |
| **decodedPlacehoder** | No | string | An optional alternative placeholder to use when the field is decoded. |

See the following examples:

Expand Down
1 change: 0 additions & 1 deletion src/components/Clusters/views/ClusterStorageType.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function ClusterStorageType({ clusterConfig }) {
setShowTitleDescription={setShowDescription}
showTitleDescription={showDescription}
description={tooltipContent}
context="storage-type"
></HintButton>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/Extensibility/components-form/FormGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ export function FormGroup({
}) {
const { WidgetRenderer } = widgets;
const ownSchema = schema.delete('widget');
const { tFromStoreKeys } = useGetTranslation();
const { tFromStoreKeys, t: tExt } = useGetTranslation();

const columns = schema.get('columns');
const gridTemplateColumns = `repeat(${columns}, 1fr)`;

const defaultOpen = schema.get('defaultExpanded') ?? false;
const schemaRequired = schema.get('required') ?? required;
const tooltipContent = schema.get('description');

return (
<ResourceForm.CollapsibleSection
title={tFromStoreKeys(storeKeys, schema)}
defaultOpen={defaultOpen}
nestingLevel={nestingLevel}
required={schemaRequired}
tooltipContent={tExt(tooltipContent)}
>
<div className="form-group__grid-wrapper" style={{ gridTemplateColumns }}>
<WidgetRenderer
Expand Down
2 changes: 2 additions & 0 deletions src/components/Extensibility/components-form/GenericList.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function GenericList({
const schemaPlaceholder = schema.get('placeholder');
const itemTemplate = schema.get('template') || {};
const defaultOpen = schema.get('defaultExpanded') ?? false;
const tooltipContent = schema.get('description');
const [newItemIndex, setNewItemIndex] = useState(0);

const addItem = itemTemplate => {
Expand Down Expand Up @@ -55,6 +56,7 @@ export function GenericList({
return (
<ResourceForm.CollapsibleSection
defaultOpen={defaultOpen}
tooltipContent={t(tooltipContent)}
container
title={tFromStoreKeys(storeKeys, schema)}
nestingLevel={nestingLevel}
Expand Down
2 changes: 0 additions & 2 deletions src/components/KymaModules/KymaModulesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ export function KymaModulesList(props) {
setShowTitleDescription={setShowReleaseChannelTitleDescription}
showTitleDescription={showReleaseChannelTitleDescription}
description={ReleaseChannelDescription}
context="details-release-channel"
/>
</FlexBox>
</DynamicPageHeader>
Expand All @@ -443,7 +442,6 @@ export function KymaModulesList(props) {
setShowTitleDescription={setShowTitleDescription}
showTitleDescription={showTitleDescription}
description={ResourceDescription}
context="modules"
/>
}
</>
Expand Down
1 change: 0 additions & 1 deletion src/shared/ResourceForm/components/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function FormField({
setShowTitleDescription={setOpenPopover}
showTitleDescription={openPopover}
description={tooltipContent}
context={props['data-testid'] ?? label}
style={spacing.sapUiTinyMarginBegin}
/>
)}
Expand Down
1 change: 0 additions & 1 deletion src/shared/ResourceForm/components/Title.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export function Title({
setShowTitleDescription={setOpenPopover}
showTitleDescription={openPopover}
description={tooltipContent}
context={title}
style={spacing.sapUiTinyMarginBegin}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { Button, Popover, Text } from '@ui5/webcomponents-react';
import { createPortal } from 'react-dom';
import { useRef } from 'react';
import React, { CSSProperties, ReactNode, useRef, useState } from 'react';
import { uniqueId } from 'lodash';

type HintButtonProps = {
setShowTitleDescription: React.Dispatch<React.SetStateAction<boolean>>;
showTitleDescription: boolean;
description: string | ReactNode;
style?: CSSProperties;
};

export function HintButton({
setShowTitleDescription,
showTitleDescription,
description,
style,
context,
}) {
}: HintButtonProps) {
const [ID] = useState(uniqueId('id-')); //todo: migrate to useID from react after upgrade to version 18+
const descBtnRef = useRef(null);
return (
<>
<Button
id={`descriptionOpener-${context}`}
id={`descriptionOpener-${ID}`}
ref={descBtnRef}
icon="hint"
design="Transparent"
Expand All @@ -25,9 +33,10 @@ export function HintButton({
/>
{createPortal(
<Popover
opener={`descriptionOpener-${context}`}
opener={`descriptionOpener-${ID}`}
//Point initial focus to other component removes the focus from the link in description
onAfterOpen={() => {
// @ts-ignore
descBtnRef.current.focus();
}}
open={showTitleDescription}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export const DynamicPageComponent = ({
setShowTitleDescription={setShowTitleDescription}
showTitleDescription={showTitleDescription}
description={description}
context="dynamic"
/>
)}
</FlexBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export const Pagination = ({
setShowTitleDescription={setShowInfo}
showTitleDescription={showInfo}
description={t('settings.other.info')}
context="pagination"
/>
</div>

Expand Down
1 change: 0 additions & 1 deletion src/shared/components/ResourceDetails/ResourceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ function Resource({
setShowTitleDescription={setShowTitleDescription}
showTitleDescription={showTitleDescription}
description={description}
context="details"
/>
)}
</div>
Expand Down
Loading