-
Notifications
You must be signed in to change notification settings - Fork 167
feat: Add feature selection capability to Bedrock Content Generator [] #10276
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { Dispatch } from 'react'; | ||
| import { | ||
| Box, | ||
| Flex, | ||
| FormControl, | ||
| Subheading, | ||
| Paragraph, | ||
| Checkbox, | ||
| } from '@contentful/f36-components'; | ||
| import { Sections } from '../configText'; | ||
| import { ParameterReducer, ParameterAction } from '../parameterReducer'; | ||
| import featureConfig, { AIFeature } from '@configs/features/featureConfig'; | ||
| import { css } from '@emotion/react'; | ||
|
|
||
| export const styles = css({ | ||
| width: '100%', | ||
| '& > *': { | ||
| marginBottom: '8px', | ||
| }, | ||
| }); | ||
|
|
||
| interface Props { | ||
| enabledFeatures: AIFeature[]; | ||
| dispatch: Dispatch<ParameterReducer>; | ||
| } | ||
|
|
||
| const FeatureSelectionSection = ({ enabledFeatures, dispatch }: Props) => { | ||
| const allFeatures = Object.keys(featureConfig) as AIFeature[]; | ||
|
|
||
| const handleFeatureToggle = (feature: AIFeature, isChecked: boolean) => { | ||
| if (isChecked) { | ||
| // Remove feature - but prevent if it's the last one | ||
| if (enabledFeatures.length === 1) { | ||
| return; // Prevent removing the last feature | ||
| } | ||
| const updatedFeatures = enabledFeatures.filter((f) => f !== feature); | ||
| dispatch({ | ||
| type: ParameterAction.UPDATE_ENABLED_FEATURES, | ||
| value: updatedFeatures, | ||
| }); | ||
| } else { | ||
| // Add feature | ||
| const updatedFeatures = [...enabledFeatures, feature]; | ||
| dispatch({ | ||
| type: ParameterAction.UPDATE_ENABLED_FEATURES, | ||
| value: updatedFeatures, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| const isFeatureEnabled = (feature: AIFeature) => { | ||
| return enabledFeatures.includes(feature); | ||
| }; | ||
|
|
||
| return ( | ||
| <Flex flexDirection="column" alignItems="flex-start" fullWidth={true}> | ||
| <Subheading>{Sections.featureSelectionHeading}</Subheading> | ||
| <Paragraph>{Sections.featureSelectionDescription}</Paragraph> | ||
| <Box css={styles}> | ||
| <FormControl as="fieldset" marginBottom="none"> | ||
| {allFeatures.map((feature) => { | ||
| const featureConfigItem = featureConfig[feature]; | ||
| return ( | ||
| <Checkbox | ||
| key={feature} | ||
| id={feature} | ||
| isChecked={isFeatureEnabled(feature)} | ||
| onChange={() => handleFeatureToggle(feature, isFeatureEnabled(feature))} | ||
| isDisabled={enabledFeatures.length === 1 && isFeatureEnabled(feature)}> | ||
| {featureConfigItem.buttonTitle} | ||
| </Checkbox> | ||
| ); | ||
| })} | ||
| </FormControl> | ||
| </Box> | ||
| </Flex> | ||
| ); | ||
| }; | ||
|
|
||
| export default FeatureSelectionSection; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,25 +2,33 @@ import AppInstallationParameters from '@components/config/appInstallationParamet | |
| import { SidebarAppSDK } from '@contentful/app-sdk'; | ||
| import { useSDK } from '@contentful/react-apps-toolkit'; | ||
| import { useEffect, useState } from 'react'; | ||
| import featureConfig, { AIFeature } from '@configs/features/featureConfig'; | ||
|
|
||
| /** | ||
| * This hook is used to get the installation parameters from the sidebar location, | ||
| * checks to see if there is a brand profile, validates the API Key and returns any errors | ||
| * | ||
| * @returns {hasBrandProfile, apiError} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this hook didn't actually return an apiError to begin with?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i guess not. looking at it, it's pretty clear. I removed this to get rid of a lint warning |
||
| * @returns {hasBrandProfile, enabledFeatures} | ||
| */ | ||
| const useSidebarParameters = () => { | ||
| const [hasBrandProfile, setHasBrandProfile] = useState(true); | ||
|
|
||
| const sdk = useSDK<SidebarAppSDK<AppInstallationParameters>>(); | ||
| const { profile } = sdk.parameters.installation; | ||
| const { profile, enabledFeatures } = sdk.parameters.installation; | ||
|
|
||
| useEffect(() => { | ||
| setHasBrandProfile(!!profile); | ||
| }, [profile]); | ||
|
|
||
| // Default to all features if enabledFeatures is not set (for backward compatibility) | ||
| const features = | ||
| enabledFeatures && enabledFeatures.length > 0 | ||
| ? enabledFeatures | ||
| : (Object.keys(featureConfig) as AIFeature[]); | ||
|
|
||
| return { | ||
| hasBrandProfile, | ||
| enabledFeatures: features, | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.