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

support for null in ui4t operations #875

Merged
merged 2 commits into from
May 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Input from '@/components/UI/Input/Input';
import { OperationFormProps } from '../../OperationConfigLayout';
import { Autocomplete } from '@/components/UI/Autocomplete/Autocomplete';
import InfoTooltip from '@/components/UI/Tooltip/Tooltip';
import { parseStringForNull } from '@/utils/common';

interface GenericOperand {
value: string;
Expand Down Expand Up @@ -324,7 +325,10 @@ const CaseWhenOpForm = ({
col_val: string;
const_val: string;
}) => ({
value: op.type === 'col' ? op.col_val : op.const_val,
value:
op.type === 'col'
? op.col_val
: parseStringForNull(op.const_val),
is_col: op.type === 'col',
})
)
Expand All @@ -333,7 +337,7 @@ const CaseWhenOpForm = ({
value:
clause.then.type === 'col'
? clause.then.col_val
: clause.then.const_val,
: parseStringForNull(clause.then.const_val),
is_col: clause.then.type === 'col',
},
operator: clause.logicalOp.id,
Expand All @@ -343,7 +347,7 @@ const CaseWhenOpForm = ({
value:
data.else.type === 'col'
? data.else.col_val
: data.else.const_val,
: parseStringForNull(data.else.const_val),
is_col: data.else.type === 'col',
},
sql_snippet: data.sql_snippet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { GlobalContext } from '@/contexts/ContextProvider';
import { errorToast } from '@/components/ToastMessage/ToastHelper';
import { OperationFormProps } from '../../OperationConfigLayout';
import { Autocomplete } from '@/components/UI/Autocomplete/Autocomplete';
import { parseStringForNull } from '@/utils/common';

export interface GenericCol {
function_name: string;
Expand Down Expand Up @@ -66,7 +67,7 @@ const GenericColumnOpForm = ({
operands: {
type: string;
col_val: string;
const_val: number | undefined;
const_val: string | undefined;
}[];
output_column_name: string;
}[];
Expand Down Expand Up @@ -126,10 +127,13 @@ const GenericColumnOpForm = ({
(op: {
type: string;
col_val: string;
const_val: number | undefined;
const_val: string | undefined;
}) => ({
is_col: op.type === 'col',
value: op.type === 'col' ? op.col_val : op.const_val,
value:
op.type === 'col'
? op.col_val
: parseStringForNull(op.const_val),
})
),
output_column_name: item.output_column_name,
Expand Down Expand Up @@ -306,7 +310,6 @@ const GenericColumnOpForm = ({
fieldStyle="transformation"
sx={{ padding: '0' }}
placeholder="Enter a numeric value"
type="number"
disabled={action === 'view'}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Input from '@/components/UI/Input/Input';
import { OperationFormProps } from '../../OperationConfigLayout';
import { Autocomplete } from '@/components/UI/Autocomplete/Autocomplete';
import { GridTable } from '@/components/UI/GridTable/GridTable';
import { parseStringForNull } from '@/utils/common';

interface ReplaceOp {
find: string;
Expand Down Expand Up @@ -114,8 +115,8 @@ const ReplaceValueOpForm = ({
data.config.forEach((item: any) => {
if (item.old && item.new)
postData.config.columns[0].replace_ops.push({
find: item.old,
replace: item.new,
find: parseStringForNull(item.old),
replace: parseStringForNull(item.new),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { OperationFormProps } from '../../OperationConfigLayout';
import { Autocomplete } from '@/components/UI/Autocomplete/Autocomplete';
import InfoTooltip from '@/components/UI/Tooltip/Tooltip';
import { LogicalOperators } from './CaseWhenOpForm';
import { parseStringForNull } from '@/utils/common';

interface GenericOperand {
value: string;
Expand Down Expand Up @@ -124,7 +125,7 @@ const WhereFilterOpForm = ({
value:
data.operand.type === 'col'
? data.operand.col_val
: data.operand.const_val,
: parseStringForNull(data.operand.const_val),
is_col: data.operand.type === 'col',
},
},
Expand Down
8 changes: 8 additions & 0 deletions src/utils/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ export const trimString = (string: string, length: number) => {
string
);
};

export const parseStringForNull = (st: string | null | undefined) => {
if (st === null || st === undefined) {
return null;
}

return st.trim().toLowerCase() === 'null' ? null : st;
};