-
Notifications
You must be signed in to change notification settings - Fork 22
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 #1119 from yaacov/handle-different-secret-data-types
🧼 Update fields clipboard copy to handle boolean and long texts
- Loading branch information
Showing
11 changed files
with
134 additions
and
50 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
75 changes: 75 additions & 0 deletions
75
.../modules/Providers/views/details/components/CredentialsSection/FieldWithClipboardCopy.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,75 @@ | ||
import React from 'react'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { ClipboardCopy, Switch, TextInput, Tooltip } from '@patternfly/react-core'; | ||
|
||
import { Field } from './components/list/Fields'; | ||
|
||
export interface ShowFieldWithClipboardCopyProps { | ||
value: string; | ||
field?: Field; | ||
} | ||
|
||
/** | ||
* Displays a field with its value. If the value is empty, shows a disabled text input with a tooltip indicating the field is missing. | ||
* If the value is non-empty, displays the value in a read-only format with a clipboard copy functionality. | ||
* | ||
* @property {string} value - The value of the field to display. | ||
* @property {object} field - Object containing details about the field such as label and display type. | ||
*/ | ||
export const FieldWithClipboardCopy: React.FC<ShowFieldWithClipboardCopyProps> = ({ | ||
field, | ||
value, | ||
}) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
// Render tooltip for missing value | ||
if (!value) { | ||
return ( | ||
<Tooltip | ||
content={ | ||
<div>{t('{{label}} field is missing from the secret data.', { label: field.label })}</div> | ||
} | ||
> | ||
<TextInput value="No value" type="text" isDisabled /> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
// Determine how to display the field based on its type | ||
const renderFieldByType = () => { | ||
switch (field.displayType) { | ||
case 'textArea': | ||
return ( | ||
<ClipboardCopy | ||
isReadOnly | ||
hoverTip={t('Copy')} | ||
clickTip={t('Copied')} | ||
isCode | ||
variant="expansion" | ||
> | ||
{value} | ||
</ClipboardCopy> | ||
); | ||
case 'switch': | ||
return ( | ||
<Switch | ||
aria-label={`Switch for ${field.label}`} | ||
label={`${field.label} is set`} | ||
labelOff={`${field.label} is not set`} | ||
isChecked={value.toLocaleLowerCase() === 'true'} | ||
hasCheckIcon | ||
isDisabled | ||
/> | ||
); | ||
default: | ||
return ( | ||
<ClipboardCopy isReadOnly hoverTip={t('Copy')} clickTip={t('Copied')} isCode> | ||
{value} | ||
</ClipboardCopy> | ||
); | ||
} | ||
}; | ||
|
||
return renderFieldByType(); | ||
}; |
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
35 changes: 0 additions & 35 deletions
35
...ules/Providers/views/details/components/CredentialsSection/ShowFieldWithClipboardCopy.tsx
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...c/modules/Providers/views/details/components/CredentialsSection/components/list/Fields.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,14 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export type Field = { | ||
label: string; | ||
description: ReactNode; | ||
helperTextPopover?: ReactNode; | ||
cacertHelperTextPopover?: ReactNode; | ||
displayType?: 'text' | 'textArea' | 'switch'; | ||
}; | ||
|
||
// Define the type for the object containing all fields | ||
export type Fields = { | ||
[key: string]: Field; | ||
}; |
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
1 change: 1 addition & 0 deletions
1
...rc/modules/Providers/views/details/components/CredentialsSection/components/list/index.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
Oops, something went wrong.