Skip to content

Commit

Permalink
Replace 'any' with correct types in typescript code (#85) (#3279)
Browse files Browse the repository at this point in the history
* Replace 'any' with correct types in typescript code
* Replace 'any' with correct types in typescript code (complex cases)
* Fix tags not being shown
* Add missing packageManager prop to install.json file

Signed-off-by: Guilherme Caponetto <[email protected]>
  • Loading branch information
caponetto authored Jan 15, 2025
1 parent 3ecdfe8 commit 381e711
Show file tree
Hide file tree
Showing 66 changed files with 1,429 additions and 889 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@typescript-eslint/no-unused-vars": ["warn", { "args": "none" }],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-namespace": "off",
"header/header": [
Expand Down
8 changes: 4 additions & 4 deletions binder/postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ set -x

# repo2docker clones the Elyra repository before the Docker image is built
# and uses the cloned directory as "root". The git extension recognizes that
# the directory is git-enabled and therefore prevents the user from
# the directory is git-enabled and therefore prevents the user from
# cloning other repositories using the UI. Remove the git artifacts in the
# root directory to work around this issue.
# root directory to work around this issue.
rm -rf ~/.git*

# Add getting started assets to Docker image
# (1) Clone the examples repository.
git clone https://github.com/elyra-ai/examples.git
git clone https://github.com/elyra-ai/examples.git

EXAMPLES_BASE_DIR=examples

# (2) Copy all getting started assets to the working directory,
# which is referenced when binder is invoked, e.g.
# which is referenced when binder is invoked, e.g.
# https://mybinder.org/v2/gh/elyra-ai/elyra/main?urlpath=lab/tree/binder-demo
cp -r $EXAMPLES_BASE_DIR/binder/getting-started/* binder-demo/

Expand Down
14 changes: 10 additions & 4 deletions cypress/tests/codesnippet.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ describe('Code Snippet tests', () => {
const updatedSnippetItem = getSnippetByName(newSnippetName);

// Check old snippet name does not exist
expect(updatedSnippetItem.innerText).not.to.eq(snippetName);
updatedSnippetItem.then((element) => {
expect(element.text()).not.to.eq(snippetName);
});

// Delete updated code snippet
deleteSnippet(newSnippetName);
Expand Down Expand Up @@ -354,11 +356,13 @@ const openCodeSnippetExtension = (): void => {
cy.get('.jp-SideBar .lm-mod-current[title="Code Snippets"]');
};

const getSnippetByName = (snippetName: string): any => {
const getSnippetByName = (
snippetName: string
): Cypress.Chainable<JQuery<HTMLElement>> => {
return cy.get(`[data-item-id="${snippetName}"]`);
};

const createInvalidCodeSnippet = (snippetName: string): any => {
const createInvalidCodeSnippet = (snippetName: string): void => {
clickCreateNewSnippetButton();

typeCodeSnippetName(snippetName);
Expand Down Expand Up @@ -441,7 +445,9 @@ const duplicateSnippet = (snippetName: string): void => {
item.find('button[title="Duplicate"]').click();
};

const getActionButtonsElement = (snippetName: string): any => {
const getActionButtonsElement = (
snippetName: string
): Cypress.Chainable<JQuery<HTMLElement>> => {
const actionButtonsElement = getSnippetByName(snippetName).find(
'.elyra-expandableContainer-action-buttons'
);
Expand Down
2 changes: 2 additions & 0 deletions cypress/utils/snapshots/add-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ beforeEach(() => {
snapshotIndexTracker = {};
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- workaround for snapshot plugin
const getSnapshotPath = (test: any): string => {
const names = [];
for (let k = test; k; k = k.parent) {
Expand All @@ -52,6 +53,7 @@ const getSnapshotPath = (test: any): string => {
};

Cypress.Commands.add('matchesSnapshot', { prevSubject: true }, (value) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- workaround for snapshot plugin
const test = (Cypress as any).mocha.getRunner().suite.ctx.test;

const path = getSnapshotPath(test);
Expand Down
3 changes: 3 additions & 0 deletions cypress/utils/snapshots/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import fs from 'fs';

import { diffStringsUnified } from 'jest-diff';

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- workaround for snapshot plugin
const createSnapshot = (value: any): string => {
let obj = value;

Expand All @@ -35,6 +36,7 @@ const createSnapshot = (value: any): string => {

interface ISnapshotOptions {
path: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- workaround for snapshot plugin
value: any;
}

Expand All @@ -57,6 +59,7 @@ interface INewSnapshotResults {
status: 'new';
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- workaround for snapshot plugin
export const register = (on: any, _config: any): void => {
on('task', {
matchesSnapshot({ path, value }: ISnapshotOptions): ISnapshotResults {
Expand Down
1 change: 1 addition & 0 deletions packages/code-snippet/install.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"packageManager": "python",
"packageName": "elyra_code_snippet_extension",
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package elyra_code_snippet_extension"
}
17 changes: 8 additions & 9 deletions packages/code-snippet/src/CodeSnippetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@
* limitations under the License.
*/

import { IMetadata } from '@elyra/metadata-common';
import { MetadataService } from '@elyra/services';
import { IMetadataResource, MetadataService } from '@elyra/services';

import { Dialog, showDialog } from '@jupyterlab/apputils';

export const CODE_SNIPPET_SCHEMASPACE = 'code-snippets';
export const CODE_SNIPPET_SCHEMA = 'code-snippet';

export class CodeSnippetService {
static async findAll(): Promise<IMetadata[]> {
return MetadataService.getMetadata(CODE_SNIPPET_SCHEMASPACE);
static async findAll(): Promise<IMetadataResource[]> {
return (await MetadataService.getMetadata(CODE_SNIPPET_SCHEMASPACE)) ?? [];
}

// TODO: Test this function
static async findByLanguage(language: string): Promise<IMetadata[]> {
static async findByLanguage(language: string): Promise<IMetadataResource[]> {
try {
const allCodeSnippets: IMetadata[] = await this.findAll();
const codeSnippetsByLanguage: IMetadata[] = [];
const allCodeSnippets = await this.findAll();
const codeSnippetsByLanguage: IMetadataResource[] = [];

for (const codeSnippet of allCodeSnippets) {
if (codeSnippet.metadata.language === language) {
Expand All @@ -54,11 +53,11 @@ export class CodeSnippetService {
* @returns A boolean promise that is true if the dialog confirmed
* the deletion, and false if the deletion was cancelled.
*/
static deleteCodeSnippet(codeSnippet: IMetadata): Promise<boolean> {
static deleteCodeSnippet(codeSnippet: IMetadataResource): Promise<boolean> {
return showDialog({
title: `Delete snippet '${codeSnippet.display_name}'?`,
buttons: [Dialog.cancelButton(), Dialog.okButton()]
}).then((result: any) => {
}).then((result) => {
// Do nothing if the cancel button is pressed
if (result.button.accept) {
return MetadataService.deleteMetadata(
Expand Down
Loading

0 comments on commit 381e711

Please sign in to comment.