Skip to content

Commit

Permalink
fix(portal): fix uploading yaml file validation failed on linux (need…
Browse files Browse the repository at this point in the history
… check) (#291)

* fix(portal): fix uploading yaml file validation failed on linux (need check)

* fix(portal): Change styles of sonata & seller apis input

* fix(portal): remove deprecated pages

* bypass coverage portal UploadYaml.tsx file
  • Loading branch information
james-tran-3005 authored Dec 19, 2024
1 parent a720615 commit f898eac
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 371 deletions.
8 changes: 4 additions & 4 deletions kraken-app/kraken-app-portal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kraken-app/kraken-app-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"js-base64": "^3.7.7",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"nanoid": "^5.0.7",
"nanoid": "^5.0.9",
"path": "^0.12.7",
"qs": "^6.12.1",
"react": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AutoGrowingInput } from "@/components/form";
import { SourceInput as RequestSourceInput } from "@/pages/NewAPIMapping/components/RequestItem/SourceInput";
import { TargetInput as RequestTargetInput } from "@/pages/NewAPIMapping/components/RequestItem/TargetInput";
import { SourceInput as ResponseSourceInput } from "@/pages/NewAPIMapping/components/ResponseItem/SourceInput";
Expand Down Expand Up @@ -194,3 +195,27 @@ describe("NewAPIMapping > response mapping", () => {
expect(response.setActiveSonataResponse).toHaveBeenCalledTimes(1);
});
});

describe('auto growing height input component tests', () => {
it('should render with initial value', () => {
const handleChange = vi.fn()
const { getByRole } = render(<AutoGrowingInput value="hello world" onChange={handleChange} />)

const textbox = getByRole('textbox')
expect(textbox).toHaveTextContent("hello world")

fireEvent.focus(textbox)
fireEvent.blur(textbox)
expect(handleChange).toHaveBeenCalledTimes(1)
})

it('should not change value once disabled', () => {
const handleChange = vi.fn()
const { getByRole } = render(<AutoGrowingInput disabled onChange={handleChange} />)

const textbox = getByRole('textbox')
fireEvent.keyDown(textbox, { key: 'A' })
fireEvent.blur(textbox)
expect(handleChange).toHaveBeenCalledTimes(0)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
import { InputProps } from "antd";

export function AutoGrowingInput({
prefix, suffix, className, value, placeholder,disabled, onChange, onBlur, ...rest
prefix, suffix, className, value, placeholder, disabled, onChange, onBlur, ...rest
}: Readonly<{ value?: string; onChange?: (value: string) => void } & Omit<InputProps, 'value' | 'onChange'>>) {
const [text, setText] = useState<string>('')
const [isFocused, setIsFocused] = useState(false)
Expand All @@ -15,23 +15,29 @@ export function AutoGrowingInput({

return (
<div {...rest}
className={classNames(className, styles.autoGrowingInput, isFocused && styles.focused)}
className={classNames(className, styles.autoGrowingInput, isFocused && styles.focused, disabled && styles.disabled)}
>
{prefix}
<span
className={styles.content}
className={classNames(styles.content, disabled && styles.disabled)}
tabIndex={0}
role="textbox"
contentEditable='true'
contentEditable={disabled ? 'false' : 'true'}
dangerouslySetInnerHTML={{ __html: text }}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
style={{ '--placeholder': `"${placeholder}"` }}
onFocus={() => setIsFocused(true)}
onFocus={() => {
if (!disabled) {
setIsFocused(true)
}
}}
onBlur={e => {
setIsFocused(false)
onChange?.(e.target.textContent ?? '')
onBlur?.(e as any)
if (!disabled) {
onChange?.(e.target.textContent ?? '')
onBlur?.(e as any)
}
}}
onKeyDown={e => {
if (e.key === 'Enter' || disabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
display: flex;
align-items: center;

&.disabled {
border-color: transparent !important;
pointer-events: none;
}

&.focused {
border-color: var(--primary);

Expand All @@ -20,7 +25,7 @@
outline-color: var(--primary);
outline-style: solid;
}

.content {
padding: 6px 7px;
flex: 1;
Expand All @@ -36,5 +41,9 @@
&:focus-visible {
outline: none;
}

&.disabled {
pointer-events: none;
}
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit f898eac

Please sign in to comment.