mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
feat: connected instances support query param for env (#6362)
This commit is contained in:
parent
38658ae653
commit
b82a650dab
@ -14,19 +14,27 @@ const setupApi = (
|
|||||||
environments: [{ name: 'development' }, { name: 'production' }],
|
environments: [{ name: 'development' }, { name: 'production' }],
|
||||||
});
|
});
|
||||||
testServerRoute(server, '/api/admin/ui-config', {});
|
testServerRoute(server, '/api/admin/ui-config', {});
|
||||||
testServerRoute(server, '/api/admin/metrics/instances/my-app/development', {
|
testServerRoute(
|
||||||
|
server,
|
||||||
|
'/api/admin/metrics/instances/my-app/environment/development',
|
||||||
|
{
|
||||||
instances,
|
instances,
|
||||||
});
|
},
|
||||||
testServerRoute(server, '/api/admin/metrics/instances/my-app/production', {
|
);
|
||||||
|
testServerRoute(
|
||||||
|
server,
|
||||||
|
'/api/admin/metrics/instances/my-app/environment/production',
|
||||||
|
{
|
||||||
instances: [
|
instances: [
|
||||||
{
|
{
|
||||||
instanceId: 'shouldNotShowUp',
|
instanceId: 'prodInstance',
|
||||||
clientIp: 'irrelevant',
|
clientIp: 'irrelevant',
|
||||||
lastSeen: '2024-02-26T14:00:59.980Z',
|
lastSeen: '2024-02-26T14:00:59.980Z',
|
||||||
sdkVersion: 'irrelevant',
|
sdkVersion: 'irrelevant',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
test('Display connected instances', async () => {
|
test('Display connected instances', async () => {
|
||||||
@ -57,20 +65,28 @@ test('Display connected instances', async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await screen.findByText('development');
|
await screen.findByText('development');
|
||||||
await screen.findByText('production');
|
const prodButton = await screen.findByText('production');
|
||||||
await screen.findByText('devInstance1');
|
await screen.findByText('devInstance1');
|
||||||
await screen.findByText('devInstance2');
|
await screen.findByText('devInstance2');
|
||||||
await screen.findByText('192.168.0.1');
|
await screen.findByText('192.168.0.1');
|
||||||
await screen.findByText('192.168.0.2');
|
await screen.findByText('192.168.0.2');
|
||||||
await screen.findByText('unleash-client-node:5.5.0');
|
await screen.findByText('unleash-client-node:5.5.0');
|
||||||
await screen.findByText('unleash-client-node:5.5.1');
|
await screen.findByText('unleash-client-node:5.5.1');
|
||||||
|
|
||||||
expect(screen.queryByText('prodInstance')).not.toBeInTheDocument();
|
expect(screen.queryByText('prodInstance')).not.toBeInTheDocument();
|
||||||
|
|
||||||
// check order
|
// check order
|
||||||
const [, row1, row2] = screen.getAllByRole('row');
|
const [, row1, row2] = screen.getAllByRole('row');
|
||||||
expect(row1.textContent?.includes('devInstance1')).toBe(true);
|
expect(row1.textContent?.includes('devInstance1')).toBe(true);
|
||||||
expect(row2.textContent?.includes('devInstance2')).toBe(true);
|
expect(row2.textContent?.includes('devInstance2')).toBe(true);
|
||||||
|
|
||||||
|
// switch tab
|
||||||
|
prodButton.click();
|
||||||
|
|
||||||
|
await screen.findByText('prodInstance');
|
||||||
|
expect(screen.queryByText('devInstance1')).not.toBeInTheDocument();
|
||||||
|
expect(window.location.href).toContain(
|
||||||
|
'applications/my-app/instances?environment=production',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Display no connected instances', async () => {
|
test('Display no connected instances', async () => {
|
||||||
|
@ -8,6 +8,7 @@ import { useApplicationOverview } from 'hooks/api/getters/useApplicationOverview
|
|||||||
import { useConnectedInstances } from 'hooks/api/getters/useConnectedInstances/useConnectedInstances';
|
import { useConnectedInstances } from 'hooks/api/getters/useConnectedInstances/useConnectedInstances';
|
||||||
import { ApplicationEnvironmentInstancesSchemaInstancesItem } from '../../../openapi';
|
import { ApplicationEnvironmentInstancesSchemaInstancesItem } from '../../../openapi';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
|
import { StringParam, useQueryParam, withDefault } from 'use-query-params';
|
||||||
|
|
||||||
const useEnvironments = (application: string) => {
|
const useEnvironments = (application: string) => {
|
||||||
const { data: applicationOverview } = useApplicationOverview(application);
|
const { data: applicationOverview } = useApplicationOverview(application);
|
||||||
@ -15,9 +16,9 @@ const useEnvironments = (application: string) => {
|
|||||||
const applicationEnvironments = applicationOverview.environments
|
const applicationEnvironments = applicationOverview.environments
|
||||||
.map((env) => env.name)
|
.map((env) => env.name)
|
||||||
.sort();
|
.sort();
|
||||||
|
const [currentEnvironment, setCurrentEnvironment] = useQueryParam(
|
||||||
const [currentEnvironment, setCurrentEnvironment] = useState(
|
'environment',
|
||||||
applicationEnvironments[0],
|
withDefault(StringParam, applicationEnvironments[0]),
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -35,6 +36,7 @@ const useEnvironments = (application: string) => {
|
|||||||
|
|
||||||
export const ConnectedInstances: FC = () => {
|
export const ConnectedInstances: FC = () => {
|
||||||
const name = useRequiredPathParam('name');
|
const name = useRequiredPathParam('name');
|
||||||
|
|
||||||
const { currentEnvironment, setCurrentEnvironment, environments } =
|
const { currentEnvironment, setCurrentEnvironment, environments } =
|
||||||
useEnvironments(name);
|
useEnvironments(name);
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export const useConnectedInstances = (
|
|||||||
options: SWRConfiguration = {},
|
options: SWRConfiguration = {},
|
||||||
) => {
|
) => {
|
||||||
const path = formatApiPath(
|
const path = formatApiPath(
|
||||||
`api/admin/metrics/instances/${application}/${environment}`,
|
`api/admin/metrics/instances/${application}/environment/${environment}`,
|
||||||
);
|
);
|
||||||
const { data, error } = useConditionalSWR<ConnectedInstancesSchema>(
|
const { data, error } = useConditionalSWR<ConnectedInstancesSchema>(
|
||||||
Boolean(environment),
|
Boolean(environment),
|
||||||
|
@ -158,7 +158,7 @@ class MetricsController extends Controller {
|
|||||||
});
|
});
|
||||||
this.route({
|
this.route({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/instances/:appName/:environment',
|
path: '/instances/:appName/environment/:environment',
|
||||||
handler: this.getApplicationEnvironmentInstances,
|
handler: this.getApplicationEnvironmentInstances,
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
|
@ -136,7 +136,9 @@ test('should show correct number of total', async () => {
|
|||||||
expect(body).toMatchObject(expected);
|
expect(body).toMatchObject(expected);
|
||||||
|
|
||||||
const { body: instancesBody } = await app.request
|
const { body: instancesBody } = await app.request
|
||||||
.get(`/api/admin/metrics/instances/${metrics.appName}/default`)
|
.get(
|
||||||
|
`/api/admin/metrics/instances/${metrics.appName}/environment/default`,
|
||||||
|
)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(instancesBody).toMatchObject({
|
expect(instancesBody).toMatchObject({
|
||||||
|
Loading…
Reference in New Issue
Block a user