Skip to content

Commit

Permalink
fix(propertyselector): fix bug (#1607)
Browse files Browse the repository at this point in the history
Co-authored-by: maxin <maxin@growingio.com>
Co-authored-by: GEARLESS JOE <31471551+berber1016@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 3, 2021
1 parent 2f84d5e commit d477af8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
28 changes: 17 additions & 11 deletions src/legacy/property-selector/PropertyPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const ExpandableGroupOrSubGroup = (props: {
};

const pinyinMatch = pinyin.default;
const Tabs = toPairs(PropertyTypes).map((v) => ({ key: v[0], children: v[1] }));

const PropertyPicker: React.FC<PropertyPickerProps> = (props: PropertyPickerProps) => {
const {
Expand All @@ -82,6 +81,7 @@ const PropertyPicker: React.FC<PropertyPickerProps> = (props: PropertyPickerProp
} = props;
const locale = useLocale('PropertyPicker');
const localeText = { ...defaultLocale, ...locale } as typeof defaultLocale;
const Tabs = toPairs(PropertyTypes(localeText)).map((v) => ({ key: v[0], children: v[1] }));
const [scope, setScope] = useState('all');
const [keyword, setKeyword] = useState<string | undefined>('');
const [recentlyUsedInMemo, setRecentlyUsedInMemo] = useState<{
Expand Down Expand Up @@ -320,6 +320,20 @@ const PropertyPicker: React.FC<PropertyPickerProps> = (props: PropertyPickerProp
<List.Divider key="divider-group-recently" />
</React.Fragment>
);

const groupFn = (item: PropertyItem, existIsSystem: boolean) => {
if (existIsSystem) {
if (item.groupId === 'tag') {
return 'tag';
}
if (item.groupId === 'virtual') {
return 'virtual';
}
return item.isSystem;
}
return item.groupId;
};

const groupDataNodes = keys(groupDatasource).map((key, index) => {
const groupData = groupDatasource[key];
const existIsSystem = has(groupData, '[0].isSystem');
Expand Down Expand Up @@ -350,18 +364,10 @@ const PropertyPicker: React.FC<PropertyPickerProps> = (props: PropertyPickerProp
acc.push(...cur);
return acc;
}, []),
existIsSystem ? 'isSystem' : 'groupId'
(item) => groupFn(item, existIsSystem)
);
} else {
subGroupDic = groupBy(groupData, (item) => {
if (existIsSystem) {
if (item.groupId === 'tag') {
return 'tag';
}
return item.isSystem;
}
return item.groupId;
});
subGroupDic = groupBy(groupData, (item) => groupFn(item, existIsSystem));
}

const { typeName } = groupData[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ExpandItem({ className, title, ...restProps }: ExpandItemProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
<li role="option" aria-selected {...restProps} className={cls}>
<DownOutlined className={`${prefixCls}__icon`} size="14px" />
<span className={`${prefixCls}__text`}>{title ?? localeTextObject.expandAll()}</span>
<span className={`${prefixCls}__text`}>{title ?? localeTextObject.expandAll?.()}</span>
</li>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/property-selector/components/list/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function renderExpandableItems(
.map(renderItem)
.concat(
<ExpandItem
title={localesText.expandAll(currentItems.length - showItems.length)}
title={localesText.expandAll?.(currentItems.length - showItems.length)}
key={`expand-item-${currentItems[0].key}-${showItems.length + 1}`}
onClick={onExpand}
/>
Expand Down
21 changes: 11 additions & 10 deletions src/legacy/property-selector/demos/insightDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ const insightDimensions: ReadonlyArray<any> = [
type: 'global',
valueType: 'string',
},
{
id: 'vvar_virtual_1',
associatedKey: null,
description: null,
groupId: 'virtual',
groupName: 'Virtual Variable',
name: '虚拟属性1',
type: 'vvar',
valueType: 'string',
isSystem: false,
},
{
associatedKey: null,
description:
Expand Down Expand Up @@ -822,16 +833,6 @@ const insightDimensions: ReadonlyArray<any> = [
type: 'global',
valueType: 'string',
},
{
id: 'vvar_virtual_1',
associatedKey: null,
description: null,
groupId: 'virtual',
groupName: 'Virtual Variable',
name: '虚拟属性1',
type: 'vvar',
valueType: 'string',
},
];

export default insightDimensions;
4 changes: 2 additions & 2 deletions src/legacy/property-selector/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default {
device: 'Device',
element: 'Autotrack Event',
tag: 'User Tags',
preset: (text: Key) => `Preset ${text}`,
custom: (text: Key) => `Custom ${text}`,
preset: (text?: Key) => `Preset ${text}`,
custom: (text?: Key) => `Custom ${text}`,
dimensionTable: 'Dimension Table',
eventVariables: 'Event Variables',
virtualProperties: 'Virtual Properties',
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/property-selector/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const DimensionGroupTypeMapper: Mapper = {
geo: 'avar',
device: 'avar',
origin: 'avar',
virtual: 'event',
};

export const PropertyGroupOrder = [
Expand Down Expand Up @@ -65,7 +66,7 @@ const regroup = (data: PropertyItem, localeText: typeof defaultLocale): Property
newTypeName = PropertyTypes(localeText)[newType];
}

let groupName = isSystem ? localeText.preset(typeName) : localeText.custom(typeName);
let groupName = isSystem ? localeText.preset?.(typeName) : localeText.custom?.(typeName);
if (groupId === 'tag') {
groupName = localeText.tag;
}
Expand Down Expand Up @@ -107,7 +108,6 @@ export const dimensionToPropertyItem: TypeMapping = (item: Dimension, localeText
// 虚拟属性需要添加到事件属性中,但是有自己的type和groupId,所以和维度表(多物品模型)做相同处理
if (groupId === 'virtual' && _type === 'vvar') {
result.iconId = 'virtual';
result.groupId = 'event';
result.groupName = localeText.virtualProperties;
result.previewTypeName = localeText.virtualProperties;
}
Expand All @@ -120,7 +120,7 @@ export const dimensionToPropertyItem: TypeMapping = (item: Dimension, localeText
const tOrder = ['event', 'avar', 'usr'].indexOf(result.type);
result.typeOrder = tOrder > -1 ? tOrder : 99999;

if (has(item, 'isSystem')) {
if (has(item, 'isSystem') && groupId !== 'virtual') {
return regroup(result, localeText);
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/panel/BatchActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BatchActions: React.FC<BatchActionProps> = ({ onClose, count = 0, children
const prefixCls = usePrefixCls('panel__batch-actions');
return (
<div className={prefixCls}>
<span className={`${prefixCls}__text`}>{localeTextObject.hasSelected(count)}</span>
<span className={`${prefixCls}__text`}>{localeTextObject.hasSelected?.(count)}</span>
<IconButton type="text" size="small" onClick={onClose}>
<CloseOutlined />
</IconButton>
Expand Down
6 changes: 3 additions & 3 deletions src/static-past-time-picker/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export const DATE_FORMAT = 'yyyy/MM/dd';

export const experimentalQuickOptions = (localeText: typeof defaultLocaleText) => [
[
{ value: 'hour:25,1', label: localeText.lastSomeHours(24) },
{ value: 'hour:73,1', label: localeText.lastSomeHours(72) },
{ value: 'hour:25,1', label: localeText.lastSomeHours?.(24) },
{ value: 'hour:73,1', label: localeText.lastSomeHours?.(72) },
],
[{ value: 'hour:49,1', label: localeText.lastSomeHours(48) }],
[{ value: 'hour:49,1', label: localeText.lastSomeHours?.(48) }],
];

export const QUICK_MAPPING = {
Expand Down

1 comment on commit d477af8

@vercel
Copy link

@vercel vercel bot commented on d477af8 Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.