Skip to content

Commit af8201e

Browse files
authored
1 parent 019a055 commit af8201e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

tina/fields/RuleSelector.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export const RuleSelector: React.FC<any> = ({ input }) => {
4444
setLoading(true);
4545
try {
4646
// Since we are in Tina admin site, we are at /admin so need to drop down a level back to root
47-
const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_PATH}/api/rules`, { method: "GET", cache: "no-store" });
47+
const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_PATH}/api/rules`, {
48+
method: "GET",
49+
cache: "no-store",
50+
});
4851
if (!res.ok) throw new Error(`HTTP ${res.status}`);
4952
const rules = await res.json();
5053
setAllRules(rules);
@@ -68,7 +71,7 @@ export const RuleSelector: React.FC<any> = ({ input }) => {
6871
const matchingRule = allRules.find((r) => r._sys.relativePath === selectedRel);
6972

7073
if (matchingRule) {
71-
setSelectedRuleLabel(matchingRule.uri);
74+
setSelectedRuleLabel(matchingRule.title || matchingRule.uri);
7275
}
7376
}, [allRules, input.value]);
7477

@@ -123,8 +126,8 @@ export const RuleSelector: React.FC<any> = ({ input }) => {
123126
setFilteredRules(includesSorted);
124127
}, [filter, allRules, selectedRule]);
125128

126-
const handleRuleSelect = (rule) => {
127-
setSelectedRuleLabel(rule.uri);
129+
const handleRuleSelect = (rule: Rule) => {
130+
setSelectedRuleLabel(rule.title || rule.uri);
128131
const rulePath = `public/uploads/rules/${rule._sys.relativePath}`;
129132
input.onChange(rulePath);
130133
};
@@ -140,7 +143,9 @@ export const RuleSelector: React.FC<any> = ({ input }) => {
140143
{({ open }) => (
141144
<>
142145
<PopoverButton className="text-sm h-11 px-4 justify-between w-full bg-white border border-gray-200 rounded-full hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors flex items-center">
143-
<span>{selectedRuleLabel || "Select a rule"}</span>
146+
<span className="truncate" title={selectedRuleLabel || undefined}>
147+
{selectedRuleLabel || "Select a rule"}
148+
</span>
144149
<BiChevronDown className={`w-4 h-4 transition-transform ${open ? "rotate-180" : ""}`} />
145150
</PopoverButton>
146151
<div className="absolute inset-x-0 -bottom-2 translate-y-full z-1000">
@@ -197,10 +202,13 @@ export const RuleSelector: React.FC<any> = ({ input }) => {
197202
handleRuleSelect(rule);
198203
close();
199204
}}
205+
title={rule.title || rule.uri}
200206
>
201207
<div className="flex items-center justify-between w-full gap-3">
202208
<div className="flex-1 min-w-0 overflow-hidden">
203-
<div className="font-medium text-gray-900 text-sm leading-5 truncate">{rule.title}</div>
209+
<div className="font-medium text-gray-900 text-sm leading-5 truncate" title={rule.title || rule.uri}>
210+
{rule.title || rule.uri}
211+
</div>
204212
<div className="text-xs text-gray-500 leading-4 truncate">{rule.uri}</div>
205213
</div>
206214
</div>

tina/tina-lock.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)