Skip to content

Commit

Permalink
feat: adding check marks for validation of the form on template and a…
Browse files Browse the repository at this point in the history
…lready adding plugins

Signed-off-by: Antonio Sonis <[email protected]>
  • Loading branch information
tonysnowboardunderthebridge committed Nov 30, 2023
1 parent ec66c5a commit 2a2abf5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function ConfigureEnvVarsTemplateAndPlugins ({
return (
<div className={`${commonStyles.mediumFlexRow} ${commonStyles.itemsStart} ${styles.scrollableSection}`}>
<TemplateAndPluginTreeSelector
configuredServices={configuredServices}
pluginSelected={pluginSelected}
serviceSelected={serviceSelected}
onTemplateSelected={onServiceSelected}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const ConfigureServices = React.forwardRef(({ onNext }, ref) => {
tmpObj.validations = { ...tmpTemplateValidations }
tmpObj.validForm = tmpTemplateValidForm
tmpObj.updatedAt = new Date().toISOString()
tmpObj.plugins = []
})
setConfiguredServices([...configuredServices, tmpObj])
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
'use strict'
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { MEDIUM, SMALL, TRANSPARENT, WHITE } from '@platformatic/ui-components/src/components/constants'
import { ERROR_RED, MAIN_GREEN, MEDIUM, SMALL, TRANSPARENT, WHITE } from '@platformatic/ui-components/src/components/constants'
import Icons from '@platformatic/ui-components/src/components/icons'
import typographyStyles from '~/styles/Typography.module.css'
import styles from './TemplateAndPluginTreeSelector.module.css'
import commonStyles from '~/styles/CommonStyles.module.css'
import { BorderedBox, PlatformaticIcon } from '@platformatic/ui-components'
import useStackablesStore from '~/useStackablesStore'

function TemplateSelector ({ onTemplateSelected, service, serviceSelected }) {
let className = `${typographyStyles.desktopHeadline5} ${typographyStyles.textWhite} ${styles.ellipsisTemplate}`
if (serviceSelected?.template !== service.template.name) {
if (serviceSelected?.template !== service.template) {
className += ` ${typographyStyles.opacity70}`
}
return (
<div className={`${commonStyles.smallFlexRow} ${styles.cursorPointer} ${styles.overflowHidden}`} onClick={() => onTemplateSelected(service)}>
<div
className={`${commonStyles.smallFlexRow} ${styles.cursorPointer} ${styles.overflowHidden}`}
onClick={() => onTemplateSelected(service)}
data-cy='template-selector'
>
<Icons.ServiceIcon color={WHITE} size={MEDIUM} />
<h5 className={className}>{service.name}</h5>
{service.validForm ? <Icons.CircleCheckMarkIcon color={MAIN_GREEN} size={SMALL} /> : <Icons.AlertIcon color={ERROR_RED} size={SMALL} />}
</div>
)
}
Expand Down Expand Up @@ -58,28 +62,28 @@ function PluginSelector ({ onPluginSelected, service, plugin, pluginSelected })
<div
className={`${commonStyles.smallFlexRow} ${commonStyles.fullWidth} ${styles.cursorPointer} ${styles.overflowHidden}`}
onClick={() => onPluginSelected(service, plugin)}
data-cy='plugin-selector'
>
<Icons.StackablesPluginIcon color={WHITE} size={SMALL} />
<span className={className} title={plugin.name}>{plugin.name}</span>
{plugin.validForm ? <Icons.CircleCheckMarkIcon color={MAIN_GREEN} size={SMALL} /> : <Icons.AlertIcon color={ERROR_RED} size={SMALL} />}

</div>
)
}

function TemplateAndPluginTreeSelector ({ onTemplateSelected, onPluginSelected, serviceSelected, pluginSelected }) {
const globalState = useStackablesStore()
const { services } = globalState

function TemplateAndPluginTreeSelector ({ configuredServices, onTemplateSelected, onPluginSelected, serviceSelected, pluginSelected }) {
function handlePluginSelected (service, plugin) {
onPluginSelected(service, plugin)
}

return (
<BorderedBox color={WHITE} borderColorOpacity={30} backgroundColor={TRANSPARENT} classes={`${commonStyles.fullWidth} ${styles.container}`}>
<div className={`${commonStyles.mediumFlexBlock} ${commonStyles.fullWidth}`}>
{services.map(service => (
<div className={`${commonStyles.smallFlexBlock} ${commonStyles.fullWidth} ${commonStyles.overflowHidden}`} key={service.name}>
<TemplateSelector onTemplateSelected={onTemplateSelected} service={{ ...service }} serviceSelected={serviceSelected} />
{service.plugins.length > 0 && <PluginsContainer service={service} onPluginSelected={handlePluginSelected} pluginSelected={pluginSelected} />}
{configuredServices.map(configuredService => (
<div className={`${commonStyles.smallFlexBlock} ${commonStyles.fullWidth} ${commonStyles.overflowHidden}`} key={configuredService.name}>
<TemplateSelector onTemplateSelected={onTemplateSelected} service={{ ...configuredService }} serviceSelected={serviceSelected} />
{configuredService.plugins.length > 0 && <PluginsContainer service={configuredService} onPluginSelected={handlePluginSelected} pluginSelected={pluginSelected} />}
</div>
))}
</div>
Expand All @@ -88,6 +92,11 @@ function TemplateAndPluginTreeSelector ({ onTemplateSelected, onPluginSelected,
}

TemplateAndPluginTreeSelector.propTypes = {
/**
* configuredServices
*/
configuredServices: PropTypes.array.isRequired,
/**
/**
* onTemplateSelected
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
.ellipsisTemplate {
@apply truncate;
width: 12rem;
max-width: 10rem;
}
.ellipsisPlugin {
@apply truncate;
Expand Down

0 comments on commit 2a2abf5

Please sign in to comment.