Skip to content

Commit

Permalink
fix(portal): Change styles of sonata & seller apis input
Browse files Browse the repository at this point in the history
  • Loading branch information
james-tran-3005 committed Dec 17, 2024
1 parent 94b6371 commit b99ff8f
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 28 deletions.
2 changes: 1 addition & 1 deletion kraken-app/kraken-app-portal/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_BASE_API=http://localhost:8001
VITE_BASE_API="https://kraken-portal-cn.dev.consolecore.cc/api"
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
import { render } from "@testing-library/react";
import { QueryClientProvider } from "@tanstack/react-query";
import { queryClient } from "@/utils/helpers/reactQuery";
import { BrowserRouter } from "react-router-dom";
import { render } from "@/__test__/utils";
import APIServerEditSelection from "..";
test("select API", () => {
const { container } = render(
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<APIServerEditSelection />
</BrowserRouter>
</QueryClientProvider>
);
expect(container).toBeInTheDocument();
import * as productHooks from '@/hooks/product'

describe("API server edit selection", () => {
it('should render without detail data', () => {
const { container, getByText } = render(
<APIServerEditSelection />
);
expect(container).toBeInTheDocument();
expect(getByText('Seller API Setup')).toBeInTheDocument()
expect(getByText('OK')).toBeInTheDocument()
expect(getByText('Cancel')).toBeInTheDocument()
})

it('should render with detail data', () => {
vi.spyOn(productHooks, "useGetComponentDetail").mockReturnValue({
data: {
facets: {
baseSpec: {
content: "content",
},
selectedAPIS: [],
metadata: {
name: "metadata",
version: "1.0"
}
},
},
isLoading: false,
isFetching: false,
isFetched: true
} as any)

const { container } = render(
<APIServerEditSelection />
);
expect(container).toBeInTheDocument();
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function SourceInput({
[styles.active]: isFocused,
[styles.error]:
errors?.requestIds?.has(item.id as any) && !item.source,
[styles.disabled]: !item.customizedField,
})}
value={item.source}
style={{ flex: 1 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}

.sellerPropItemWrapper {
background: #f2f3f5;
cursor: pointer;

input {
Expand All @@ -46,11 +45,11 @@
text-overflow: ellipsis;
cursor: pointer;

&:disabled {
&.disabled {
color: var(--black) !important;
background: var(--lightgray) !important;
border: none !important;
cursor: default;
cursor: not-allowed;
}

&.error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function TargetInput({
className={clsx(styles.input, {
[styles.activeInput]: isFocused,
[styles.error]: errors?.responseIds?.has(item.id!) && !item.target,
[styles.disabled]: !item.customizedField,
})}
value={item.target}
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
text-overflow: ellipsis;
}

&:disabled {
&.disabled {
color: #000 !important;
background: #f0f2f5 !important;
border: none !important;
cursor: default;
cursor: not-allowed;
}

&.error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
border-radius: 6px;
padding: 17px;
.sellerPropItemWrapper {
background: #f2f3f5;
cursor: pointer;
&.active {
border-radius: 2px;
Expand Down

0 comments on commit b99ff8f

Please sign in to comment.