Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat importer settings #826

Merged
merged 4 commits into from
Oct 6, 2024
Merged
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
3 changes: 3 additions & 0 deletions apps/api/src/app/review/usecases/replace/replace.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class Replace {
{ $eq: ['$' + path, ''] },
{ $regexMatch: { input: { $toString: '$' + path }, regex: /^\s*$/ } },
{ $eq: ['$' + path, null] },
{ $not: [{ $ifNull: ['$' + path, false] }] },
],
};
replaceOperation = { $literal: formattedReplace };
Expand Down Expand Up @@ -146,6 +147,8 @@ export class Replace {
// Add a final stage to remove the temporary _oldRecord field
updateStages.push({ $unset: '_oldRecord' });

console.log(updateStages);

const result = await recordCollectionModal.updateMany({}, updateStages, { multi: true });

return result;
Expand Down
41 changes: 28 additions & 13 deletions apps/widget/src/components/Common/Heading/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { CloseButton, Group, MediaQuery, Title } from '@mantine/core';
import { PhasesEnum } from '@types';
import { FlowsEnum, PhasesEnum } from '@types';
import { Stepper } from '@ui/Stepper';
import { WIDGET_TEXTS } from '@impler/client';
import { TemplateModeEnum } from '@impler/shared';
import { useAppState } from '@store/app.context';

interface IHeadingProps {
title?: string;
active: PhasesEnum;
onClose?: () => void;
mode?: TemplateModeEnum;
hasImageUpload?: boolean;
texts: typeof WIDGET_TEXTS;
}

export function Heading({ active, title, mode, hasImageUpload, texts, onClose }: IHeadingProps) {
const manualImportSteps = [
export function Heading({ active, title, onClose }: IHeadingProps) {
const { texts, flow } = useAppState();
const straightImportSteps = [
{
label: texts.STEPPER_TITLES.UPLOAD_FILE,
},
Expand All @@ -32,6 +29,15 @@ export function Heading({ active, title, mode, hasImageUpload, texts, onClose }:
},
];

const manualEntryImportSteps = [
{
label: texts.STEPPER_TITLES.UPLOAD_FILE,
},
{
label: texts.STEPPER_TITLES.REVIEW_EDIT,
},
];

const autoImportSteps = [
{
label: texts.STEPPER_TITLES.CONFIGURE_JOB,
Expand All @@ -52,18 +58,27 @@ export function Heading({ active, title, mode, hasImageUpload, texts, onClose }:
<Title order={3}>{title}</Title>
<MediaQuery smallerThan="md" styles={{ display: 'none' }}>
<Stepper
active={active - (mode === TemplateModeEnum.AUTOMATIC ? 1 : hasImageUpload ? 1 : 2)}
active={
active -
([FlowsEnum.AUTO_IMPORT, FlowsEnum.IMAGE_IMPORT].includes(flow)
? 1
: flow === FlowsEnum.MANUAL_ENTRY
? 0
: 2)
}
steps={
mode === TemplateModeEnum.AUTOMATIC
flow == FlowsEnum.AUTO_IMPORT
? autoImportSteps
: hasImageUpload
: flow == FlowsEnum.IMAGE_IMPORT
? [
{
label: texts.STEPPER_TITLES.GENERATE_TEMPLATE,
},
...manualImportSteps,
...straightImportSteps,
]
: manualImportSteps
: flow === FlowsEnum.MANUAL_ENTRY
? manualEntryImportSteps
: straightImportSteps
}
/>
</MediaQuery>
Expand Down
16 changes: 2 additions & 14 deletions apps/widget/src/components/Common/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
import { PropsWithChildren } from 'react';
import useStyles from './Styles';
import { PhasesEnum } from '@types';
import { WIDGET_TEXTS } from '@impler/client';
import { TemplateModeEnum } from '@impler/shared';
import { Heading } from 'components/Common/Heading';

interface ILayoutProps {
active: PhasesEnum;
title?: string;
onClose?: () => void;
mode?: TemplateModeEnum;
hasImageUpload?: boolean;
texts: typeof WIDGET_TEXTS;
}

export function Layout(props: PropsWithChildren<ILayoutProps>) {
const { classes } = useStyles();
const { children, active, title, hasImageUpload, mode, texts, onClose } = props;
const { children, active, title, onClose } = props;

return (
<div className={classes.root}>
<Heading
mode={mode}
texts={texts}
title={title}
active={active}
onClose={onClose}
hasImageUpload={hasImageUpload}
/>
<Heading title={title} active={active} onClose={onClose} />
<div className={classes.container}>{children}</div>
</div>
);
Expand Down
11 changes: 7 additions & 4 deletions apps/widget/src/components/Common/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ export const Table = forwardRef<HotTableClass, TableProps>(
}
}}
beforeKeyDown={(event) => {
const [[row, col]] = (gridRef as any)?.current.__hotInstance?.getSelected();
const rows = (gridRef as any)?.current?.__hotInstance?.countRows();
if (event.key === 'Tab' && col === headings.length - 1) {
(gridRef as any)?.current.__hotInstance.selectCell(Math.min(rows, row + 1), selectEnabled ? 3 : 1);
const selected = (gridRef as any)?.current.__hotInstance?.getSelected();
if (Array.isArray(selected) && selected.length > 0 && Array.isArray(selected[0])) {
const [[row, col]] = selected;
const rows = (gridRef as any)?.current?.__hotInstance?.countRows();
if (event.key === 'Tab' && col === headings.length - 1) {
(gridRef as any)?.current.__hotInstance.selectCell(Math.min(rows, row + 1), selectEnabled ? 3 : 1);
}
}
}}
fillHandle={{
Expand Down
9 changes: 1 addition & 8 deletions apps/widget/src/components/widget/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,7 @@ export function Widget() {

return (
<Modal title={title || importConfig?.title || templateInfo?.name} opened={showWidget} onClose={onClose}>
<Layout
texts={texts}
active={phase}
onClose={onClose}
hasImageUpload={hasImageUpload}
mode={importConfig.mode as TemplateModeEnum}
title={title || importConfig?.title || templateInfo?.name}
>
<Layout active={phase} onClose={onClose} title={title || importConfig?.title || templateInfo?.name}>
{PhaseView[phase]}

<ConfirmModal
Expand Down
3 changes: 3 additions & 0 deletions apps/widget/src/hooks/DataGrid/useDataGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export function useDataGrid({ limit }: IDataGridProps) {
columnItem.dateFormat = column.dateFormats[variables.baseIndex];
columnItem.correctFormat = true;
}
columnItem.datePickerConfig = {
yearRange: [1900, 3000],
};
columnItem.renderer = 'custom';
break;
default:
Expand Down
3 changes: 3 additions & 0 deletions apps/widget/src/hooks/Phase3/usePhase3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export function usePhase3({ onNext }: IUsePhase3Props) {
columnItem.dateFormat = column.dateFormats[variables.baseIndex];
columnItem.correctFormat = true;
}
columnItem.datePickerConfig = {
yearRange: [1900, 3000],
};
columnItem.renderer = 'custom';
break;
default:
Expand Down
1 change: 1 addition & 0 deletions apps/widget/src/types/utility.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type HotItemSchema = {
allowInvalid?: boolean;
disableVisualSelection?: boolean;
description?: string;
datePickerConfig?: Record<string, any>; // https://github.com/Pikaday/Pikaday#configuration
renderer?:
| 'custom'
| 'check'
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/config/texts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const WIDGET_TEXTS = {
CONFIGURE_JOB: 'Configure',
SCHEDULE_JOB: 'Schedule',
CONFIRM_JOB: 'Confirm',
REVIEW_EDIT: 'Review & Edit',
},
FILE_DROP_AREA: {
DROP_FILE: 'Drop and drop a file here',
Expand Down
Loading