Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions apps/roam/src/components/DiscourseContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const ContextTab = ({
r: DiscourseContextResults[number];
groupByTarget: boolean;
setGroupByTarget: (b: boolean) => void;
onRefresh: () => void;
onRefresh: (ignoreCache?: boolean) => void;
}) => {
const [subTabId, setSubTabId] = useState(0);

Expand Down Expand Up @@ -345,22 +345,25 @@ export const ContextContent = ({ uid, results }: Props) => {
}));
}, []);

const onRefresh = useCallback(() => {
setRawQueryResults({});
getDiscourseContextResults({
uid,
onResult: addLabels,
ignoreCache: true,
}).finally(() => setLoading(false));
}, [uid, setRawQueryResults, setLoading, addLabels]);
const onRefresh = useCallback(
(ignoreCache = true) => {
setRawQueryResults({});
void getDiscourseContextResults({
uid,
onResult: addLabels,
ignoreCache,
}).finally(() => setLoading(false));
},
[uid, setRawQueryResults, setLoading, addLabels],
);

const delayedRefresh = () => {
window.setTimeout(onRefresh, 250);
};

useEffect(() => {
if (!results) {
onRefresh();
onRefresh(false);
} else {
results.forEach(addLabels);
setLoading(false);
Expand Down
71 changes: 34 additions & 37 deletions apps/roam/src/components/QueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,41 @@ const QueryBuilder = ({ pageUid, isEditBlock, showAlias }: Props) => {
const [columns, setColumns] = useState<Column[]>([]);
const [results, setResults] = useState<Result[]>([]);
const containerRef = useRef<HTMLDivElement>(null);
const onRefresh = useCallback(
(loadInBackground = false) => {
setError("");
setLoading(!loadInBackground);
const args = parseQuery(pageUid);
const { inputs } = parseResultSettings(pageUid, args.columns);
const transformedInputs = Object.fromEntries(
inputs.map(({ key, inputValue }) => [key, inputValue]),
);
setTimeout(() => {
fireQuery({ ...args, inputs: transformedInputs })
.then((results) => {
setColumns(args.columns);
setResults(results);
})
.catch(() => {
setError(
`Query failed to run. Try running a new query from the editor.`,
);
})
.finally(() => {
const tree = getBasicTreeByParentUid(pageUid);
const node = getSubTree({ tree, key: "results" });
return (
node.uid
? Promise.resolve(node.uid)
: createBlock({
parentUid: pageUid,
node: { text: "results" },
})
).then(() => {
setLoading(false);
});
const onRefresh = useCallback(() => {
setError("");
setLoading(true);
const args = parseQuery(pageUid);
const { inputs } = parseResultSettings(pageUid, args.columns);
const transformedInputs = Object.fromEntries(
inputs.map(({ key, inputValue }) => [key, inputValue]),
);
setTimeout(() => {
fireQuery({ ...args, inputs: transformedInputs })
.then((results) => {
setColumns(args.columns);
setResults(results);
})
.catch(() => {
setError(
`Query failed to run. Try running a new query from the editor.`,
);
})
.finally(() => {
const tree = getBasicTreeByParentUid(pageUid);
const node = getSubTree({ tree, key: "results" });
void (
node.uid
? Promise.resolve(node.uid)
: createBlock({
parentUid: pageUid,
node: { text: "results" },
})
).then(() => {
setLoading(false);
});
}, 1);
},
[setResults, pageUid, setLoading, setColumns],
);
});
}, 1);
}, [setResults, pageUid, setLoading, setColumns]);
useEffect(() => {
if (!isEdit) {
if (hasResults) {
Expand Down
4 changes: 2 additions & 2 deletions apps/roam/src/components/results-view/ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type ResultRowProps = {
parentUid: string;
ctrlClick?: (e: Result) => void;
views: { column: string; mode: string; value: string }[];
onRefresh: () => void;
onRefresh: (ignoreCache?: boolean) => void;
};

const ResultRow = ({
Expand Down Expand Up @@ -391,7 +391,7 @@ const ResultsTable = ({
setFilters: (f: FilterData) => void;
preventSavingSettings?: boolean;
views: Views;
onRefresh: () => void;
onRefresh: (ignoreCache?: boolean) => void;
allResults: Result[];
showInterface?: boolean;
}) => {
Expand Down
6 changes: 3 additions & 3 deletions apps/roam/src/components/results-view/ResultsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Charts from "./Charts";
import Timeline from "./Timeline";
import Kanban from "./Kanban";
import MenuItemSelect from "roamjs-components/components/MenuItemSelect";
import { RoamBasicNode } from "roamjs-components/types";
import type { RoamBasicNode } from "roamjs-components/types/native";
import { render as renderToast } from "roamjs-components/components/Toast";
import { Column, Result } from "~/utils/types";
import updateBlock from "roamjs-components/writes/updateBlock";
Expand Down Expand Up @@ -238,7 +238,7 @@ type ResultsViewComponent = (props: {
preventSavingSettings?: boolean;
onEdit?: () => void;
onDeleteQuery?: () => void;
onRefresh: (loadInBackground?: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

loadInBackground is 'used' in QueryBuilder.tsx. If we are changing this, should probably remove the loadInBackground reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I missed that one, thanks. And I agree with the quotation marks around 'used'.
Two things I could do: Remove the loadInBackground reference, since it does so little; (and probably just not call setLoading, but also a decision);
OR add the parameter back, and have a signature with two parameters on the type everywhere.
Which do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove. But keep the same behavior (which is setLoading(true) I believe)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(the linear comment did not carry, copying) Done. onRefresh is called twice, this time with true (hence setLoading(true) as you say, which amounts to load in background being statically false, not true as you say in the other comment.) and in the DiscourseContext.tsx:366 useEffect, where it used to be false. I think this was to avoid a "loading" flicker on first display. I think this flicker is very short, accurately represents processing, and not worth another parameter to suppress.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. onRefresh is called twice, this time with true (hence setLoading(true) as you say, which amounts to load in background being statically false, not true as you say in the other comment.) and in the DiscourseContext.tsx:366 useEffect, where it used to be false. I think this was to avoid a "loading" flicker on first display. I think this flicker is very short, accurately represents processing, and not worth another parameter to suppress.

onRefresh: (ignoreCache?: boolean) => void;
globalFiltersData?: Record<string, Filters>;
globalPageSize?: number;
isEditBlock?: boolean;
Expand Down Expand Up @@ -1369,7 +1369,7 @@ const ResultsView: ResultsViewComponent = ({
<Kanban
data={allProcessedResults}
layout={layout}
onQuery={() => onRefresh(true)}
onQuery={() => onRefresh()}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some context as to why this change was made, please? Kanban quite seems unrelated to discourse context UI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is because I removed the loadInBackground flag, so I removed the one call instance which seemed to be using it. So it depends on what we decide to do with that flag, above.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, well "load in background" can be statically true , so this line can stay the way it is if we change setLoading(true) where loadInBackground was being used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

statically false, but otherwise agreed.

resultKeys={columns}
parentUid={parentUid}
views={views}
Expand Down
4 changes: 2 additions & 2 deletions apps/roam/src/utils/getDiscourseContextResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CACHE_TIMEOUT = 1000 * 60 * 5;

type BuildQueryConfig = {
args: {
ignoreCache?: true;
ignoreCache?: boolean;
};
targetUid: string;
fireQueryContext: {
Expand Down Expand Up @@ -176,7 +176,7 @@ const getDiscourseContextResults = async ({
uid: string;
nodes?: ReturnType<typeof getDiscourseNodes>;
relations?: ReturnType<typeof getDiscourseRelations>;
ignoreCache?: true;
ignoreCache?: boolean;
onResult?: onResult;
}) => {
const args = { ignoreCache };
Expand Down