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

feat(lb-components): Add multi-select functionality in subAttributeList #458

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -59,7 +59,8 @@
}
.attributeList {
flex: 1;
overflow: auto;
overflow-x: hidden;
overflow-y: auto;
:global {
.sensebee-radio-group,
.sensebee-radio-group-no-limit-height .ant-radio-group {
Expand Down
65 changes: 50 additions & 15 deletions packages/lb-components/src/components/subAttributeList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @createdate 2024-4-30
*/
import React from 'react';
import { Select, Divider } from 'antd';
import { Select, Divider, Checkbox } from 'antd';
import { useTranslation } from 'react-i18next';
import AttributeList from '@/components/attributeList';

Expand All @@ -27,6 +27,24 @@ const SubAttributeList = (props: IProps) => {
const { subAttributeList, setSubAttribute, getValue } = props;
const { t } = useTranslation();

const setSubAttributeValue = (value: string, subAttribute: string | string[]) => {
if (Array.isArray(subAttribute)) {
setSubAttribute(value, subAttribute.join(';'));
return;
}
setSubAttribute(value, subAttribute);
};

const getInputValue = (subAttribute: IInputList) => {
const value = getValue(subAttribute);

if (subAttribute?.isMulti) {
return value ? value?.split(';') : [];
}

return value;
};

return (
<>
{subAttributeList.map(
Expand All @@ -37,24 +55,41 @@ const SubAttributeList = (props: IProps) => {
{t('SubAttribute')}-{subAttribute.key}
</div>
{subAttribute.subSelected?.length < 5 ? (
<AttributeList
list={subAttribute.subSelected.map((v: IInputList) => ({
label: v.key,
value: v.value,
}))}
selectedAttribute={getValue(subAttribute)}
num='-'
forbidColor={true}
forbidDefault={true}
attributeChanged={(value) => setSubAttribute(subAttribute.value, value)}
style={{ marginBottom: 12 }}
/>
subAttribute?.isMulti ? (
<Checkbox.Group
Glenfiddish marked this conversation as resolved.
Show resolved Hide resolved
style={{
padding: `0px 21px 17px 16px`,
Glenfiddish marked this conversation as resolved.
Show resolved Hide resolved
}}
options={subAttribute.subSelected.map((v: IInputList) => ({
label: v.key,
value: v.value,
}))}
value={getInputValue(subAttribute) as string[]}
onChange={(value) =>
setSubAttributeValue(subAttribute.value, value as string[])
}
/>
) : (
<AttributeList
list={subAttribute.subSelected.map((v: IInputList) => ({
label: v.key,
value: v.value,
}))}
selectedAttribute={getValue(subAttribute)}
num='-'
forbidColor={true}
forbidDefault={true}
attributeChanged={(value) => setSubAttribute(subAttribute.value, value)}
style={{ marginBottom: 12 }}
/>
)
) : (
<Select
style={{ margin: '0px 21px 17px 16px', width: '87%' }}
value={getValue(subAttribute)}
mode={subAttribute?.isMulti ? 'multiple' : undefined}
value={getInputValue(subAttribute)}
placeholder={t('PleaseSelect')}
onChange={(value) => setSubAttribute(subAttribute.value, value)}
onChange={(value) => setSubAttributeValue(subAttribute.value, value)}
allowClear={true}
>
{subAttribute.subSelected.map((sub: any) => (
Expand Down
Loading