mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix merge from master
This commit is contained in:
parent
f4922811cc
commit
de94d0bdad
31
src/common/utils/__tests__/arrays.test.ts
Normal file
31
src/common/utils/__tests__/arrays.test.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { splitArray } from "../splitArray";
|
||||
|
||||
describe("split array on element tests", () => {
|
||||
test("empty array", () => {
|
||||
expect(splitArray([], 10)).toStrictEqual([[], [], false]);
|
||||
});
|
||||
|
||||
test("one element, not in array", () => {
|
||||
expect(splitArray([1], 10)).toStrictEqual([[1], [], false]);
|
||||
});
|
||||
|
||||
test("ten elements, not in array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], false]);
|
||||
});
|
||||
|
||||
test("one elements, in array", () => {
|
||||
expect(splitArray([1], 1)).toStrictEqual([[], [], true]);
|
||||
});
|
||||
|
||||
test("ten elements, in front array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0)).toStrictEqual([[], [1, 2, 3, 4, 5, 6, 7, 8, 9], true]);
|
||||
});
|
||||
|
||||
test("ten elements, in middle array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)).toStrictEqual([[0, 1, 2, 3], [5, 6, 7, 8, 9], true]);
|
||||
});
|
||||
|
||||
test("ten elements, in end array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 9)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8], [], true]);
|
||||
});
|
||||
});
|
||||
@ -1,5 +1,5 @@
|
||||
// Common utils bundle
|
||||
// Common utils (main/renderer)
|
||||
|
||||
export * from "./app-version"
|
||||
export * from "./base64"
|
||||
export * from "./camelCase"
|
||||
export * from "./splitArray"
|
||||
|
||||
19
src/common/utils/splitArray.ts
Normal file
19
src/common/utils/splitArray.ts
Normal file
@ -0,0 +1,19 @@
|
||||
// Restored from dashboard/client/utils/arrays.ts
|
||||
/**
|
||||
* This function splits an array into two sub arrays on the first instance of
|
||||
* element (from the left). If the array does not contain the element. The
|
||||
* return value is defined to be `[array, [], false]`. If the element is in
|
||||
* the array then the return value is `[left, right, true]` where `left` is
|
||||
* the elements of `array` from `[0, index)` and `right` is `(index, length)`
|
||||
* @param array the full array to split into two sub-arrays
|
||||
* @param element the element in the middle of the array
|
||||
* @returns the left and right sub-arrays which when conjoined with `element`
|
||||
* is the same as `array`, and `true`
|
||||
*/
|
||||
export function splitArray<T>(array: T[], element: T): [T[], T[], boolean] {
|
||||
const index = array.indexOf(element);
|
||||
if (index < 0) {
|
||||
return [array, [], false];
|
||||
}
|
||||
return [array.slice(0, index), array.slice(index + 1, array.length), true]
|
||||
}
|
||||
@ -7,7 +7,7 @@ import { IKubeObjectRef, KubeJsonApi, KubeJsonApiData, KubeJsonApiDataList } fro
|
||||
import { apiKube } from "./index";
|
||||
import { kubeWatchApi } from "./kube-watch-api";
|
||||
import { apiManager } from "./api-manager";
|
||||
import { split } from "../utils/arrays";
|
||||
import { splitArray } from "../../common/utils";
|
||||
|
||||
export interface IKubeApiOptions<T extends KubeObject> {
|
||||
kind: string; // resource type within api-group, e.g. "Namespace"
|
||||
@ -45,7 +45,7 @@ export class KubeApi<T extends KubeObject = any> {
|
||||
const [, prefix, ...parts] = apiPath.split("/");
|
||||
const apiPrefix = `/${prefix}`;
|
||||
|
||||
const [left, right, found] = split(parts, "namespaces");
|
||||
const [left, right, found] = splitArray(parts, "namespaces");
|
||||
let apiGroup, apiVersion, namespace, resource, name;
|
||||
|
||||
if (found) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import "./chart.scss";
|
||||
import React from "react";
|
||||
import ChartJS, {ChartData, ChartOptions} from "chart.js";
|
||||
import ChartJS from "chart.js";
|
||||
import { isEqual, remove } from "lodash";
|
||||
import { cssNames } from "../../utils";
|
||||
import { StatusBrick } from "../status-brick";
|
||||
@ -17,7 +17,7 @@ export interface ChartDataSets extends ChartJS.ChartDataSets {
|
||||
|
||||
export interface ChartProps {
|
||||
data: ChartData;
|
||||
options?: ChartOptions; // Passed to ChartJS instance
|
||||
options?: ChartJS.ChartOptions; // Passed to ChartJS instance
|
||||
width?: number | string;
|
||||
height?: number | string;
|
||||
type?: ChartKind;
|
||||
@ -126,8 +126,7 @@ export class Chart extends React.Component<ChartProps> {
|
||||
...datasets[index],
|
||||
...props
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
datasets[datasetIndex] = next
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user