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

Add images to the select provider in create provider form #536

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import React, { ReactNode } from 'react';

import { Card, CardBody, CardTitle } from '@patternfly/react-core';
import { Card, CardBody, CardTitle, Level, LevelItem } from '@patternfly/react-core';

interface SelectableCardProps {
/** The title of the card */
/** The title of the card. It can be any element - a string, a React component, etc. */
title: ReactNode;
/** The content of the card */
content: ReactNode;
/** Handler function to be called when the card is clicked */
/** Optional: A logo or symbol to be displayed along with the title. It can be any element - a string, a React component, etc. */
titleLogo?: ReactNode;
/** Optional: The content of the card. It can be any element - a string, a React component, etc. */
content?: ReactNode;
/** A function that will be called when the card is clicked. It receives a single argument, `isSelected`, which is a boolean indicating the selected state of the card. */
onChange: (isSelected: boolean) => void;
/** The selected state of the card */
/** A boolean indicating whether the card is currently selected. */
isSelected: boolean;
/** Optional: A boolean indicating whether the card should be displayed in a compact form. This may affect things like the card's padding and margin. */
isCompact?: boolean;
/** Optional: A string representing a CSS class name. This class will be applied to the card's top-level DOM element, allowing you to style the card with custom CSS. */
className?: string;
}

/**
Expand All @@ -19,9 +25,12 @@ interface SelectableCardProps {
*/
export const SelectableCard: React.FC<SelectableCardProps> = ({
title,
titleLogo,
content,
onChange,
isSelected,
isCompact,
className,
}) => {
// Handler function to toggle selection and call onChange
const handleClick = () => {
Expand All @@ -31,16 +40,27 @@ export const SelectableCard: React.FC<SelectableCardProps> = ({

return (
<Card
className="forklift-selectable-gallery-card"
className={`forklift-selectable-gallery-card ${className}`}
id="selectable-card"
onKeyDown={handleClick}
onClick={handleClick}
onSelectableInputChange={handleClick}
isSelectable
isCompact={isCompact}
isSelected={isSelected}
>
<CardTitle>{title}</CardTitle>
<CardBody>{content}</CardBody>
{titleLogo ? (
<CardTitle>
<Level className="forklift--create-provider-edit-card-title">
<LevelItem>{titleLogo}</LevelItem>
<LevelItem>{title}</LevelItem>
</Level>
</CardTitle>
) : (
<CardTitle>{title}</CardTitle>
)}

{content && <CardBody>{content}</CardBody>}
</Card>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React, { FC, ReactNode } from 'react';

import { Gallery, GalleryItem } from '@patternfly/react-core';

Expand All @@ -9,6 +9,8 @@ import './SelectableGallery.style.css';
export interface SelectableGalleryItem {
/** The title of the item */
title: string;
/** The logo of the item */
logo?: ReactNode;
/** The content of the item */
content: string;
}
Expand Down Expand Up @@ -58,6 +60,7 @@ export const SelectableGallery: FC<SelectableGalleryProps> = ({
<GalleryItem key={id}>
<SelectableCard
title={item.title}
titleLogo={item.logo}
content={item.content}
isSelected={id === selectedCardId}
onChange={(isSelected) => handleCardChange(isSelected, id)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
.forklift-create-provider-edit-section {
padding-top: var(--pf-global--spacer--md);
}
}

.forklift--create-provider-edit-card-selected {
min-width: 25%;
}

.forklift--create-provider-edit-card-title {
justify-content: normal;
}

.forklift--create-provider-edit-card-title-logo {
margin-right: var(--pf-global--spacer--sm);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Flex, FlexItem, Form, FormGroup, TextInput } from '@patternfly/react-co

import { EditProvider } from './EditProvider';
import { providerCardItems } from './providerCardItems';

export interface ProvidersCreateFormProps {
newProvider: V1beta1Provider;
newSecret: V1Secret;
Expand Down Expand Up @@ -101,12 +100,13 @@ export const ProvidersCreateForm: React.FC<ProvidersCreateFormProps> = ({
<FormGroup label={t('Select provider type')} isRequired fieldId="type">
{newProvider?.spec?.type ? (
<Flex>
<FlexItem>
<FlexItem className="forklift--create-provider-edit-card-selected">
<SelectableCard
title={providerCardItems[newProvider?.spec?.type]?.title}
content={providerCardItems[newProvider?.spec?.type]?.content}
titleLogo={providerCardItems[newProvider?.spec?.type]?.logo}
onChange={() => handleTypeChange(null)}
isSelected={true}
isSelected
isCompact
/>
</FlexItem>
</Flex>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { SelectableGalleryItem } from 'src/modules/Providers/utils/components/Galerry/SelectableGallery';

import openshiftImg from '../images/openshift.svg';
import openstackImg from '../images/openstack.svg';
import redhatImg from '../images/redhat.svg';
import vmImg from '../images/vm.svg';

const openshiftLogo = (
<img
className="forklift--create-provider-edit-card-title-logo"
src={openshiftImg}
alt="PatternFly logo"
width="27px"
/>
);

const openstackLogo = (
<img
className="forklift--create-provider-edit-card-title-logo"
src={openstackImg}
alt="PatternFly logo"
width="27px"
/>
);

const vmLogo = (
<img
className="forklift--create-provider-edit-card-title-logo"
src={vmImg}
alt="PatternFly logo"
width="27px"
/>
);

const redhatLogo = (
<img
className="forklift--create-provider-edit-card-title-logo"
src={redhatImg}
alt="PatternFly logo"
width="27px"
/>
);

export const providerCardItems: Record<string, SelectableGalleryItem> = {
openshift: {
title: 'OpenShift Virtualization',
logo: openshiftLogo,
content: 'OpenShift Virtualization run and manage virtual machine in Openshift.',
},
openstack: {
title: 'OpenStack',
logo: openstackLogo,
content: 'OpenStack is a cloud computing platform that controls large pools of resources.',
},
ovirt: {
title: 'Red Hat Virtualization',
logo: redhatLogo,
content: 'Red Hat Virtualization (RHV) is a virtualization platform from Red Hat.',
},
vsphere: {
title: 'vSphere',
logo: vmLogo,
content: "vSphere is VMware's cloud computing virtualization platform.",
},
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading