Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSCI][Enhancement] ts cleanup and precommit #930

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
41 changes: 34 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

const LICENSE_HEADER = `
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
* Copyright OpenSearch Contributors
*
kohinoor98 marked this conversation as resolved.
Show resolved Hide resolved
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
`;

Expand All @@ -15,6 +20,28 @@ module.exports = {
extends: ["@elastic/eslint-config-kibana", "plugin:@elastic/eui/recommended"],
rules: {
// "@osd/eslint/require-license-header": "off"
"import/no-default-export": "off",
"@typescript-eslint/naming-convention": [
"error",
{
selector: "default",
format: ["camelCase", "UPPER_CASE", "PascalCase", "snake_case"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
],
"@osd/eslint/no-restricted-paths": [
"error",
{
basePath: __dirname,
zones: [
{
target: ["(public|server)/**/*"],
from: ["../../packages/**/*", "packages/**/*"],
},
],
},
],
},
overrides: [
{
Expand Down
55 changes: 49 additions & 6 deletions .github/workflows/links.yml
kohinoor98 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
name: Link Checker
name: Link Checker and ESLint
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
linkchecker:
lint-and-link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout Repository
uses: actions/checkout@v2


# Enable longer filenames for windows
- name: Enable longer filenames
if: ${{ matrix.os == 'windows-latest' }}
run: git config --system core.longpaths true
- name: Checkout OpenSearch-Dashboards
uses: actions/checkout@v2
with:
repository: opensearch-project/OpenSearch-Dashboards
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
path: OpenSearch-Dashboards
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: "./OpenSearch-Dashboards/.nvmrc"
registry-url: "https://registry.npmjs.org"
- name: Install Yarn
# Need to use bash to avoid having a windows/linux specific step
shell: bash
run: |
YARN_VERSION=$(node -p "require('./OpenSearch-Dashboards/package.json').engines.yarn")
echo "Installing yarn@$YARN_VERSION"
npm i -g yarn@$YARN_VERSION
- run: node -v
- run: yarn -v
- name: Checkout Index Management Dashboards plugin
uses: actions/checkout@v2
with:
path: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin
- name: Bootstrap plugin/OpenSearch-Dashboards
run: |
cd OpenSearch-Dashboards/plugins/index-management-dashboards-plugin
yarn osd bootstrap

- name: Install Dependencies
run: yarn install

- name: Run ESLint
run: yarn eslint:run
working-directory: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin

- name: lychee Link Checker
id: lychee
uses: lycheeverse/lychee-action@master
with:
args: --accept=200,403,429 --exclude=localhost "**/*.html" "**/*.md" "**/*.txt" "**/*.json"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Fail if there were link errors
run: exit ${{ steps.lychee.outputs.exit_code }}
8 changes: 7 additions & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"*.{ts,tsx,js,jsx,json,css,md}": ["prettier --write", "git add"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this git add here?

Copy link
Contributor Author

@kohinoor98 kohinoor98 Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For lint-staged v10 onwards, we do not need to add git add
We are using:

    "lint-staged": "^10.2.0",

It should be fine. Do you think I should add it as a fail-safe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know 👍

"*.{ts,tsx}": [
"npx eslint --fix",
"prettier --write"
],
"*.{js,jsx,json,css,md}": [
"prettier --write"
]
}
16 changes: 13 additions & 3 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/// <reference types="cypress" />
// / <reference types="cypress" />

declare namespace Cypress {
interface Chainable<Subject> {
Expand Down
37 changes: 26 additions & 11 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// TODO: Backend has PR out to change this model, this needs to be updated once that goes through
Expand Down Expand Up @@ -41,13 +51,13 @@ export type DiffableMappingsPropertiesObject = Record<
}
>;

export type MappingsProperties = {
export type MappingsProperties = Array<{
fieldName: string;
type: string;
path?: string;
analyzer?: string;
properties?: MappingsProperties;
}[];
}>;

export interface IndexItem {
index: string;
Expand Down Expand Up @@ -525,14 +535,14 @@ export interface Transform {
enabled_at: number | null;
updated_at: number;
metadata_id: string | null;
aggregations: Map<String, any>;
aggregations: Map<string, any>;
page_size: number;
schedule: IntervalSchedule | CronSchedule;
schema_version: number;
source_index: string;
target_index: string;
roles: String[];
data_selection_query: Map<String, any>;
roles: string[];
data_selection_query: Map<string, any>;
}

export interface TransformMetadata {
Expand Down Expand Up @@ -571,15 +581,15 @@ export interface CronSchedule {
};
}

//Frontend dimension data model
// Frontend dimension data model
export interface DimensionItem {
sequence: number;
field: FieldItem;
aggregationMethod: string;
interval?: number;
}

//Frontend metric data model
// Frontend metric data model
export interface MetricItem {
source_field: FieldItem;
all: boolean;
Expand Down Expand Up @@ -620,18 +630,23 @@ interface HistogramItem {
};
}

//Backend dimension data model
// Backend dimension data model
export type RollupDimensionItem = DateHistogramItem | TermsItem | HistogramItem;

//Backend metric data model
// Backend metric data model
export interface RollupMetricItem {
source_field: string;
metrics: [
{
// eslint-disable-next-line @typescript-eslint/ban-types
min?: Object;
// eslint-disable-next-line @typescript-eslint/ban-types
max?: Object;
// eslint-disable-next-line @typescript-eslint/ban-types
sum?: Object;
// eslint-disable-next-line @typescript-eslint/ban-types
avg?: Object;
// eslint-disable-next-line @typescript-eslint/ban-types
value_count?: Object;
}
];
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"osd": "node ../../scripts/osd",
"opensearch": "node ../../scripts/opensearch",
"lint": "node ../../scripts/eslint . && node ../../scripts/stylelint",
"eslint:fix": "npx eslint '**/*.{ts,tsx}' --fix",
"eslint:run": "npx eslint '**/*.{ts,tsx}'",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js",
"build": "yarn plugin-helpers build",
Expand Down Expand Up @@ -73,4 +75,4 @@
"engines": {
"yarn": "^1.21.1"
}
}
}
18 changes: 14 additions & 4 deletions public/JobHandler/callbacks/force_merge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { CoreSetup } from "opensearch-dashboards/public";
import { callbackForForceMerge, callbackForForceMergeTimeout } from "./force_merge";
import { coreServicesMock, httpClientMock } from "../../../test/mocks";
import { ListenType } from "../../lib/JobScheduler";
import { CoreSetup } from "opensearch-dashboards/public";

const getMockFn = (response = {}, ok = true) => {
return jest.fn().mockResolvedValue({
Expand All @@ -33,7 +43,7 @@ const core = ({
describe("callbackForForceMerge spec", () => {
it("callback when error", async () => {
httpClientMock.fetch = getMockFn({}, false);
let result = await callbackForForceMerge(forceMergeMetaData, {
const result = await callbackForForceMerge(forceMergeMetaData, {
core,
});
expect(result).toBe(false);
Expand Down
18 changes: 14 additions & 4 deletions public/JobHandler/callbacks/force_merge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import React from "react";
import { CallbackType, TaskResult } from "../interface";
Expand All @@ -15,11 +25,11 @@ type ForceMergeTaskResult = TaskResult<{
successful: number;
total: number;
failed: number;
failures?: {
failures?: Array<{
index: string;
status: string;
shard: number;
}[];
}>;
};
}>;

Expand Down
18 changes: 14 additions & 4 deletions public/JobHandler/callbacks/open.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { CoreSetup } from "opensearch-dashboards/public";
import { callbackForOpen, callbackForOpenTimeout } from "./open";
import { coreServicesMock, httpClientMock } from "../../../test/mocks";
import { ListenType } from "../../lib/JobScheduler";
import { CoreSetup } from "opensearch-dashboards/public";

const getMockFn = (response = {}, ok = true) => {
return jest.fn().mockResolvedValue({
Expand All @@ -32,7 +42,7 @@ const core = ({
describe("callbackForOpen spec", () => {
it("callback when error", async () => {
httpClientMock.fetch = getMockFn({}, false);
let result = await callbackForOpen(openMetaData, {
const result = await callbackForOpen(openMetaData, {
core,
});
expect(result).toBe(false);
Expand Down
15 changes: 13 additions & 2 deletions public/JobHandler/callbacks/open.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import React from "react";
import { CallbackType, TaskResult } from "../interface";
import { OpenJobMetaData } from "../../models/interfaces";
Expand Down
Loading
Loading