Skip to content

Commit

Permalink
fix: tables behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonardoD committed Mar 5, 2025
1 parent 6c30a9e commit bcd1c6e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions frontend/src/modules/attachments/table/table-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const AttachmentsTable = ({ organization, canUpload = true, isSheet = false }: A
const { q, sort, order, attachmentPreview, groupId } = search;
const limit = LIMIT;

useAttachmentDialog({ orgIdOrSlug: organization.id, attachmentPreview, groupId });

// State for selected and total counts
const [total, setTotal] = useState<number | undefined>(undefined);
const [selected, setSelected] = useState<Attachment[]>([]);
Expand All @@ -62,8 +64,6 @@ const AttachmentsTable = ({ organization, canUpload = true, isSheet = false }: A
});
};

useAttachmentDialog({ orgIdOrSlug: organization.id, attachmentPreview, groupId });

return (
<div className="flex flex-col gap-4 h-full">
<AttachmentsTableBar
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/modules/attachments/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ const BaseDataTable = memo(
({ organization, columns, queryVars, sortColumns, setSortColumns, setTotal, setSelected }, ref) => {
const { t } = useTranslation();

useSync(organization.id);

const { q, sort, order, limit } = queryVars;

// Query attachments
const { rows, selectedRows, setRows, setSelectedRows, totalCount, isLoading, isFetching, error, fetchNextPage } = useDataFromInfiniteQuery(
attachmentsQueryOptions({ orgIdOrSlug: organization.id, q, sort, order, limit }),
);

useSync(organization.id);
const attachmentUpdateMutation = useAttachmentUpdateMutation();

// Update rows
const onRowsChange = (changedRows: Attachment[], { indexes, column }: RowsChangeData<Attachment>) => {
if (column.key === 'name') {
Expand Down Expand Up @@ -77,7 +77,7 @@ const BaseDataTable = memo(
fetchMore: fetchNextPage,
isFiltered: !!q,
selectedRows,
onSelectedRowsChange: setSelectedRows,
onSelectedRowsChange,
sortColumns,
onSortColumnsChange: setSortColumns,
NoRowsComponent: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const MembersTable = ({ entity: baseEntity, isSheet = false }: MembersTableProps
const { q, role, sort, order, sheetId } = search;
const limit = LIMIT;

// Render user sheet if sheetId is present
useUserSheet({ sheetId, organizationId });

// State for selected, total counts and entity
const [total, setTotal] = useState<number | undefined>(undefined);
const [selected, setSelected] = useState<Member[]>([]);
Expand All @@ -57,9 +60,6 @@ const MembersTable = ({ entity: baseEntity, isSheet = false }: MembersTableProps
if (dataTableRef.current) dataTableRef.current.clearSelection();
};

// Render user sheet if sheetId is present
useUserSheet({ sheetId, organizationId });

const openInviteDialog = (container?: HTMLElement | null) => {
if (!onlineManager.isOnline()) return toaster(t('common:action.offline.text'), 'warning');

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/organizations/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const BaseDataTable = memo(
selectedRows,
onRowsChange,
fetchMore: fetchNextPage,
onSelectedRowsChange: setSelectedRows,
onSelectedRowsChange,
sortColumns,
onSortColumnsChange: setSortColumns,
NoRowsComponent: (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/requests/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const BaseRequestsTable = memo(
fetchMore: fetchNextPage,
sortColumns,
selectedRows,
onSelectedRowsChange: setSelectedRows,
onSelectedRowsChange,
onSortColumnsChange: setSortColumns,
NoRowsComponent: <ContentPlaceholder Icon={Bird} title={t('common:no_resource_yet', { resource: t('common:requests').toLowerCase() })} />,
}}
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/modules/users/table/table-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const UsersTable = () => {
const limit = LIMIT;

const mutateQuery = useMutateQueryData(usersKeys.list(), (item) => usersKeys.single(item.id), ['update']);
// Render user sheet if sheetId is present
useUserSheet({ sheetId });

// State for selected and total counts
const [total, setTotal] = useState<number | undefined>(undefined);
Expand All @@ -46,9 +48,6 @@ const UsersTable = () => {
if (dataTableRef.current) dataTableRef.current.clearSelection();
};

// Render user sheet if sheetId is present
useUserSheet({ sheetId });

const openInviteDialog = (container: HTMLElement | null) => {
dialog(<InviteUsers mode={'email'} dialog />, {
id: 'user-invite',
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/modules/users/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const BaseDataTable = memo(
);

const mutateQuery = useMutateQueryData(usersKeys.list(), (item) => usersKeys.single(item.id), ['update']);

// Update user role
const { mutate: updateUserRole } = useUpdateUserMutation();

Expand Down Expand Up @@ -81,7 +80,7 @@ const BaseDataTable = memo(
fetchMore: fetchNextPage,
isFiltered: role !== undefined || !!q,
selectedRows,
onSelectedRowsChange: setSelectedRows,
onSelectedRowsChange,
sortColumns,
onSortColumnsChange: setSortColumns,
}}
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/query/hybrid-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export const hybridFetch = async <T>(options: FetchQueryOptions<any, any, any, a

try {
// Remove cached queries to trigger re-fetch if online
if (refetchIfOnline) queryClient.removeQueries({ queryKey, exact: true });
if (refetchIfOnline) {
await queryClient.cancelQueries({ queryKey, exact: true }); // To avoid CancelledError
await queryClient.invalidateQueries({ queryKey, exact: true });
}
return queryClient.fetchQuery(options);
} catch (error) {
return cachedData ?? undefined; // Fallback to cached data if available
Expand All @@ -44,7 +47,10 @@ export const hybridFetchInfinite = async (options: FetchInfiniteQueryOptions<any
if (!onlineManager.isOnline()) return cachedData ?? undefined;

try {
if (refetchIfOnline) queryClient.removeQueries({ queryKey, exact: true });
if (refetchIfOnline) {
await queryClient.cancelQueries({ queryKey, exact: true }); // To avoid CancelledError
await queryClient.invalidateQueries({ queryKey, exact: true });
}
return queryClient.fetchInfiniteQuery(options);
} catch (error) {
return cachedData ?? undefined; // Fallback to cached data if available
Expand Down

0 comments on commit bcd1c6e

Please sign in to comment.