mirror of
https://github.com/docmost/docmost.git
synced 2026-06-10 10:13:01 +08:00
refactor(base): rename baseId to pageId in client services and queries
This commit is contained in:
@@ -26,7 +26,7 @@ export function useCreatePropertyMutation() {
|
||||
mutationFn: (data) => createProperty(data),
|
||||
onSuccess: (newProperty) => {
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", newProperty.baseId],
|
||||
["bases", newProperty.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -51,7 +51,7 @@ export function useUpdatePropertyMutation() {
|
||||
mutationFn: (data) => updateProperty(data),
|
||||
onSuccess: (result, variables) => {
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", variables.baseId],
|
||||
["bases", variables.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -78,7 +78,7 @@ export function useDeletePropertyMutation() {
|
||||
mutationFn: (data) => deleteProperty(data),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", variables.baseId],
|
||||
["bases", variables.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -91,7 +91,7 @@ export function useDeletePropertyMutation() {
|
||||
);
|
||||
|
||||
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||
{ queryKey: ["base-rows", variables.baseId] },
|
||||
{ queryKey: ["base-rows", variables.pageId] },
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -123,16 +123,16 @@ export function useReorderPropertyMutation() {
|
||||
mutationFn: (data) => reorderProperty(data),
|
||||
onMutate: async (variables) => {
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["bases", variables.baseId],
|
||||
queryKey: ["bases", variables.pageId],
|
||||
});
|
||||
|
||||
const previous = queryClient.getQueryData<IBase>([
|
||||
"bases",
|
||||
variables.baseId,
|
||||
variables.pageId,
|
||||
]);
|
||||
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", variables.baseId],
|
||||
["bases", variables.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -151,7 +151,7 @@ export function useReorderPropertyMutation() {
|
||||
onError: (_, variables, context) => {
|
||||
if (context?.previous) {
|
||||
queryClient.setQueryData(
|
||||
["bases", variables.baseId],
|
||||
["bases", variables.pageId],
|
||||
context.previous,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ import { queryClient } from "@/main";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export function useBaseQuery(
|
||||
baseId: string | undefined,
|
||||
pageId: string | undefined,
|
||||
): UseQueryResult<IBase, Error> {
|
||||
return useQuery({
|
||||
queryKey: ["bases", baseId],
|
||||
queryFn: () => getBaseInfo(baseId!),
|
||||
enabled: !!baseId,
|
||||
queryKey: ["bases", pageId],
|
||||
queryFn: () => getBaseInfo(pageId!),
|
||||
enabled: !!pageId,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
@@ -68,10 +68,10 @@ export function useUpdateBaseMutation() {
|
||||
|
||||
export function useDeleteBaseMutation() {
|
||||
const { t } = useTranslation();
|
||||
return useMutation<void, Error, { baseId: string; spaceId: string }>({
|
||||
mutationFn: ({ baseId }) => deleteBase(baseId),
|
||||
onSuccess: (_, { baseId, spaceId }) => {
|
||||
queryClient.removeQueries({ queryKey: ["bases", baseId] });
|
||||
return useMutation<void, Error, { pageId: string; spaceId: string }>({
|
||||
mutationFn: ({ pageId }) => deleteBase(pageId),
|
||||
onSuccess: (_, { pageId, spaceId }) => {
|
||||
queryClient.removeQueries({ queryKey: ["bases", pageId] });
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["bases", "list", spaceId],
|
||||
});
|
||||
|
||||
@@ -59,7 +59,7 @@ function newRequestId(): string {
|
||||
}
|
||||
|
||||
export function useBaseRowsQuery(
|
||||
baseId: string | undefined,
|
||||
pageId: string | undefined,
|
||||
filter?: FilterNode,
|
||||
sorts?: ViewSortConfig[],
|
||||
search?: SearchSpec,
|
||||
@@ -69,16 +69,16 @@ export function useBaseRowsQuery(
|
||||
const activeSearch = search?.query ? search : undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: ["base-rows", baseId, activeFilter, activeSorts, activeSearch],
|
||||
queryKey: ["base-rows", pageId, activeFilter, activeSorts, activeSearch],
|
||||
queryFn: ({ pageParam }) =>
|
||||
listRows(baseId!, {
|
||||
listRows(pageId!, {
|
||||
cursor: pageParam,
|
||||
limit: 100,
|
||||
filter: activeFilter,
|
||||
sorts: activeSorts,
|
||||
search: activeSearch,
|
||||
}),
|
||||
enabled: !!baseId,
|
||||
enabled: !!pageId,
|
||||
initialPageParam: undefined as string | undefined,
|
||||
getNextPageParam: (lastPage: IPagination<IBaseRow>) =>
|
||||
lastPage.meta?.nextCursor ?? undefined,
|
||||
@@ -99,7 +99,7 @@ export function useCreateRowMutation() {
|
||||
mutationFn: (data) => createRow({ ...data, requestId: newRequestId() }),
|
||||
onSuccess: (newRow) => {
|
||||
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||
{ queryKey: ["base-rows", newRow.baseId] },
|
||||
{ queryKey: ["base-rows", newRow.pageId] },
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
const lastPageIndex = old.pages.length - 1;
|
||||
@@ -130,15 +130,15 @@ export function useUpdateRowMutation() {
|
||||
mutationFn: (data) => updateRow({ ...data, requestId: newRequestId() }),
|
||||
onMutate: async (variables) => {
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["base-rows", variables.baseId],
|
||||
queryKey: ["base-rows", variables.pageId],
|
||||
});
|
||||
|
||||
const snapshots = queryClient.getQueriesData<
|
||||
InfiniteData<IPagination<IBaseRow>>
|
||||
>({ queryKey: ["base-rows", variables.baseId] });
|
||||
>({ queryKey: ["base-rows", variables.pageId] });
|
||||
|
||||
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||
{ queryKey: ["base-rows", variables.baseId] },
|
||||
{ queryKey: ["base-rows", variables.pageId] },
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -173,7 +173,7 @@ export function useUpdateRowMutation() {
|
||||
},
|
||||
onSuccess: (updatedRow) => {
|
||||
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||
{ queryKey: ["base-rows", updatedRow.baseId] },
|
||||
{ queryKey: ["base-rows", updatedRow.pageId] },
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -199,15 +199,15 @@ export function useDeleteRowMutation() {
|
||||
mutationFn: (data) => deleteRow({ ...data, requestId: newRequestId() }),
|
||||
onMutate: async (variables) => {
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["base-rows", variables.baseId],
|
||||
queryKey: ["base-rows", variables.pageId],
|
||||
});
|
||||
|
||||
const snapshots = queryClient.getQueriesData<
|
||||
InfiniteData<IPagination<IBaseRow>>
|
||||
>({ queryKey: ["base-rows", variables.baseId] });
|
||||
>({ queryKey: ["base-rows", variables.pageId] });
|
||||
|
||||
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||
{ queryKey: ["base-rows", variables.baseId] },
|
||||
{ queryKey: ["base-rows", variables.pageId] },
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -242,16 +242,16 @@ export function useDeleteRowsMutation() {
|
||||
mutationFn: (data) => deleteRows({ ...data, requestId: newRequestId() }),
|
||||
onMutate: async (variables) => {
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["base-rows", variables.baseId],
|
||||
queryKey: ["base-rows", variables.pageId],
|
||||
});
|
||||
|
||||
const snapshots = queryClient.getQueriesData<
|
||||
InfiniteData<IPagination<IBaseRow>>
|
||||
>({ queryKey: ["base-rows", variables.baseId] });
|
||||
>({ queryKey: ["base-rows", variables.pageId] });
|
||||
|
||||
const removeSet = new Set(variables.rowIds);
|
||||
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||
{ queryKey: ["base-rows", variables.baseId] },
|
||||
{ queryKey: ["base-rows", variables.pageId] },
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -287,7 +287,7 @@ export function useDeleteRowsMutation() {
|
||||
* of the key so a "show exact" toggle doesn't clobber the estimate cache.
|
||||
*/
|
||||
export function useBaseRowsCountQuery(
|
||||
baseId: string | undefined,
|
||||
pageId: string | undefined,
|
||||
filter?: FilterNode,
|
||||
search?: SearchSpec,
|
||||
exact = false,
|
||||
@@ -296,15 +296,15 @@ export function useBaseRowsCountQuery(
|
||||
const activeSearch = search?.query ? search : undefined;
|
||||
|
||||
return useQuery<CountRowsResult>({
|
||||
queryKey: ["base-rows-count", baseId, activeFilter, activeSearch, exact],
|
||||
queryKey: ["base-rows-count", pageId, activeFilter, activeSearch, exact],
|
||||
queryFn: () =>
|
||||
countRows({
|
||||
baseId: baseId!,
|
||||
pageId: pageId!,
|
||||
filter: activeFilter,
|
||||
search: activeSearch,
|
||||
exact,
|
||||
}),
|
||||
enabled: !!baseId,
|
||||
enabled: !!pageId,
|
||||
staleTime: 30 * 1000,
|
||||
});
|
||||
}
|
||||
@@ -315,15 +315,15 @@ export function useReorderRowMutation() {
|
||||
mutationFn: (data) => reorderRow({ ...data, requestId: newRequestId() }),
|
||||
onMutate: async (variables) => {
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["base-rows", variables.baseId],
|
||||
queryKey: ["base-rows", variables.pageId],
|
||||
});
|
||||
|
||||
const snapshots = queryClient.getQueriesData<
|
||||
InfiniteData<IPagination<IBaseRow>>
|
||||
>({ queryKey: ["base-rows", variables.baseId] });
|
||||
>({ queryKey: ["base-rows", variables.pageId] });
|
||||
|
||||
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||
{ queryKey: ["base-rows", variables.baseId] },
|
||||
{ queryKey: ["base-rows", variables.pageId] },
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
|
||||
@@ -21,7 +21,7 @@ export function useCreateViewMutation() {
|
||||
mutationFn: (data) => createView(data),
|
||||
onSuccess: (newView) => {
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", newView.baseId],
|
||||
["bases", newView.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -46,16 +46,16 @@ export function useUpdateViewMutation() {
|
||||
mutationFn: (data) => updateView(data),
|
||||
onMutate: async (variables) => {
|
||||
await queryClient.cancelQueries({
|
||||
queryKey: ["bases", variables.baseId],
|
||||
queryKey: ["bases", variables.pageId],
|
||||
});
|
||||
|
||||
const previous = queryClient.getQueryData<IBase>([
|
||||
"bases",
|
||||
variables.baseId,
|
||||
variables.pageId,
|
||||
]);
|
||||
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", variables.baseId],
|
||||
["bases", variables.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -85,7 +85,7 @@ export function useUpdateViewMutation() {
|
||||
onError: (_, variables, context) => {
|
||||
if (context?.previous) {
|
||||
queryClient.setQueryData(
|
||||
["bases", variables.baseId],
|
||||
["bases", variables.pageId],
|
||||
context.previous,
|
||||
);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ export function useUpdateViewMutation() {
|
||||
},
|
||||
onSuccess: (updatedView) => {
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", updatedView.baseId],
|
||||
["bases", updatedView.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
@@ -117,7 +117,7 @@ export function useDeleteViewMutation() {
|
||||
mutationFn: (data) => deleteView(data),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.setQueryData<IBase>(
|
||||
["bases", variables.baseId],
|
||||
["bases", variables.pageId],
|
||||
(old) => {
|
||||
if (!old) return old;
|
||||
return {
|
||||
|
||||
@@ -35,8 +35,8 @@ export async function createBase(data: CreateBaseInput): Promise<IBase> {
|
||||
return req.data;
|
||||
}
|
||||
|
||||
export async function getBaseInfo(baseId: string): Promise<IBase> {
|
||||
const req = await api.post<IBase>("/bases/info", { baseId });
|
||||
export async function getBaseInfo(pageId: string): Promise<IBase> {
|
||||
const req = await api.post<IBase>("/bases/info", { pageId });
|
||||
return req.data;
|
||||
}
|
||||
|
||||
@@ -45,14 +45,14 @@ export async function updateBase(data: UpdateBaseInput): Promise<IBase> {
|
||||
return req.data;
|
||||
}
|
||||
|
||||
export async function deleteBase(baseId: string): Promise<void> {
|
||||
await api.post("/bases/delete", { baseId });
|
||||
export async function deleteBase(pageId: string): Promise<void> {
|
||||
await api.post("/bases/delete", { pageId });
|
||||
}
|
||||
|
||||
export async function exportBaseToCsv(baseId: string): Promise<void> {
|
||||
export async function exportBaseToCsv(pageId: string): Promise<void> {
|
||||
const req = await api.post(
|
||||
"/bases/export-csv",
|
||||
{ baseId },
|
||||
{ pageId },
|
||||
{ responseType: "blob" },
|
||||
);
|
||||
|
||||
@@ -115,9 +115,9 @@ export async function createRow(data: CreateRowInput): Promise<IBaseRow> {
|
||||
|
||||
export async function getRowInfo(
|
||||
rowId: string,
|
||||
baseId: string,
|
||||
pageId: string,
|
||||
): Promise<IBaseRow> {
|
||||
const req = await api.post<IBaseRow>("/bases/rows/info", { rowId, baseId });
|
||||
const req = await api.post<IBaseRow>("/bases/rows/info", { rowId, pageId });
|
||||
return req.data;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export async function deleteRows(data: DeleteRowsInput): Promise<void> {
|
||||
}
|
||||
|
||||
export async function listRows(
|
||||
baseId: string,
|
||||
pageId: string,
|
||||
params?: {
|
||||
viewId?: string;
|
||||
cursor?: string;
|
||||
@@ -145,7 +145,7 @@ export async function listRows(
|
||||
search?: SearchSpec;
|
||||
},
|
||||
): Promise<IPagination<IBaseRow>> {
|
||||
const req = await api.post("/bases/rows", { baseId, ...params });
|
||||
const req = await api.post("/bases/rows", { pageId, ...params });
|
||||
return req.data;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ export async function deleteView(data: DeleteViewInput): Promise<void> {
|
||||
await api.post("/bases/views/delete", data);
|
||||
}
|
||||
|
||||
export async function listViews(baseId: string): Promise<IBaseView[]> {
|
||||
const req = await api.post<IBaseView[]>("/bases/views", { baseId });
|
||||
export async function listViews(pageId: string): Promise<IBaseView[]> {
|
||||
const req = await api.post<IBaseView[]>("/bases/views", { pageId });
|
||||
return req.data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user