-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(1314737): [Boost] Add Proportional Attribute Component to the Fi…
…eldGuesser
- Loading branch information
1 parent
ebc3452
commit 8adebba
Showing
10 changed files
with
255 additions
and
9 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
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
52 changes: 52 additions & 0 deletions
52
...ts/src/components/molecules/ProportionalToAttributes/ProportionalToAttributes.stories.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,52 @@ | ||
import React, { useState } from 'react' | ||
import { ComponentMeta, ComponentStory } from '@storybook/react' | ||
import ProportionalToAttributesComponent, { | ||
IProportionalToAttributesValue, | ||
} from './ProportionalToAttributes' | ||
|
||
export default { | ||
title: 'Molecules/ProportionalToAttributesComponent', | ||
component: ProportionalToAttributesComponent, | ||
} as ComponentMeta<typeof ProportionalToAttributesComponent> | ||
|
||
const Template: ComponentStory<typeof ProportionalToAttributesComponent> = ( | ||
args | ||
) => { | ||
const [value, setValue] = useState<IProportionalToAttributesValue>({ | ||
sourceField: undefined, | ||
boostImpact: undefined, | ||
scaleFactor: 0, | ||
}) | ||
return ( | ||
<ProportionalToAttributesComponent | ||
{...args} | ||
value={value} | ||
onChange={(value): void => setValue(value)} | ||
/> | ||
) | ||
} | ||
|
||
export const ProportionalToAttributes = Template.bind({}) | ||
|
||
ProportionalToAttributes.args = { | ||
boostImpactOptions: [ | ||
{ | ||
label: 'Low', | ||
value: 'Low', | ||
}, | ||
{ | ||
label: 'Medium', | ||
value: 'Medium', | ||
}, | ||
{ | ||
label: 'High', | ||
value: 'High', | ||
}, | ||
], | ||
sourceFields: [ | ||
{ | ||
label: 'test', | ||
value: 'test', | ||
}, | ||
], | ||
} |
85 changes: 85 additions & 0 deletions
85
...components/src/components/molecules/ProportionalToAttributes/ProportionalToAttributes.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,85 @@ | ||
import React from 'react' | ||
import RadioGroup from '../../atoms/form/RadioGroup' | ||
import InputText from '../../atoms/form/InputText' | ||
import DropDown from '../../atoms/form/DropDown' | ||
import { styled } from '@mui/material' | ||
import { IOptions } from '@elastic-suite/gally-admin-shared' | ||
import { useTranslation } from 'next-i18next' | ||
|
||
const Container = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: theme.spacing(1), | ||
})) | ||
|
||
export interface IProportionalToAttributesValue { | ||
sourceField?: string | ||
boostImpact?: string | ||
scaleFactor: number | ||
} | ||
export interface IProportionalToAttributesProps { | ||
sourceFields: IOptions<string> | ||
boostImpactOptions: IOptions<string> | ||
value: IProportionalToAttributesValue | ||
showError?: boolean | ||
onChange: (value: IProportionalToAttributesValue) => void | ||
} | ||
|
||
function ProportionalToAttributes({ | ||
value, | ||
sourceFields, | ||
boostImpactOptions, | ||
showError, | ||
onChange, | ||
}: IProportionalToAttributesProps): JSX.Element { | ||
const { sourceField, boostImpact, scaleFactor } = value | ||
const { t } = useTranslation('boost') | ||
|
||
function handleChange( | ||
name: keyof IProportionalToAttributesProps['value'], | ||
newValue: string | number | ||
): void { | ||
onChange({ | ||
...value, | ||
[name]: newValue, | ||
}) | ||
} | ||
|
||
return ( | ||
<Container> | ||
<DropDown | ||
options={sourceFields} | ||
label={t('boostConfig.sourceField')} | ||
value={sourceField} | ||
onChange={(value: string): void => handleChange('sourceField', value)} | ||
required | ||
showError={showError} | ||
sx={{ minWidth: '230px' }} | ||
placeholder={t('boostConfig.sourceField.placeholder')} | ||
/> | ||
|
||
<RadioGroup | ||
options={boostImpactOptions} | ||
defaultValue={boostImpact} | ||
onChange={(value: string): void => handleChange('boostImpact', value)} | ||
label={t('boostConfig.boostImpact')} | ||
required | ||
showError={showError} | ||
/> | ||
|
||
<InputText | ||
type="number" | ||
label={t('boostConfig.scaleFactor')} | ||
required | ||
inputProps={{ | ||
min: 0, | ||
}} | ||
value={scaleFactor} | ||
onChange={(value: number): void => handleChange('scaleFactor', value)} | ||
showError={showError} | ||
/> | ||
</Container> | ||
) | ||
} | ||
|
||
export default ProportionalToAttributes |
65 changes: 65 additions & 0 deletions
65
...nts/src/components/molecules/ProportionalToAttributes/ProportionalToAttributesManager.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,65 @@ | ||
import React, { useMemo } from 'react' | ||
import { useApiList, useResource } from '../../../hooks' | ||
import ProportionalToAttributes, { | ||
IProportionalToAttributesProps, | ||
} from './ProportionalToAttributes' | ||
import { IOption } from '@elastic-suite/gally-admin-shared' | ||
|
||
function ProportionalToAttributesManager( | ||
props: Omit< | ||
IProportionalToAttributesProps, | ||
'sourceFields' | 'boostImpactOptions' | ||
> | ||
): JSX.Element { | ||
const rowsPerPage = 200 | ||
const sourceFieldFixedFilters = useMemo( | ||
() => ({ | ||
'metadata.entity': 'product', | ||
}), | ||
[] | ||
) | ||
|
||
const boostImpactOptionResource = useResource('BoostImpactOption') | ||
const boostAttributeValueFieldOptionsResource = useResource( | ||
'BoostAttributeValueFieldOption' | ||
) | ||
|
||
const [boostImpactOptionsResponse] = useApiList<IOption<string>>( | ||
boostImpactOptionResource, | ||
false, | ||
rowsPerPage, | ||
undefined, | ||
undefined, | ||
false, | ||
true | ||
) | ||
|
||
const [boostAttributeValueFieldOptionsResponse] = useApiList<IOption<string>>( | ||
boostAttributeValueFieldOptionsResource, | ||
false, | ||
rowsPerPage, | ||
sourceFieldFixedFilters, | ||
undefined, | ||
false, | ||
true | ||
) | ||
|
||
if ( | ||
!boostImpactOptionsResponse?.data || | ||
!boostAttributeValueFieldOptionsResponse?.data | ||
) { | ||
return null | ||
} | ||
|
||
return ( | ||
<ProportionalToAttributes | ||
sourceFields={ | ||
boostAttributeValueFieldOptionsResponse.data['hydra:member'] | ||
} | ||
boostImpactOptions={boostImpactOptionsResponse.data['hydra:member']} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export default ProportionalToAttributesManager |
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