mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: fix imports for error-boundary and error-boundary
Signed-off-by: Gabriel <gaccettola@mirantis.com>
This commit is contained in:
parent
2d315ec616
commit
9af5159706
6
package-lock.json
generated
6
package-lock.json
generated
@ -37220,7 +37220,10 @@
|
|||||||
"version": "1.0.0-alpha.0",
|
"version": "1.0.0-alpha.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ogre-tools/injectable-react": "12.0.1"
|
"@ogre-tools/injectable": "^15.3.1",
|
||||||
|
"@ogre-tools/injectable-react": "12.0.1",
|
||||||
|
"history": "^4.10.1",
|
||||||
|
"mobx-observable-history": "^2.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@async-fn/jest": "^1.6.4",
|
"@async-fn/jest": "^1.6.4",
|
||||||
@ -37230,6 +37233,7 @@
|
|||||||
"@testing-library/user-event": "^12.8.3"
|
"@testing-library/user-event": "^12.8.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
"@k8slens/button": "^1.0.0-alpha.1",
|
||||||
"@k8slens/utilities": "^1.0.0-alpha.1",
|
"@k8slens/utilities": "^1.0.0-alpha.1",
|
||||||
"auto-bind": "^4.0.0",
|
"auto-bind": "^4.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|||||||
6
packages/ui-components/error-boundary/.eslintrc.json
Normal file
6
packages/ui-components/error-boundary/.eslintrc.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "@k8slens/eslint-config/eslint",
|
||||||
|
"parserOptions": {
|
||||||
|
"project": "./tsconfig.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
packages/ui-components/error-boundary/.swcrc
Normal file
19
packages/ui-components/error-boundary/.swcrc
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"module": {
|
||||||
|
"type": "commonjs"
|
||||||
|
},
|
||||||
|
"jsc": {
|
||||||
|
"parser": {
|
||||||
|
"syntax": "typescript",
|
||||||
|
"tsx": true,
|
||||||
|
"decorators": true,
|
||||||
|
"dynamicImport": false
|
||||||
|
},
|
||||||
|
"transform": {
|
||||||
|
"legacyDecorator": true,
|
||||||
|
"decoratorMetadata": true
|
||||||
|
},
|
||||||
|
"target": "es2019"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,2 +1 @@
|
|||||||
export * from "./src/error-boundary";
|
export * from "./src/error-boundary";
|
||||||
export * from "./src/withTooltip";
|
|
||||||
@ -25,14 +25,17 @@
|
|||||||
"homepage": "https://github.com/lensapp/lens",
|
"homepage": "https://github.com/lensapp/lens",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack",
|
"build": "webpack",
|
||||||
"test:unit": "jest --coverage --runInBand",
|
|
||||||
"lint": "lens-lint",
|
"lint": "lens-lint",
|
||||||
"lint:fix": "lens-lint --fix"
|
"lint:fix": "lens-lint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ogre-tools/injectable-react": "12.0.1"
|
"@ogre-tools/injectable": "^15.3.1",
|
||||||
|
"@ogre-tools/injectable-react": "12.0.1",
|
||||||
|
"history": "^4.10.1",
|
||||||
|
"mobx-observable-history": "^2.0.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
"@k8slens/button": "^1.0.0-alpha.1",
|
||||||
"@k8slens/utilities": "^1.0.0-alpha.1",
|
"@k8slens/utilities": "^1.0.0-alpha.1",
|
||||||
"auto-bind": "^4.0.0",
|
"auto-bind": "^4.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
.ErrorBoundary {
|
.ErrorBoundary {
|
||||||
--flex-gap: #{$padding * 2};
|
--flex-gap: #{8px * 2};
|
||||||
|
|
||||||
padding: var(--flex-gap);
|
padding: var(--flex-gap);
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
|
|||||||
@ -8,12 +8,14 @@ import "./error-boundary.scss";
|
|||||||
import type { ErrorInfo } from "react";
|
import type { ErrorInfo } from "react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { Button } from "../button";
|
import { Button } from "@k8slens/button";
|
||||||
import { issuesTrackerUrl, forumsUrl } from "../../../common/vars";
|
|
||||||
import type { SingleOrMany } from "@k8slens/utilities";
|
import type { SingleOrMany } from "@k8slens/utilities";
|
||||||
import type { ObservableHistory } from "mobx-observable-history";
|
import type { ObservableHistory } from "mobx-observable-history";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
|
import observableHistoryInjectable from "./routing/observable-history.injectable";
|
||||||
|
|
||||||
|
const issuesTrackerUrl = "https://github.com/lensapp/lens/issues";
|
||||||
|
const forumsUrl = "https://forums.k8slens.dev";
|
||||||
|
|
||||||
export interface ErrorBoundaryProps {
|
export interface ErrorBoundaryProps {
|
||||||
children?: SingleOrMany<React.ReactNode>;
|
children?: SingleOrMany<React.ReactNode>;
|
||||||
@ -29,7 +31,10 @@ interface Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedErrorBoundary extends React.Component<ErrorBoundaryProps & Dependencies, State> {
|
class NonInjectedErrorBoundary extends React.Component<
|
||||||
|
ErrorBoundaryProps & Dependencies,
|
||||||
|
State
|
||||||
|
> {
|
||||||
public state: State = {};
|
public state: State = {};
|
||||||
|
|
||||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||||
@ -49,24 +54,15 @@ class NonInjectedErrorBoundary extends React.Component<ErrorBoundaryProps & Depe
|
|||||||
<div className="ErrorBoundary flex column gaps">
|
<div className="ErrorBoundary flex column gaps">
|
||||||
<h5>
|
<h5>
|
||||||
{"App crash at "}
|
{"App crash at "}
|
||||||
<span className="contrast">{location.pathname}</span>
|
<span className="contrast">{window.location.pathname}</span>
|
||||||
</h5>
|
</h5>
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
{"To help us improve the product please report bugs on"}
|
{"To help us improve the product please report bugs on"}
|
||||||
<a
|
<a href={forumsUrl} rel="noreferrer" target="_blank">
|
||||||
href={forumsUrl}
|
|
||||||
rel="noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
Lens Forums
|
Lens Forums
|
||||||
</a>
|
</a>
|
||||||
{" or on our"}
|
{" or on our"}
|
||||||
<a
|
<a href={issuesTrackerUrl} rel="noreferrer" target="_blank">
|
||||||
href={issuesTrackerUrl}
|
|
||||||
rel="noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
Github
|
Github
|
||||||
</a>
|
</a>
|
||||||
{" issues tracker."}
|
{" issues tracker."}
|
||||||
@ -95,9 +91,12 @@ class NonInjectedErrorBoundary extends React.Component<ErrorBoundaryProps & Depe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ErrorBoundary = withInjectables<Dependencies, ErrorBoundaryProps>(NonInjectedErrorBoundary, {
|
export const ErrorBoundary = withInjectables<Dependencies, ErrorBoundaryProps>(
|
||||||
getProps: (di, props) => ({
|
NonInjectedErrorBoundary,
|
||||||
...props,
|
{
|
||||||
observableHistory: di.inject(observableHistoryInjectable),
|
getProps: (di, props) => ({
|
||||||
}),
|
...props,
|
||||||
});
|
observableHistory: di.inject(observableHistoryInjectable),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { createBrowserHistory } from "history";
|
||||||
|
import type { History } from "history";
|
||||||
|
|
||||||
|
const historyInjectable = getInjectable({
|
||||||
|
id: "history",
|
||||||
|
instantiate: (): History => createBrowserHistory(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default historyInjectable;
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { createObservableHistory } from "mobx-observable-history";
|
||||||
|
import { searchParamsOptions } from "./search-params";
|
||||||
|
import historyInjectable from "./history.injectable";
|
||||||
|
|
||||||
|
const observableHistoryInjectable = getInjectable({
|
||||||
|
id: "observable-history",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const history = di.inject(historyInjectable);
|
||||||
|
const navigation = createObservableHistory(history, {
|
||||||
|
searchParams: searchParamsOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
return navigation;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default observableHistoryInjectable;
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { ObservableSearchParamsOptions } from "mobx-observable-history";
|
||||||
|
|
||||||
|
export const searchParamsOptions: ObservableSearchParamsOptions = {
|
||||||
|
skipEmpty: true, // skip empty params, e.g. "?x=&y2=" will be "?y=2"
|
||||||
|
joinArrays: false, // join multiple params with same name, e.g. "?x=1&x=2" => "?x=1,2"
|
||||||
|
joinArraysWith: ",", // param values splitter, applicable only with {joinArrays:true}
|
||||||
|
};
|
||||||
6
packages/ui-components/resizing-anchor/.eslintrc.json
Normal file
6
packages/ui-components/resizing-anchor/.eslintrc.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "@k8slens/eslint-config/eslint",
|
||||||
|
"parserOptions": {
|
||||||
|
"project": "./tsconfig.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
packages/ui-components/resizing-anchor/.swcrc
Normal file
19
packages/ui-components/resizing-anchor/.swcrc
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"module": {
|
||||||
|
"type": "commonjs"
|
||||||
|
},
|
||||||
|
"jsc": {
|
||||||
|
"parser": {
|
||||||
|
"syntax": "typescript",
|
||||||
|
"tsx": true,
|
||||||
|
"decorators": true,
|
||||||
|
"dynamicImport": false
|
||||||
|
},
|
||||||
|
"transform": {
|
||||||
|
"legacyDecorator": true,
|
||||||
|
"decoratorMetadata": true
|
||||||
|
},
|
||||||
|
"target": "es2019"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -150,8 +150,11 @@ function directionDelta(P1: number, P2: number, M: number): number | false {
|
|||||||
@observer
|
@observer
|
||||||
export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
||||||
@observable lastMouseEvent?: MouseEvent;
|
@observable lastMouseEvent?: MouseEvent;
|
||||||
|
|
||||||
ref = React.createRef<HTMLDivElement>();
|
ref = React.createRef<HTMLDivElement>();
|
||||||
|
|
||||||
@observable isDragging = false;
|
@observable isDragging = false;
|
||||||
|
|
||||||
@observable wasDragging = false;
|
@observable wasDragging = false;
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@ -169,6 +172,7 @@ export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
|||||||
minExtent: 0,
|
minExtent: 0,
|
||||||
placement: ResizeSide.LEADING,
|
placement: ResizeSide.LEADING,
|
||||||
};
|
};
|
||||||
|
|
||||||
static IS_RESIZING = "resizing";
|
static IS_RESIZING = "resizing";
|
||||||
|
|
||||||
constructor(props: ResizingAnchorProps) {
|
constructor(props: ResizingAnchorProps) {
|
||||||
@ -220,11 +224,12 @@ export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
|||||||
const boundingBox = node.getBoundingClientRect();
|
const boundingBox = node.getBoundingClientRect();
|
||||||
|
|
||||||
if (this.props.direction === ResizeDirection.HORIZONTAL) {
|
if (this.props.direction === ResizeDirection.HORIZONTAL) {
|
||||||
const barX = Math.round(boundingBox.x + (boundingBox.width / 2));
|
const barX = Math.round(boundingBox.x + boundingBox.width / 2);
|
||||||
|
|
||||||
return directionDelta(from.pageX, to.pageX, barX);
|
return directionDelta(from.pageX, to.pageX, barX);
|
||||||
} else { // direction === ResizeDirection.VERTICAL
|
} else {
|
||||||
const barY = Math.round(boundingBox.y + (boundingBox.height / 2));
|
// direction === ResizeDirection.VERTICAL
|
||||||
|
const barY = Math.round(boundingBox.y + boundingBox.height / 2);
|
||||||
|
|
||||||
return directionDelta(from.pageY, to.pageY, barY);
|
return directionDelta(from.pageY, to.pageY, barY);
|
||||||
}
|
}
|
||||||
@ -254,8 +259,15 @@ export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { maxExtent, minExtent, getCurrentExtent, growthDirection } = this.props;
|
const { maxExtent, minExtent, getCurrentExtent, growthDirection } =
|
||||||
const { onDrag, onMaxExtentExceed, onMinExtentSucceed: onMinExtentSubceed, onMaxExtentSubceed, onMinExtentExceed } = this.props;
|
this.props;
|
||||||
|
const {
|
||||||
|
onDrag,
|
||||||
|
onMaxExtentExceed,
|
||||||
|
onMinExtentSucceed: onMinExtentSubceed,
|
||||||
|
onMaxExtentSubceed,
|
||||||
|
onMinExtentExceed,
|
||||||
|
} = this.props;
|
||||||
const delta = this.calculateDelta(this.lastMouseEvent, event);
|
const delta = this.calculateDelta(this.lastMouseEvent, event);
|
||||||
|
|
||||||
// always update the last mouse event
|
// always update the last mouse event
|
||||||
@ -266,8 +278,10 @@ export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const previousExtent = getCurrentExtent();
|
const previousExtent = getCurrentExtent();
|
||||||
const unboundedExtent = previousExtent + (delta * growthDirection);
|
const unboundedExtent = previousExtent + delta * growthDirection;
|
||||||
const boundedExtent = Math.round(Math.max(minExtent, Math.min(maxExtent, unboundedExtent)));
|
const boundedExtent = Math.round(
|
||||||
|
Math.max(minExtent, Math.min(maxExtent, unboundedExtent))
|
||||||
|
);
|
||||||
|
|
||||||
onDrag(boundedExtent);
|
onDrag(boundedExtent);
|
||||||
|
|
||||||
@ -292,7 +306,7 @@ export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
|||||||
this.isDragging = false;
|
this.isDragging = false;
|
||||||
this.wasDragging = true;
|
this.wasDragging = true;
|
||||||
|
|
||||||
setTimeout(() => this.wasDragging = false, 200);
|
setTimeout(() => (this.wasDragging = false), 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -301,7 +315,11 @@ export class ResizingAnchor extends React.PureComponent<ResizingAnchorProps> {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={this.ref}
|
ref={this.ref}
|
||||||
className={cssNames("ResizingAnchor", direction, placement, { disabled, resizing: this.isDragging, wasDragging: this.wasDragging })}
|
className={cssNames("ResizingAnchor", direction, placement, {
|
||||||
|
disabled,
|
||||||
|
resizing: this.isDragging,
|
||||||
|
wasDragging: this.wasDragging,
|
||||||
|
})}
|
||||||
onMouseDown={this.onDragInit}
|
onMouseDown={this.onDragInit}
|
||||||
onDoubleClick={onDoubleClick}
|
onDoubleClick={onDoubleClick}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user