Skip to content

Commit 2f33b0f

Browse files
authored
[ENG-76] Attribute-select drop down enhancements (#495)
* use new MenuItemSelect for AttributeSelect * remove tsconfig change * comment out format * update roamjs-components
1 parent 3600281 commit 2f33b0f

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"color": "^4.2.3",
1414
"markmap-lib": "^0.11.1",
1515
"markmap-view": "^0.2.1",
16-
"roamjs-components": "^0.82.13",
16+
"roamjs-components": "^0.85.0",
1717
"tesseract.js": "^2.1.4",
1818
"turndown": "^7.1.1"
1919
},

src/features/attributeSelect.tsx

+34-22
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,57 @@ const AttributeButtonPopover = <T extends ReactText>({
5555
filterable = false,
5656
isOpen,
5757
}: AttributeButtonPopoverProps<T>) => {
58-
const AttributeSelect = Select.ofType<T>();
5958
const itemPredicate = (query: string, item: T) => {
6059
return String(item).toLowerCase().includes(query.toLowerCase());
6160
};
6261
const [sliderValue, setSliderValue] = useState(0);
6362
useEffect(() => {
6463
setSliderValue(Number(currentValue));
6564
}, [isOpen, currentValue]);
65+
66+
const formatDisplayText = (text: string): string => {
67+
// TODO: for doantrang982/eng-77-decouple-display-from-output: Create formatDisplayText from configPage
68+
// const match = text.match(/\[\[(.*?)\]\]/);
69+
// if (match && match[1]) {
70+
// return match[1];
71+
// }
72+
return text;
73+
};
74+
75+
// Only show filter if we have more than 10 items
76+
const shouldFilter = filterable && items.length > 10;
77+
6678
return (
67-
<AttributeSelect
79+
<MenuItemSelect
6880
className="inline-menu-item-select"
69-
itemRenderer={(item, { modifiers, handleClick }) => (
70-
<MenuItem
71-
key={item}
72-
text={item}
73-
active={modifiers.active}
74-
onClick={handleClick}
75-
/>
76-
)}
7781
itemPredicate={itemPredicate}
7882
items={items}
83+
activeItem={currentValue as T}
84+
filterable={shouldFilter}
85+
// transformItem={(item) => formatDisplayText(String(item))}
7986
onItemSelect={(s) => {
8087
updateBlock({
8188
text: `${attributeName}:: ${s}`,
8289
uid,
8390
});
91+
setIsOpen(false);
92+
}}
93+
popoverProps={{
94+
isOpen,
95+
onClose: () => setIsOpen(false),
8496
}}
85-
activeItem={currentValue as T}
86-
// onActiveItemChange={} // TODO: get this working for keyboard support
87-
filterable={filterable}
8897
>
89-
<Button
90-
className="roamjs-attribute-select-button p-0 ml-1"
91-
icon="chevron-down"
92-
style={{ minHeight: 15, minWidth: 20 }}
93-
intent="primary"
94-
minimal
95-
onClick={() => setIsOpen(true)}
96-
/>
97-
</AttributeSelect>
98+
{() => (
99+
<Button
100+
className="roamjs-attribute-select-button p-0 ml-1"
101+
icon="chevron-down"
102+
style={{ minHeight: 15, minWidth: 20 }}
103+
intent="primary"
104+
minimal
105+
onClick={() => setIsOpen(true)}
106+
/>
107+
)}
108+
</MenuItemSelect>
98109
);
99110
};
100111

@@ -214,6 +225,7 @@ const AttributeButton = ({
214225
uid={uid}
215226
currentValue={currentValue}
216227
isOpen={isOpen}
228+
filterable={true}
217229
/>
218230
)}
219231
</>

0 commit comments

Comments
 (0)