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

65% Coverage with Additional Exclusions. Small refactor required #861

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .github/workflows/daily_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ jobs:
needs: [DevTests, LiveServices, BuildTests, ExampleDataCache, ExampleDataTests]
if: |
${{ needs.DevTests.result }} == 'failure' ||
${{ needs.LiveServices.result }} == 'failure' ||
${{ needs.BuildTests.result }} == 'failure' ||
${{ needs.ExampleDataCache.result }} == 'failure' ||
${{ needs.LiveServices.result }} == 'failure' ||
${{ needs.BuildTests.result }} == 'failure' ||
${{ needs.ExampleDataCache.result }} == 'failure' ||
${{ needs.ExampleDataTests.result }} == 'failure'
steps:
- name: Printout which failed
Expand Down
16 changes: 1 addition & 15 deletions src/electron/frontend/core/components/InstanceListItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class InstanceListItem extends LitElement {
declare label: string
declare status: string
declare selected: boolean
declare onRemoved?: Function

static get styles() {
return css`
Expand Down Expand Up @@ -120,7 +119,7 @@ export class InstanceListItem extends LitElement {
}
}

constructor({ label, status, selected, onRemoved, id, ...metadata } = {
constructor({ label, status, selected, id, ...metadata } = {
label: "",
status: "",
selected: false
Expand All @@ -131,7 +130,6 @@ export class InstanceListItem extends LitElement {
this.status = status;
this.selected = selected;
this.metadata = metadata
if (this.onRemoved) this.onRemoved = onRemoved;
}

#onClick () {
Expand All @@ -154,18 +152,6 @@ export class InstanceListItem extends LitElement {
>${this.label}
<div class="indicator"></div>
</span>
${this.onRemoved
? html`<nwb-button
size="small"
primary
color="gray"
@click=${this.onRemoved}
.buttonStyles=${{
padding: "7px",
}}
>x</nwb-button
>`
: ""}
</li>
`
}
Expand Down
39 changes: 6 additions & 33 deletions src/electron/frontend/core/components/InstanceManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LitElement, css, html } from "lit";
import "./Button";
import { notify } from "../dependencies";
import { notify } from "../notifications";
import { Accordion } from "./Accordion";
import { InstanceListItem } from "./InstanceListItem";
import { checkStatus } from "../validation";
Expand Down Expand Up @@ -142,7 +142,6 @@ export class InstanceManager extends LitElement {
this.header = props.header;
this.instanceType = props.instanceType ?? "Instance";
if (props.onAdded) this.onAdded = props.onAdded;
if (props.onRemoved) this.onRemoved = props.onRemoved;
if (props.onDisplay) this.onDisplay = props.onDisplay;
this.controls = props.controls ?? [];
}
Expand All @@ -157,8 +156,12 @@ export class InstanceManager extends LitElement {
} else return content;
};

getInstance(id) {
return this.#items.find((item) => item.id === id);
}

