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: Added properties disableFindAndReplace,disableCheckBox and disa… #908

Merged
merged 4 commits into from
Jan 3, 2025
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
2 changes: 2 additions & 0 deletions apps/widget/src/components/Common/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function Container({ children }: PropsWithChildren<{}>) {
colorScheme: data.value.colorScheme,
title: data.value.title,
texts: deepMerge(WIDGET_TEXTS, data.value.texts),
config: data.value.config,
schema:
typeof data.value.schema === 'string'
? data.value.schema
Expand Down Expand Up @@ -330,6 +331,7 @@ export function Container({ children }: PropsWithChildren<{}>) {
schema={secondaryPayload?.schema}
title={secondaryPayload?.title}
texts={secondaryPayload.texts as typeof WIDGET_TEXTS}
config={secondaryPayload.config}
// api
api={api}
// impler-context
Expand Down
5 changes: 4 additions & 1 deletion apps/widget/src/components/Common/Provider/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PropsWithChildren } from 'react';
import { ApiService } from '@api';
import { WIDGET_TEXTS } from '@impler/client';
import { WIDGET_TEXTS, WidgetConfig } from '@impler/client';
import APIContextProvider from '@store/api.context';
import AppContextProvider from '@store/app.context';
import { JobsInfoProvider } from '@store/jobinfo.context';
Expand All @@ -10,6 +10,7 @@ interface IProviderProps {
// app-context
title?: string;
texts: typeof WIDGET_TEXTS;
config?: WidgetConfig;
primaryColor: string;
output?: string;
sampleFile?: File | Blob;
Expand All @@ -31,6 +32,7 @@ export function Provider(props: PropsWithChildren<IProviderProps>) {
const {
api,
data,
config,
title,
sampleFile,
texts,
Expand Down Expand Up @@ -61,6 +63,7 @@ export function Provider(props: PropsWithChildren<IProviderProps>) {
data={data}
title={title}
sampleFile={sampleFile}
config={config}
texts={texts}
output={output}
schema={schema}
Expand Down
21 changes: 12 additions & 9 deletions apps/widget/src/components/Common/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ interface TableProps {
onCheckAll?: (checked: boolean) => void;
onValueChange?: (row: number, prop: string, oldVal: any, newVal: any) => void;
onRowCheck?: (rowIndex: number, recordIndex: number, checked: boolean) => void;
disableCheckBox?: boolean;
}

export const Table = forwardRef<HotTableClass, TableProps>(
Expand All @@ -182,6 +183,7 @@ export const Table = forwardRef<HotTableClass, TableProps>(
headings,
columnDefs,
data,
disableCheckBox,
beforePaste,
columnDescriptions,
allChecked,
Expand All @@ -191,7 +193,8 @@ export const Table = forwardRef<HotTableClass, TableProps>(
minSpareRows,
frozenColumns = 2,
onValueChange,
selectEnabled = true,
// Conditionally set selectEnabled based on disableCheckBox
selectEnabled = disableCheckBox === undefined ? true : !disableCheckBox,
}: TableProps,
gridRef
) => {
Expand Down Expand Up @@ -244,15 +247,15 @@ export const Table = forwardRef<HotTableClass, TableProps>(

if (!selectEnabled && i < 0) {
TH.innerHTML = '#';
} else if (selectEnabled && i === 0) {
TH.classList.add('check-all-cell');
} else if (selectEnabled && i === 0 && selectEnabled) {
TH.innerHTML = `
<div class="checkbox">
<input type="checkbox" ${allChecked ? 'checked' : ''} class="checkbox__control">
<svg class="checkbox__control-icon" xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 24 24">
<path fill="currentColor" d="M 20.292969 5.2929688 L 9 16.585938 L 4.7070312 12.292969 L 3.2929688 13.707031 L 9 19.414062 L 21.707031 6.7070312 L 20.292969 5.2929688 z"></path>
</svg>
</div>`;
<div class="checkbox">
<input type="checkbox" ${allChecked ? 'checked' : ''} class="checkbox__control">
<svg class="checkbox__control-icon" xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 24 24">
<path fill="currentColor" d="M 20.292969 5.2929688 L 9 16.585938 L 4.7070312 12.292969 L 3.2929688 13.707031 L 9 19.414062 L 21.707031 6.7070312 L 20.292969 5.2929688 z"></path>
</svg>
</div>
`;
} else {
if (columnDescriptions && columnDescriptions[i]) {
// Create the SVG icon element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function AutoImportPhase3({ onNextClick }: IAutoImportPhase3Props) {
<Tabs.List>
{autoImportSchedulerFrequency.map((type) => (
<Tabs.Tab key={type} value={type}>
{type.charAt(0).toUpperCase() + type.slice(1)}
<Text size="md">{type.charAt(0).toUpperCase() + type.slice(1)}</Text>
</Tabs.Tab>
))}
</Tabs.List>
Expand Down
8 changes: 6 additions & 2 deletions apps/widget/src/components/widget/Phases/Phase3/Phase3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export function Phase3(props: IPhase3Props) {
isCompleteImportLoading,
setShowAllDataValidModal,
setShowDeleteConfirmModal,
disableFindAndReplace,
disableCheckBox,
} = usePhase3({ onNext: onNextClick });
const tableWrapperRef = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>;
const [tableWrapperDimensions, setTableWrapperDimentions] = useState({
Expand All @@ -70,7 +72,6 @@ export function Phase3(props: IPhase3Props) {
const columnDescriptions = columnDefs.map((column) => column.description || '');

useEffect(() => {
// setting wrapper height
setTableWrapperDimentions({
height: tableWrapperRef.current.getBoundingClientRect().height - 50,
width: tableWrapperRef.current.getBoundingClientRect().width,
Expand Down Expand Up @@ -115,7 +116,9 @@ export function Phase3(props: IPhase3Props) {
]}
/>
<Group spacing="xs">
<Button onClick={() => setShowFindReplaceModal(true)}>{texts.PHASE3.FIND_REPLACE}</Button>
{!disableFindAndReplace && (
<Button onClick={() => setShowFindReplaceModal(true)}>{texts.PHASE3.FIND_REPLACE}</Button>
)}
<Button
color="red"
disabled={!selectedRowsRef.current.size}
Expand Down Expand Up @@ -202,6 +205,7 @@ export function Phase3(props: IPhase3Props) {
columnDefs={columnDefs}
allChecked={allChecked}
columnDescriptions={columnDescriptions}
disableCheckBox={disableCheckBox}
/>
</Stack>
<Pagination page={page} total={totalPages} onChange={onPageChange} />
Expand Down
50 changes: 31 additions & 19 deletions apps/widget/src/hooks/Phase3/usePhase3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function usePhase3({ onNext }: IUsePhase3Props) {
valid: new Set(),
invalid: new Set(),
});
const { uploadInfo, setUploadInfo } = useAppState();
const { uploadInfo, setUploadInfo, config } = useAppState();
const [allChecked, setAllChecked] = useState<boolean>(false);
const [reviewData, setReviewData] = useState<IRecordExtended[]>([]);
const [columnDefs, setColumnDefs] = useState<HotItemSchema[]>([]);
Expand All @@ -60,26 +60,36 @@ export function usePhase3({ onNext }: IUsePhase3Props) {
() => api.getColumns(uploadInfo._id),
{
onSuccess(data) {
let updatedFrozenColumns = 2;
let updatedFrozenColumns = 0;
const dataColumns: IOption[] = [{ value: '', label: 'All columns' }];
const newColumnDefs: HotItemSchema[] = [];
const newHeadings: string[] = ['*', 'Sr. No.'];
newColumnDefs.push({
type: 'text',
data: 'record.index',
readOnly: true,
editor: false,
renderer: 'check',
className: 'check-cell',
disableVisualSelection: true,
});
newColumnDefs.push({
type: 'text',
data: 'index',
readOnly: true,
className: 'index-cell',
disableVisualSelection: true,
});
const newHeadings: string[] = [];

if (!config?.disableCheckBox) {
newHeadings.push('*');
updatedFrozenColumns++;
newColumnDefs.push({
type: 'text',
data: 'record.index',
readOnly: true,
editor: false,
renderer: 'check',
className: 'check-cell',
disableVisualSelection: true,
});
}

if (!config?.disableSrNo) {
newHeadings.push('Sr. No.');
updatedFrozenColumns++;
newColumnDefs.push({
type: 'text',
data: 'index',
readOnly: true,
className: 'index-cell',
disableVisualSelection: true,
});
}
data.forEach((column: ISchemaColumn) => {
if (column.isFrozen) updatedFrozenColumns++;
newHeadings.push(column.name);
Expand Down Expand Up @@ -294,5 +304,7 @@ export function usePhase3({ onNext }: IUsePhase3Props) {
totalRecords: uploadInfo.totalRecords ?? undefined,
invalidRecords: uploadInfo.invalidRecords ?? undefined,
refetchReviewData: () => refetchReviewData([page, type]),
disableFindAndReplace: config?.disableFindAndReplace,
disableCheckBox: config?.disableCheckBox,
};
}
2 changes: 2 additions & 0 deletions apps/widget/src/store/app.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const AppContextProvider = ({
primaryColor,
title,
texts,
config,
data,
sampleFile,
schema,
Expand All @@ -55,6 +56,7 @@ const AppContextProvider = ({
value={{
title,
texts,
config,
host,
reset,
data,
Expand Down
3 changes: 2 additions & 1 deletion apps/widget/src/types/store.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiService } from '@api';
import { Dispatch, SetStateAction } from 'react';
import { IUpload, WIDGET_TEXTS } from '@impler/client';
import { IUpload, WIDGET_TEXTS, WidgetConfig } from '@impler/client';
import { ITemplate, IImportConfig } from '@impler/shared';

export interface IImplerStore {
Expand Down Expand Up @@ -29,6 +29,7 @@ export enum FlowsEnum {
export interface IAppStore {
title?: string;
texts: typeof WIDGET_TEXTS;
config?: WidgetConfig;
importId?: string;
imageSchema?: string;
data?: string;
Expand Down
4 changes: 3 additions & 1 deletion libs/shared/src/types/widget/widget.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WIDGET_TEXTS } from '@impler/client';
import { WIDGET_TEXTS, WidgetConfig } from '@impler/client';
import { ISchemaItem } from '../column';

export interface ICommonShowPayload {
Expand All @@ -16,13 +16,15 @@ export interface ICommonShowPayload {
}
export interface IWidgetShowPayload extends ICommonShowPayload {
texts?: typeof WIDGET_TEXTS;
config?: WidgetConfig;
data?: string;
schema?: string;
output?: string;
}

export interface IUserShowPayload extends ICommonShowPayload {
texts?: string | typeof WIDGET_TEXTS;
config?: WidgetConfig;
data?: string | Record<string, string | number>[];
schema?: string | ISchemaItem[];
output?: string | Record<string, string | number>;
Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface IShowWidgetProps {
accessToken: string;
sampleFile?: File | Blob;
texts?: CustomTexts;
config?: WidgetConfig;
title?: string;
primaryColor?: string;
extra?: string | Record<string, any>;
Expand All @@ -179,6 +180,12 @@ export type DeepPartial<T> = T extends object

export type ValueOf<T> = T[keyof T];

export declare type WidgetConfig = {
disableFindAndReplace?: boolean;
disableCheckBox?: boolean;
disableSrNo?: boolean;
};

export type CustomTexts = DeepPartial<typeof WIDGET_TEXTS>;

export interface IUseImplerProps {
Expand All @@ -189,6 +196,7 @@ export interface IUseImplerProps {
accessToken?: string;
primaryColor?: string;
extra?: string | Record<string, any>;
config?: WidgetConfig;
authHeaderValue?: string | (() => string) | (() => Promise<string>);
onUploadStart?: (value: UploadTemplateData) => void;
onUploadTerminate?: (value: UploadData) => void;
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/hooks/useImpler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function useImpler({
title,
texts,
extra,
config,
onUploadComplete,
onWidgetClose,
onUploadStart,
Expand Down Expand Up @@ -96,6 +97,7 @@ export function useImpler({
output,
title,
extra,
config,
colorScheme,
primaryColor,
};
Expand Down
Loading