Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/util/getWorstHealthCheckStatus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HealthCheck, HealthCheckStatus } from '../services/topoCliSchema';

export const getWorstHealthCheckStatus = (
healthChecks: HealthCheck[],
healthChecks: readonly HealthCheck[],
): HealthCheckStatus => {
return healthChecks.reduce((acc: HealthCheckStatus, healthCheck) => {
if (healthCheck.status === 'error') {
Expand Down
9 changes: 8 additions & 1 deletion src/views/hostTreeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('HostTreeView', () => {
expect(children[0].contextValue).toBe('Health');
});

it('returns host health checks sorted by name below the Health group', async () => {
it('returns sorted host health checks without mutating the model', async () => {
const model = new HostModel();
model.setHealth(
loaded({
Expand Down Expand Up @@ -79,6 +79,13 @@ describe('HostTreeView', () => {
description: 'missing',
}),
]);
expect(model.health).toMatchObject({
data: {
host: {
dependencies: [{ name: 'Zed' }, { name: 'Alpha' }],
},
},
});
});

it('returns an error item when host health cannot be loaded', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/views/hostTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { HostModel } from '../models/hostModel';
import { DisposableCollector } from '../util/disposableCollector';
import { loaded } from '../util/loadable';

function sortHealthChecksByName(healthChecks: HealthCheck[]): HealthCheck[] {
return healthChecks.sort((a, b) =>
function sortHealthChecksByName(
healthChecks: readonly HealthCheck[],
): HealthCheck[] {
return healthChecks.toSorted((a, b) =>
a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }),
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/views/projectsTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
ProcessingDomainTreeItem,
} from './treeItems/processingDomainTreeItem';

function syncProjectCountContext(projects: Loadable<ProjectMetadata[]>): void {
function syncProjectCountContext(
projects: Loadable<readonly ProjectMetadata[]>,
): void {
const count =
projects.status === 'loaded' ? projects.data.length : undefined;
void vscode.commands.executeCommand(
Expand All @@ -35,7 +37,7 @@ function compareContainers(a: ContainerItem, b: ContainerItem): number {
}

function groupContainersByProcessingDomain(
containers: ContainerItem[],
containers: readonly ContainerItem[],
): ProcessingDomainTreeItem[] {
const containersByDomain = new Map<string, ContainerItem[]>();
for (const container of containers) {
Expand All @@ -48,7 +50,7 @@ function groupContainersByProcessingDomain(

return [...containersByDomain.entries()]
.map(([domain, containers]) => {
const sortedContainers = [...containers].sort(compareContainers);
const sortedContainers = containers.toSorted(compareContainers);
return new ProcessingDomainTreeItem(domain, sortedContainers);
})
.sort(compareProcessingDomains);
Expand Down
6 changes: 4 additions & 2 deletions src/views/targetTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function getSelectedTargetChildren(
}
}

function syncTargetDataIssueContext(targets: Loadable<string[]>): void {
function syncTargetDataIssueContext(
targets: Loadable<readonly string[]>,
): void {
void vscode.commands.executeCommand(
'setContext',
manifest.CONTEXT_TARGET_DATA_ISSUE,
Expand Down Expand Up @@ -199,7 +201,7 @@ export class TargetTreeView
}

if (element instanceof HealthCheckGroupTreeItem) {
const healthChecks = [...element.healthChecks].sort(compareByName);
const healthChecks = element.healthChecks.toSorted(compareByName);
return healthChecks.map(
(healthCheck) => new HealthCheckTreeItem(loaded(healthCheck)),
);
Expand Down
4 changes: 2 additions & 2 deletions src/views/treeItems/healthCheckGroupTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Loaded } from '../../util/loadable';
import { hasFixCommand } from '../../util/issueFixes';

export class HealthCheckGroupTreeItem extends vscode.TreeItem {
public readonly healthChecks: HealthCheck[];
public readonly healthChecks: readonly HealthCheck[];

constructor(healthChecks: Loaded<HealthCheck[]>) {
constructor(healthChecks: Loaded<readonly HealthCheck[]>) {
super('Health', vscode.TreeItemCollapsibleState.Collapsed);
this.contextValue = 'Health';
if (healthChecks.data.some(hasFixCommand)) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/treeItems/processingDomainTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function compareProcessingDomains(
export class ProcessingDomainTreeItem extends vscode.TreeItem {
constructor(
public readonly processingDomain: string,
public readonly containers?: ContainerItem[],
public readonly containers?: readonly ContainerItem[],
) {
super(
processingDomain,
Expand Down
4 changes: 2 additions & 2 deletions src/views/treeItems/projectTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Loadable } from '../../util/loadable';
import { ContainerItem } from '../../util/types';

function getCollapsibleState(
containers: Loadable<ContainerItem[]>,
containers: Loadable<readonly ContainerItem[]>,
): vscode.TreeItemCollapsibleState {
if (containers.status === 'loaded') {
return containers.data.length > 0
Expand All @@ -25,7 +25,7 @@ export class ProjectTreeItem extends vscode.TreeItem {
constructor(
public readonly project: ProjectMetadata,
showWorkspaceName: boolean,
public readonly containers: Loadable<ContainerItem[]>,
public readonly containers: Loadable<readonly ContainerItem[]>,
) {
super(project.name, getCollapsibleState(containers));
this.composeFileUri = project.composeFileUri;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": ["ES2022", "DOM"],
"lib": ["ES2023", "DOM"],
"types": ["node", "vitest/globals"]
},
"include": ["**/*.ts"]
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2022",
"target": "ES2023",
"module": "commonjs",
"lib": ["ES2022"],
"lib": ["ES2023"],
"types": ["node", "vitest/globals"],
"sourceMap": true,
"strict": true,
Expand Down