updateState = (id, state) => {
const item = this.#items.find((i) => i.id === id);
const item = this.getInstance(id);

item.status = state;

Expand All @@ -178,7 +181,6 @@ export class InstanceManager extends LitElement {
};

// onAdded = () => {}
// onRemoved = () => {}

toggleInput = (force) => {
const newInfoDiv = this.shadowRoot.querySelector("#new-info");
Expand Down Expand Up @@ -248,34 +250,6 @@ export class InstanceManager extends LitElement {
#items = [];
#info = {};

#onRemoved(ev) {
const parent = ev.target.parentNode;
const name = parent.getAttribute("data-instance");
const ogPath = name.split("/");
const path = [...ogPath];
let target = toRender;
const key = path.pop();
target = path.reduce((acc, cur) => acc[cur], target);
this.onRemoved(target[key], ogPath);
delete target[key];

if (parent.hasAttribute("selected")) {
const previous = parent.previousElementSibling?.getAttribute("data-instance");
if (previous) this.#selected = previous;
else {
const next = parent.nextElementSibling?.getAttribute("data-instance");
if (next) this.#selected = next;
else this.#selected = undefined;
}
}

// parent.remove()
// const instance = this.shadowRoot.querySelector(`div[data-instance="${name}"]`)
// instance.remove()

this.requestUpdate();
}

#hideAll(chosenInstanceElement) {
Array.from(this.shadowRoot.querySelectorAll("div[data-instance]")).forEach((instanceElement) => {
if (instanceElement !== chosenInstanceElement) instanceElement.hidden = true;
Expand Down Expand Up @@ -332,7 +306,6 @@ export class InstanceManager extends LitElement {
id: key,
label: key.split("/").pop(),
selected: key === this.#selected,
onRemoved: this.#onRemoved.bind(this),
...info,
};

Expand Down
9 changes: 5 additions & 4 deletions src/electron/frontend/core/components/JSONSchemaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { OptionalSection } from "./OptionalSection";
import { InspectorListItem } from "./InspectorList.js";
import { renderDateTime, resolveDateTime } from "./DateTimeSelector";
import { isObject } from "../../utils/typecheck";
import { resolve } from "../../utils/promises";

const isDevelopment = !!import.meta.env;

Expand Down Expand Up @@ -583,7 +584,7 @@ export class JSONSchemaInput extends LitElement {
// onUpdate = () => {}
// onValidate = () => {}

updateData(value, forceValidate = false) {
async updateData(value, forceValidate = false) {
if (!forceValidate) {
// Update the actual input element
const inputElement = this.getElement();
Expand All @@ -603,9 +604,9 @@ export class JSONSchemaInput extends LitElement {
const name = path.splice(-1)[0];

this.#updateData(fullPath, value);
this.#triggerValidation(name, path); // NOTE: Is asynchronous
const possiblePromise = this.#triggerValidation(name, path);

return true;
return resolve(possiblePromise, () => true);
}

getElement = () => this.shadowRoot.querySelector(".schema-input");
Expand Down Expand Up @@ -641,7 +642,7 @@ export class JSONSchemaInput extends LitElement {
if (hooks.willTimeout !== false) this.#activateTimeoutValidation(name, path, hooks);
};

#triggerValidation = async (name, path) => {
#triggerValidation = (name, path) => {
this.#clearTimeoutValidation();
return this.onValidate
? this.onValidate()
Expand Down
2 changes: 1 addition & 1 deletion src/electron/frontend/core/components/pages/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LitElement, html } from "lit";
import { run } from "../../../utils/run";
import { get, save } from "../../progress/index.js";

import { dismissNotification, notify } from "../../dependencies.js";
import { dismissNotification, notify } from "../../notifications";
import { isStorybook } from "../../globals.js";

import { mapSessions, merge } from "../../../utils/data";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { html } from "lit";
import { contact_lottie } from "../../../../assets/lotties/contact-us-lotties.js";
import { Page } from "../Page.js";

import { startLottie } from "../../../dependencies.js";
import { startLottie } from "../../../lotties";

export class ContactPage extends Page {
header = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { html } from "lit";
import { docu_lottie } from "../../../../assets/lotties/documentation-lotties.js";
import { Page } from "../Page.js";

import { startLottie } from "../../../dependencies.js";
import { startLottie } from "../../../lotties";

import { Button } from "../../Button.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { html } from "lit";
import { Page } from "../Page.js";
import { ProgressCard } from "./ProgressCard.js";

import { startLottie } from "../../../dependencies.js";
import { startLottie } from "../../../lotties";
import * as progress from "../../../progress/index.js";
import { newDataset } from "../../../../assets/lotties/index.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Button } from "../../Button.js";
import { global, remove, save } from "../../../progress/index.js";
import { merge, setUndefinedIfNotDeclared } from "../../../../utils/data";

import { notyf } from "../../../dependencies.js";
import { notyf } from "../../../notifications";
import { homeDirectory, testDataFolderPath } from "../../../globals.js";

import { SERVER_FILE_PATH, electron, path, port, fs } from "../../../../utils/electron";
Expand Down
3 changes: 1 addition & 2 deletions src/electron/frontend/core/components/table/Cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ export class TableCell extends LitElement {

if (!this.editable) return // Don't set value if not editable

if (this.input) this.input.set(value) // Ensure all operations are undoable
if (this.input) return this.input.set(value) // Ensure all operations are undoable
else this.#value = value // Silently set value if not rendered yet

}

#value
Expand Down
2 changes: 1 addition & 1 deletion src/electron/frontend/core/errors.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { notify } from './dependencies'
import { notify } from './notifications'
export const onThrow = (message: string, id?: string) => notify(id ? `<b>[${id}]</b>: ${message}` : message, "error", 7000);
2 changes: 1 addition & 1 deletion src/electron/frontend/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Dashboard } from './components/Dashboard.js'
import {
notyf,
notify
} from './dependencies.js'
} from './notifications'

import Swal from 'sweetalert2'
import { loadServerEvents, pythonServerOpened } from "./server/index.js";
Expand Down
19 changes: 19 additions & 0 deletions src/electron/frontend/core/lotties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import lottie from "lottie-web";

import checkChromatic from "chromatic/isChromatic";
export const isChromatic = checkChromatic();

export const startLottie = (lottieElement: HTMLElement, animationData: any) => {
lottieElement.innerHTML = "";
const thisLottie = lottie.loadAnimation({
container: lottieElement,
animationData,
renderer: "svg",
loop: !isChromatic,
autoplay: !isChromatic,
});

if (isChromatic) thisLottie.goToAndStop(thisLottie.getDuration(true) - 1, true); // Go to last frame

return thisLottie;
};
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
import { Notyf } from "notyf";
import checkChromatic from "chromatic/isChromatic";
import lottie from "lottie-web";

// ---------- Lottie Helper ----------
const isChromatic = checkChromatic();

export const startLottie = (lottieElement, animationData) => {
lottieElement.innerHTML = "";
const thisLottie = lottie.loadAnimation({
container: lottieElement,
animationData,
renderer: "svg",
loop: !isChromatic,
autoplay: !isChromatic,
});

if (isChromatic) thisLottie.goToAndStop(thisLottie.getDuration(true) - 1, true); // Go to last frame

return thisLottie;
};

const longDuration = 20000;

Expand Down
2 changes: 1 addition & 1 deletion src/electron/frontend/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isTestEnvironment } from '../globals.js'

import {
notyf,
} from '../dependencies.js'
} from '../notifications'

import Swal from 'sweetalert2'

Expand Down
10 changes: 8 additions & 2 deletions src/electron/frontend/utils/random.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

export const getRandomIndex = (count: number) => Math.floor(count * Math.random());

export const getRandomString = () => Math.random().toString(36).substring(7);
// return random string always of len characters
export const getRandomString = (len = 7) => {
let result = "";
for (let i = 0; i < len; i++) result += chars.charAt(Math.floor(Math.random() * chars.length));
return result;
}

export const getRandomSample = (
array: any[],
Expand All @@ -18,4 +24,4 @@ export const getRandomSample = (
result.push(element);
}
return result;
};
};
Loading
Loading