forked from opensearch-project/ml-commons-dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support external models in deployed model list
Signed-off-by: Lin Wang <wonglam@amazon.com>
- Loading branch information
Showing
31 changed files
with
1,229 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export class Connector { | ||
public async getAll() { | ||
return { | ||
data: [ | ||
{ | ||
id: 'external-connector-1-id', | ||
name: 'External Connector 1', | ||
}, | ||
], | ||
total_connectors: 1, | ||
}; | ||
} | ||
|
||
public async getAllInternal() { | ||
return { | ||
data: ['Internal Connector 1', 'Common Connector'], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
CONNECTOR_API_ENDPOINT, | ||
INTERNAL_CONNECTOR_API_ENDPOINT, | ||
} from '../../server/routes/constants'; | ||
import { InnerHttpProvider } from './inner_http_provider'; | ||
|
||
interface GetAllConnectorResponse { | ||
data: Array<{ | ||
id: string; | ||
name: string; | ||
description?: string; | ||
}>; | ||
total_connectors: number; | ||
} | ||
|
||
interface GetAllInternalConnectorResponse { | ||
data: string[]; | ||
} | ||
|
||
export class Connector { | ||
public getAll() { | ||
return InnerHttpProvider.getHttp().get<GetAllConnectorResponse>(CONNECTOR_API_ENDPOINT); | ||
} | ||
|
||
public getAllInternal() { | ||
return InnerHttpProvider.getHttp().get<GetAllInternalConnectorResponse>( | ||
INTERNAL_CONNECTOR_API_ENDPOINT | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
public/components/common/options_filter/__tests__/options_filter.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { OptionsFilter } from '../options_filter'; | ||
import { render, screen } from '../../../../../test/test_utils'; | ||
|
||
describe('<OptionsFilter />', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should render "Tags" as filter name by default', () => { | ||
render( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={[]} | ||
value={[]} | ||
onChange={() => {}} | ||
/> | ||
); | ||
expect(screen.getByText('Tags')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render Tags with 2 active filter', () => { | ||
render( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={[]} | ||
value={['foo', 'bar']} | ||
onChange={() => {}} | ||
/> | ||
); | ||
expect(screen.getByText('Tags')).toBeInTheDocument(); | ||
expect(screen.getByText('2')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render options filter after filter button clicked', async () => { | ||
render( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={['foo', 'bar']} | ||
value={['foo', 'bar']} | ||
onChange={() => {}} | ||
/> | ||
); | ||
expect(screen.queryByText('foo')).not.toBeInTheDocument(); | ||
expect(screen.queryByPlaceholderText('Search Tags')).not.toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByText('Tags')); | ||
|
||
expect(screen.getByText('foo')).toBeInTheDocument(); | ||
expect(screen.getByPlaceholderText('Search Tags')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render passed footer after filter button clicked', async () => { | ||
const { getByText, queryByText } = render( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={['foo', 'bar']} | ||
value={['foo', 'bar']} | ||
onChange={() => {}} | ||
footer="footer" | ||
/> | ||
); | ||
expect(queryByText('footer')).not.toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByText('Tags')); | ||
expect(getByText('footer')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should only show "bar" after search', async () => { | ||
render( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={['foo', 'bar']} | ||
value={['foo', 'bar']} | ||
onChange={() => {}} | ||
/> | ||
); | ||
|
||
await userEvent.click(screen.getByText('Tags')); | ||
expect(screen.getByText('foo')).toBeInTheDocument(); | ||
|
||
await userEvent.type(screen.getByPlaceholderText('Search Tags'), 'bAr{enter}'); | ||
expect(screen.queryByText('foo')).not.toBeInTheDocument(); | ||
expect(screen.getByText('bar')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onChange with consistent value after option click', async () => { | ||
const onChangeMock = jest.fn(); | ||
const { rerender } = render( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={['foo', 'bar']} | ||
value={[]} | ||
onChange={onChangeMock} | ||
/> | ||
); | ||
|
||
expect(onChangeMock).not.toHaveBeenCalled(); | ||
|
||
await userEvent.click(screen.getByText('Tags')); | ||
await userEvent.click(screen.getByText('foo')); | ||
expect(onChangeMock).toHaveBeenCalledWith(['foo']); | ||
onChangeMock.mockClear(); | ||
|
||
rerender( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={['foo', 'bar']} | ||
value={['foo']} | ||
onChange={onChangeMock} | ||
/> | ||
); | ||
|
||
await userEvent.click(screen.getByText('bar')); | ||
expect(onChangeMock).toHaveBeenCalledWith(['foo', 'bar']); | ||
onChangeMock.mockClear(); | ||
|
||
rerender( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={['foo', 'bar']} | ||
value={['foo', 'bar']} | ||
onChange={onChangeMock} | ||
/> | ||
); | ||
|
||
await userEvent.click(screen.getByText('bar')); | ||
expect(onChangeMock).toHaveBeenCalledWith(['foo']); | ||
onChangeMock.mockClear(); | ||
}); | ||
|
||
it('should call obChange with option.value after option click', async () => { | ||
const onChangeMock = jest.fn(); | ||
render( | ||
<OptionsFilter | ||
name="Tags" | ||
searchPlaceholder="Search Tags" | ||
options={[ | ||
{ name: 'foo', value: 1 }, | ||
{ name: 'bar', value: 2 }, | ||
]} | ||
value={[]} | ||
onChange={onChangeMock} | ||
/> | ||
); | ||
|
||
expect(onChangeMock).not.toHaveBeenCalled(); | ||
|
||
await userEvent.click(screen.getByText('Tags')); | ||
await userEvent.click(screen.getByText('foo')); | ||
expect(onChangeMock).toHaveBeenCalledWith([1]); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
public/components/common/options_filter/__tests__/options_filter_item.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { OptionsFilterItem } from '../options_filter_item'; | ||
|
||
import { render, screen } from '../../../../../test/test_utils'; | ||
|
||
describe('<OptionsFilterItem />', () => { | ||
it('should render passed children and check icon', () => { | ||
render( | ||
<OptionsFilterItem checked="on" value="foo" onClick={() => {}}> | ||
foo | ||
</OptionsFilterItem> | ||
); | ||
expect(screen.getByText('foo')).toBeInTheDocument(); | ||
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onClick with "foo" after click', async () => { | ||
const onClickMock = jest.fn(); | ||
render( | ||
<OptionsFilterItem checked="on" value="foo" onClick={onClickMock}> | ||
foo | ||
</OptionsFilterItem> | ||
); | ||
await userEvent.click(screen.getByRole('option')); | ||
expect(onClickMock).toHaveBeenCalledWith('foo'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { OptionsFilter, OptionsFilterProps } from './options_filter'; |
Oops, something went wrong.