Skip to content

Commit

Permalink
feat: Added Loader to Manual Entry Grid while pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik committed Oct 4, 2024
1 parent 634d22d commit a75c058
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apps/widget/src/components/Common/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ interface TableProps {
width?: string | number;
selectEnabled?: boolean;
afterRender?: () => void;
beforePaste?: () => void;
columnDefs: HotItemSchema[];
data?: Record<string, any>[];
columnDescriptions?: string[];
Expand All @@ -181,6 +182,7 @@ export const Table = forwardRef<HotTableClass, TableProps>(
headings,
columnDefs,
data,
beforePaste,
columnDescriptions,
allChecked,
onRowCheck,
Expand Down Expand Up @@ -278,6 +280,7 @@ export const Table = forwardRef<HotTableClass, TableProps>(
columns={columnDefs}
colHeaders={headings}
rowHeaders={rowHeaders}
beforePaste={beforePaste}
afterRender={afterRender}
minSpareRows={minSpareRows}
fixedColumnsLeft={frozenColumns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MANUAL_ENTRY_LIMIT } from '@config';
import { WIDGET_TEXTS } from '@impler/client';
import { Table } from 'components/Common/Table';
import { Footer } from 'components/Common/Footer';
import { LoadingOverlay } from '@ui/LoadingOverlay';
import { SegmentedControl } from '@ui/SegmentedControl';
import { useDataGrid } from '@hooks/DataGrid/useDataGrid';
import { useCompleteImport } from '@hooks/useCompleteImport';
Expand Down Expand Up @@ -39,8 +40,15 @@ export function DataGrid({ onNextClick, onPrevClick, texts }: IPhase12Props) {
isReviewDataLoading,
showFindReplaceModal,
setShowFindReplaceModal,
isTemplateColumnsLoading,
} = useDataGrid({ limit: MANUAL_ENTRY_LIMIT });
const { updateRecord } = useBatchedUpdateRecord({ onUpdate: reReviewData });
const [isPasteLoading, setIsPasteLoading] = useState<boolean>(false);
const { updateRecord } = useBatchedUpdateRecord({
onUpdate: () => {
reReviewData();
setIsPasteLoading(false);
},
});
const tableWrapperRef = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>;
const { completeImport, isCompleteImportLoading } = useCompleteImport({ onNext: onNextClick });
const [tableWrapperDimensions, setTableWrapperDimentions] = useState({
Expand All @@ -57,6 +65,8 @@ export function DataGrid({ onNextClick, onPrevClick, texts }: IPhase12Props) {

return (
<>
<LoadingOverlay visible={isTemplateColumnsLoading || isPasteLoading} />

<Stack ref={tableWrapperRef} style={{ flexGrow: 1 }} spacing="xs" align="flex-start">
<Flex direction="row" justify="space-between" w="100%">
<SegmentedControl
Expand Down Expand Up @@ -95,6 +105,7 @@ export function DataGrid({ onNextClick, onPrevClick, texts }: IPhase12Props) {
headings={headings}
selectEnabled={false}
columnDefs={columnDefs}
beforePaste={() => setIsPasteLoading(true)}
onValueChange={(row, prop, oldVal, newVal) => {
const name = String(prop).replace('record.', '');

Expand Down
11 changes: 7 additions & 4 deletions apps/widget/src/hooks/DataGrid/useDataGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ export function useDataGrid({ limit }: IDataGridProps) {
]
);

const { data: templateColumns } = useQuery<unknown, IErrorObject, IColumn[], [string, string]>(
[`columns:${uploadInfo._id}`, uploadInfo._id],
() => api.getColumns(uploadInfo._id)
);
const { data: templateColumns, isLoading: isTemplateColumnsLoading } = useQuery<
unknown,
IErrorObject,
IColumn[],
[string, string]
>([`columns:${uploadInfo._id}`, uploadInfo._id], () => api.getColumns(uploadInfo._id));

const { mutate: refetchReviewData, isLoading: isReviewDataLoading } = useMutation<
IReviewData,
Expand Down Expand Up @@ -180,6 +182,7 @@ export function useDataGrid({ limit }: IDataGridProps) {
isReviewDataLoading,
showFindReplaceModal,
setShowFindReplaceModal,
isTemplateColumnsLoading,
totalRecords: uploadInfo.totalRecords ?? undefined,
invalidRecords: uploadInfo.invalidRecords ?? undefined,
};
Expand Down

0 comments on commit a75c058

Please sign in to comment.