changed to use code editor (#1161)
* changed to use code editor * Update src/components/json-file-upload/JsonFileUpload.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * fixed tests Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
parent
34e9d7a3ca
commit
809247a686
3 changed files with 23 additions and 8 deletions
|
@ -40,7 +40,7 @@ describe("Partial import test", () => {
|
||||||
|
|
||||||
it("Import button only enabled if JSON has something to import", () => {
|
it("Import button only enabled if JSON has something to import", () => {
|
||||||
modal.open();
|
modal.open();
|
||||||
cy.get("#partial-import-file").type("{}");
|
cy.get(".pf-c-code-editor__code textarea").type("{}");
|
||||||
modal.importButton().should("be.disabled");
|
modal.importButton().should("be.disabled");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,13 @@ export default class GroupModal {
|
||||||
(myJSON) => {
|
(myJSON) => {
|
||||||
const text = JSON.stringify(myJSON);
|
const text = JSON.stringify(myJSON);
|
||||||
|
|
||||||
cy.get("#partial-import-file").type(text, {
|
cy.get(".pf-c-code-editor__code textarea")
|
||||||
parseSpecialCharSequences: false,
|
.type(text, {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
});
|
parseSpecialCharSequences: false,
|
||||||
|
})
|
||||||
|
.type("{shift}{end}")
|
||||||
|
.type("{del}");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,9 +8,10 @@ import {
|
||||||
FileUploadProps,
|
FileUploadProps,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { CodeEditor, Language } from "@patternfly/react-code-editor";
|
||||||
|
|
||||||
type FileUpload = {
|
type FileUpload = {
|
||||||
value: string | File;
|
value: string;
|
||||||
filename: string;
|
filename: string;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
modal: boolean;
|
modal: boolean;
|
||||||
|
@ -60,7 +61,7 @@ export const JsonFileUpload = ({
|
||||||
} else {
|
} else {
|
||||||
setFileUpload({
|
setFileUpload({
|
||||||
...fileUpload,
|
...fileUpload,
|
||||||
value,
|
value: value as string,
|
||||||
filename,
|
filename,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -147,7 +148,18 @@ export const JsonFileUpload = ({
|
||||||
dropzoneProps={{
|
dropzoneProps={{
|
||||||
accept: ".json",
|
accept: ".json",
|
||||||
}}
|
}}
|
||||||
|
hideDefaultPreview
|
||||||
|
>
|
||||||
|
<CodeEditor
|
||||||
|
isLineNumbersVisible
|
||||||
|
code={fileUpload.value}
|
||||||
|
language={Language.json}
|
||||||
|
height="128px"
|
||||||
|
onChange={(value, event) =>
|
||||||
|
handleChange(value ?? "", fileUpload.filename, event)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
</FileUpload>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue