Skip to content

Commit b51c8ce

Browse files
authored
ENG-427 Query builder doesn't remember the column layout preference (#869)
* Store query view layout by uid * format
1 parent aa4795b commit b51c8ce

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

apps/roam/src/components/results-view/ResultsView.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ const ResultsView: ResultsViewComponent = ({
431431

432432
newViews
433433
.map((v) => ({
434-
text: v.column,
434+
text: v.uid,
435435
children: [
436436
{ text: v.mode, children: v.value ? [{ text: v.value }] : [] },
437437
],
@@ -1051,7 +1051,7 @@ const ResultsView: ResultsViewComponent = ({
10511051
</tr>
10521052
</thead>
10531053
<tbody className="divide-y divide-gray-200 bg-white">
1054-
{views.map(({ column, mode, value }, i) => (
1054+
{views.map(({ column, mode, value, uid }, i) => (
10551055
<tr key={i}>
10561056
<td className="whitespace-nowrap">{column}</td>
10571057
<td className="whitespace-nowrap">
@@ -1074,7 +1074,10 @@ const ResultsView: ResultsViewComponent = ({
10741074
},
10751075
);
10761076

1077-
onViewChange({ mode: m, column, value }, i);
1077+
onViewChange(
1078+
{ mode: m, column, value, uid },
1079+
i,
1080+
);
10781081
}}
10791082
/>
10801083
</td>
@@ -1089,6 +1092,7 @@ const ResultsView: ResultsViewComponent = ({
10891092
mode,
10901093
column,
10911094
value: e.target.value,
1095+
uid,
10921096
},
10931097
i,
10941098
)
@@ -1110,6 +1114,7 @@ const ResultsView: ResultsViewComponent = ({
11101114
nextValue === "default"
11111115
? ""
11121116
: nextValue,
1117+
uid,
11131118
},
11141119
i,
11151120
);

apps/roam/src/utils/parseResultSettings.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { OnloadArgs, RoamBasicNode } from "roamjs-components/types/native";
44
import getSettingIntFromTree from "roamjs-components/util/getSettingIntFromTree";
55
import getSubTree from "roamjs-components/util/getSubTree";
66
import toFlexRegex from "roamjs-components/util/toFlexRegex";
7+
import { BLOCK_REF_REGEX } from "roamjs-components/dom/constants";
78
import { StoredFilters } from "~/components/settings/DefaultFilters";
89
import { Column } from "./types";
910
import getSettingValueFromTree from "roamjs-components/util/getSettingValueFromTree";
@@ -24,11 +25,17 @@ export type InputValues = {
2425
}[];
2526
export type FilterData = Record<string, Filters>;
2627
export type Views = {
28+
uid: string;
2729
column: string;
2830
mode: string;
2931
value: string;
3032
}[];
3133

34+
const getStoredViewKey = (text: string): string => {
35+
const blockRefMatch = text.match(BLOCK_REF_REGEX);
36+
return blockRefMatch?.[1] || text;
37+
};
38+
3239
export const getAlias = (parentUid: string) => {
3340
const aliasMatch = getTextByBlockUid(parentUid).match(
3441
/{{query block:(.*?)}}/,
@@ -124,7 +131,7 @@ const parseResultSettings = (
124131
const viewsNode = getSubTree({ tree: resultNode.children, key: "views" });
125132
const savedViewData = Object.fromEntries(
126133
viewsNode.children.map((c) => [
127-
c.text,
134+
getStoredViewKey(c.text),
128135
{
129136
mode: c.children[0]?.text,
130137
value: c.children[0]?.children?.[0]?.text || "",
@@ -210,11 +217,14 @@ const parseResultSettings = (
210217
type: getSettingValueFromTree({ tree: c.children, key: "type" }),
211218
};
212219
}),
213-
views: columns.map(({ key: column }) => ({
220+
views: columns.map(({ key: column, uid }) => ({
221+
uid,
214222
column,
215223
mode:
216-
savedViewData[column]?.mode || (column === "text" ? "link" : "plain"),
217-
value: savedViewData[column]?.value || "",
224+
savedViewData[uid]?.mode ||
225+
savedViewData[column]?.mode ||
226+
(column === "text" ? "link" : "plain"),
227+
value: savedViewData[uid]?.value || savedViewData[column]?.value || "",
218228
})),
219229
random,
220230
pageSize,

0 commit comments

Comments
 (0)