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

chore(T-161): remove react-json-view package #130

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 27 additions & 21 deletions apps/feature-flags/modals/Flag/Tab/Advance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { Text, CalendarInput, Tabs } from "@basestack/design-system";
// Types
import { EnvironmentInput, FlagFormInputs } from "../types";
import { UseFormSetValue } from "react-hook-form";
import type { InteractionProps } from "react-json-view";
import { Value } from "react-calendar/src/shared/types";
// JSON Editor
const ReactJson = dynamic(import("react-json-view"), { ssr: false });
import type { Value } from "react-calendar/src/shared/types";
// Utils
import dayjs from "dayjs";
// Locales
import useTranslation from "next-translate/useTranslation";
// Styles
import { ReactJsonContainer } from "../styles";
import { EditorContainer } from "../styles";

const Editor = dynamic(() => import("@monaco-editor/react"), {
ssr: false,
});

export interface Props {
setValue: UseFormSetValue<FlagFormInputs>;
Expand Down Expand Up @@ -43,7 +44,7 @@ const AdvanceTab = ({ setValue, environments }: Props) => {
[environments, activeTabIndex],
);

const createOnChangeHandler = <T extends Value | InteractionProps>(
const createOnChangeHandler = <T extends Value | string | undefined>(
propName: string,
) => {
return (data: T) => {
Expand All @@ -54,7 +55,7 @@ const AdvanceTab = ({ setValue, environments }: Props) => {
}

if (propName === "payload") {
value = JSON.stringify((data as InteractionProps)?.updated_src ?? "{}");
value = (data as string) ?? "{}";
}

setValue(
Expand All @@ -75,7 +76,7 @@ const AdvanceTab = ({ setValue, environments }: Props) => {
};
};

const onChangeJson = createOnChangeHandler<InteractionProps>("payload");
const onChangeJson = createOnChangeHandler<string | undefined>("payload");
const onChangeDate = createOnChangeHandler<Value>("expiredAt");

return (
Expand Down Expand Up @@ -116,20 +117,25 @@ const AdvanceTab = ({ setValue, environments }: Props) => {
>
{t("flag.tab.advanced.input.payload.title")}
</Text>
<ReactJsonContainer>
<ReactJson
name="data"
theme="chalk"
iconStyle="triangle"
defaultValue="string"
src={JSON.parse(activeTabData?.payload ?? "{}")}
onEdit={onChangeJson}
onAdd={onChangeJson}
onDelete={onChangeJson}
enableClipboard={false}
collapsed={false}
<EditorContainer>
<Editor
height="150px"
theme="vs-dark"
onChange={(value) => onChangeJson(value)}
language="json"
value={activeTabData?.payload ?? "{}"}
options={{
fontSize: "14px",
formatOnPaste: true,
inlineSuggest: false,
formatOnType: true,
autoClosingBrackets: true,
minimap: {
enabled: false,
},
}}
/>
</ReactJsonContainer>
</EditorContainer>
</>
);
};
Expand Down
6 changes: 2 additions & 4 deletions apps/feature-flags/modals/Flag/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ export const Environments = styled.div`
flex-wrap: wrap;
`;

export const ReactJsonContainer = styled.div`
export const EditorContainer = styled.div`
display: flex;
flex-direction: column;

.react-json-view {
font-size: ${rem("14px")};
div {
border-radius: ${rem("4px")};
padding: ${({ theme }) => theme.spacing.s4};
}
`;
2 changes: 1 addition & 1 deletion apps/feature-flags/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@emotion/is-prop-valid": "^1.2.1",
"@floating-ui/react": "^0.25.4",
"@hookform/resolvers": "^3.3.1",
"@monaco-editor/react": "^4.6.0",
"@next-auth/prisma-adapter": "^1.0.4",
"@prisma/client": "^5.3.1",
"@tanstack/react-query": "^4.35.3",
Expand All @@ -59,7 +60,6 @@
"react-calendar": "^4.6.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.46.2",
"react-json-view": "^1.21.3",
"react-select": "^5.7.5",
"react-spring": "^9.7.1",
"react-use": "^17.4.0",
Expand Down
Loading
Loading