Skip to content

Commit 6163b5c

Browse files
authored
fix: Updating non-selected text and other fixes (#298)
## Description Updating the default text when no category/related rule is selected. We are unable to set the selected items as the title, must be the URI SSWConsulting/SSW.Rules#2150 SSWConsulting/SSW.Rules#2153
1 parent 8bfdbdb commit 6163b5c

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

tina/collection/category.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from "react";
22
import { Collection, wrapFieldsWithMeta } from "tinacms";
33
import { embedTemplates } from "@/components/embeds";
44
import { generateGuid } from "@/utils/guidGenerationUtils";
5-
import { PaginatedRuleSelectorInput } from "../fields/paginatedRuleSelector";
65
import { ReadonlyUriInput } from "../fields/ReadonlyUriInput";
6+
import { RuleSelector } from "../fields/RuleSelector";
77
import { historyBeforeSubmit, historyFields } from "./shared/historyFields";
88
import { toolbarFields } from "./shared/toolbarFields";
99

@@ -210,9 +210,7 @@ const Category: Collection = {
210210
description:
211211
"Note: The rules listed here are only used for sorting on the category page. To assign a category, open the specific rule and select the category there. This list updates automatically based on those assignments, but any rule added directly to this list will not update on its own.",
212212
ui: {
213-
itemProps: (item) => ({
214-
label: item.rule?.split("/").at(-2) || "Rule is not selected",
215-
}),
213+
itemProps: (item) => ({ label: item.rule?.split("/").at(-2) || "Select a Rule" }),
216214
max: -1, // this disable the rules to be added to the category
217215
},
218216
fields: [
@@ -222,7 +220,7 @@ const Category: Collection = {
222220
name: "rule",
223221
collections: ["rule"],
224222
ui: {
225-
component: PaginatedRuleSelectorInput,
223+
component: RuleSelector,
226224
},
227225
},
228226
],

tina/collection/rule.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { generateGuid } from "@/utils/guidGenerationUtils";
55
import { countEndIntro } from "@/utils/mdxNodeUtils";
66
import { CategorySelectorInput } from "../fields/CategorySelector";
77
import { ConditionalHiddenField } from "../fields/ConditionalHiddenField";
8-
import { PaginatedRuleSelectorInput } from "../fields/paginatedRuleSelector";
98
import { ReadonlyUriInput } from "../fields/ReadonlyUriInput";
9+
import { RuleSelector } from "../fields/RuleSelector";
1010
import { historyBeforeSubmit, historyFields } from "./shared/historyFields";
1111
import { toolbarFields } from "./shared/toolbarFields";
1212

1313
const Rule: Collection = {
1414
name: "rule",
15-
label: "Rule",
15+
label: "Rules",
1616
path: "public/uploads/rules",
1717
format: "mdx",
1818
match: {
@@ -69,14 +69,11 @@ const Rule: Collection = {
6969
type: "object",
7070
name: "categories",
7171
label: "Categories",
72-
description: "Assigns one or more categories to the rule",
72+
description: "Assigns one or more categories to the rule.",
7373
list: true,
7474
searchable: false,
7575
ui: {
76-
itemProps: (item) => {
77-
const categoryTitle = item?.category ? `🔗 ${item?.category?.split("/").at(-1)?.replace(".mdx", "")}` : "Unselected Category";
78-
return { label: categoryTitle };
79-
},
76+
itemProps: (item) => ({ label: item?.category ? `📂 ${item?.category?.split("/").at(-1)?.replace(".mdx", "")}` : "Select a Category" }),
8077
component: ConditionalHiddenField,
8178
},
8279
fields: [
@@ -100,9 +97,7 @@ const Rule: Collection = {
10097
list: true,
10198
searchable: false,
10299
ui: {
103-
itemProps: (item) => {
104-
return { label: "👤 " + (item?.title ?? "Author") };
105-
},
100+
itemProps: (item) => ({ label: "👤 " + (item?.title ?? "Author") }),
106101
defaultItem: {
107102
title: "Bob Northwind",
108103
url: "https://ssw.com.au/people/bob-northwind",
@@ -136,7 +131,7 @@ const Rule: Collection = {
136131
searchable: false,
137132
ui: {
138133
itemProps: (item) => ({
139-
label: item.rule?.split("/").at(-2) || "Rule is not selected",
134+
label: item.rule?.split("/").at(-2) || "Select a Related Rule",
140135
}),
141136
component: ConditionalHiddenField,
142137
},
@@ -148,7 +143,7 @@ const Rule: Collection = {
148143
description: "This rule list may not include newly created rules for up to one hour. It is updated based on the main branch after that time.",
149144
collections: ["rule"],
150145
ui: {
151-
component: PaginatedRuleSelectorInput,
146+
component: RuleSelector,
152147
},
153148
},
154149
],
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Rule {
1616
const MIN_SEARCH_LENGTH = 2;
1717
const INITIAL_RULES_COUNT = 20;
1818

19-
export const PaginatedRuleSelectorInput: React.FC<any> = ({ input }) => {
19+
export const RuleSelector: React.FC<any> = ({ input }) => {
2020
const [filter, setFilter] = useState("");
2121
const [allRules, setAllRules] = useState<Rule[]>([]);
2222
const [filteredRules, setFilteredRules] = useState<Rule[]>([]);
@@ -203,9 +203,6 @@ export const PaginatedRuleSelectorInput: React.FC<any> = ({ input }) => {
203203
<div className="font-medium text-gray-900 text-sm leading-5 truncate">{rule.title}</div>
204204
<div className="text-xs text-gray-500 leading-4 truncate">{rule.uri}</div>
205205
</div>
206-
<div className="text-xs text-gray-500 leading-4 whitespace-nowrap text-right">
207-
Last updated: {formatLastUpdated(rule.lastUpdated)}
208-
</div>
209206
</div>
210207
</button>
211208
);

0 commit comments

Comments
 (0)