Skip to content

Commit

Permalink
Revert "[GEN-1515]: fix stringify for graphql (odigos-io#1615)"
Browse files Browse the repository at this point in the history
  • Loading branch information
BenElferink authored Oct 27, 2024
1 parent f97a5a1 commit 41baae0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React, { useMemo } from 'react';
import { safeJsonParse } from '@/utils';
import { FieldTitle, FieldWrapper } from './styled';
import { KeyValueInputsList } from '@/reuseable-components';
import styled from 'styled-components';
import { KeyValueInputsList, Text } from '@/reuseable-components';

const FieldWrapper = styled.div`
width: 100%;
margin: 8px 0;
`;

const FieldTitle = styled(Text)`
margin-bottom: 12px;
`;

type Props = {
value: string;
Expand All @@ -18,10 +26,7 @@ type Parsed = {
const AddClusterInfo: React.FC<Props> = ({ value, setValue }) => {
const mappedValue = useMemo(
() =>
safeJsonParse<Parsed>(value, { clusterAttributes: [] }).clusterAttributes.map((obj) => ({
key: obj.attributeName,
value: obj.attributeStringValue,
})),
value ? (JSON.parse(value) as Parsed).clusterAttributes.map((obj) => ({ key: obj.attributeName, value: obj.attributeStringValue })) : undefined,
[value]
);

Expand All @@ -32,11 +37,15 @@ const AddClusterInfo: React.FC<Props> = ({ value, setValue }) => {
}[]
) => {
const payload: Parsed = {
clusterAttributes: arr.map((obj) => ({
clusterAttributes: [],
};

arr.forEach((obj) => {
payload.clusterAttributes.push({
attributeName: obj.key,
attributeStringValue: obj.value,
})),
};
});
});

setValue(JSON.stringify(payload));
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React, { useMemo } from 'react';
import { safeJsonParse } from '@/utils';
import { InputList } from '@/reuseable-components';
import { FieldTitle, FieldWrapper } from './styled';
import styled from 'styled-components';
import { InputList, Text } from '@/reuseable-components';

const FieldWrapper = styled.div`
width: 100%;
margin: 8px 0;
`;

const FieldTitle = styled(Text)`
margin-bottom: 12px;
`;

type Props = {
value: string;
Expand All @@ -13,7 +21,7 @@ type Parsed = {
};

const DeleteAttributes: React.FC<Props> = ({ value, setValue }) => {
const mappedValue = useMemo(() => safeJsonParse<Parsed>(value, { attributeNamesToDelete: [] }).attributeNamesToDelete, [value]);
const mappedValue = useMemo(() => (value ? (JSON.parse(value) as Parsed).attributeNamesToDelete : undefined), [value]);

const handleChange = (arr: string[]) => {
const payload: Parsed = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React, { useMemo } from 'react';
import { safeJsonParse } from '@/utils';
import { InputList } from '@/reuseable-components';
import { FieldTitle, FieldWrapper } from './styled';
import styled from 'styled-components';
import { InputList, Text } from '@/reuseable-components';

const FieldWrapper = styled.div`
width: 100%;
margin: 8px 0;
`;

const FieldTitle = styled(Text)`
margin-bottom: 12px;
`;

type Props = {
value: string;
Expand All @@ -13,7 +21,7 @@ type Parsed = {
};

const PiiMasking: React.FC<Props> = ({ value, setValue }) => {
const mappedValue = useMemo(() => safeJsonParse<Parsed>(value, { piiCategories: [] }).piiCategories, [value]);
const mappedValue = useMemo(() => (value ? (JSON.parse(value) as Parsed).piiCategories : undefined), [value]);

const handleChange = (arr: string[]) => {
const payload: Parsed = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React, { useMemo } from 'react';
import { safeJsonParse } from '@/utils';
import { FieldTitle, FieldWrapper } from './styled';
import { KeyValueInputsList } from '@/reuseable-components';
import styled from 'styled-components';
import { KeyValueInputsList, Text } from '@/reuseable-components';

const FieldWrapper = styled.div`
width: 100%;
margin: 8px 0;
`;

const FieldTitle = styled(Text)`
margin-bottom: 12px;
`;

type Props = {
value: string;
Expand All @@ -16,7 +24,7 @@ type Parsed = {

const RenameAttributes: React.FC<Props> = ({ value, setValue }) => {
const mappedValue = useMemo(
() => Object.entries(safeJsonParse<Parsed>(value, { renames: {} }).renames).map(([k, v]) => ({ key: k, value: v })),
() => (value ? Object.entries((JSON.parse(value) as Parsed).renames).map(([k, v]) => ({ key: k, value: v })) : undefined),
[value]
);

Expand Down

This file was deleted.

0 comments on commit 41baae0

Please sign in to comment.