Skip to content

Commit

Permalink
Merge pull request #2635 from plotly/optim/refact
Browse files Browse the repository at this point in the history
Refactors
  • Loading branch information
T4rk1n committed Sep 28, 2023
2 parents 6eaf2e1 + 8ae9488 commit d9b8d17
Show file tree
Hide file tree
Showing 28 changed files with 923 additions and 702 deletions.
18 changes: 16 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
orbs:
win: circleci/[email protected]
percy: percy/[email protected]
browser-tools: circleci/[email protected].3
browser-tools: circleci/[email protected].6

jobs:
artifacts:
Expand Down Expand Up @@ -102,11 +102,13 @@ jobs:

steps:
- checkout
- run: sudo apt-get update
- run: echo $PYVERSION > ver.txt
- run: cat requires-*.txt > requires-all.txt
- restore_cache:
key: dep-{{ checksum ".circleci/config.yml" }}-{{ checksum "ver.txt" }}-{{ checksum "requires-all.txt" }}
- browser-tools/install-browser-tools
- browser-tools/install-browser-tools:
chrome-version: 116.0.5845.110
- run:
name: ️️🏗️ pip dev requirements
command: |
Expand Down Expand Up @@ -176,11 +178,13 @@ jobs:
steps:
- checkout:
path: ~/dash
- run: sudo apt-get update
- run: echo $PYVERSION > ver.txt
- run: cat requires-*.txt > requires-all.txt
- restore_cache:
key: dep-{{ checksum ".circleci/config.yml" }}-{{ checksum "ver.txt" }}-{{ checksum "requires-all.txt" }}
- browser-tools/install-browser-tools:
chrome-version: 116.0.5845.110
install-firefox: false
install-geckodriver: false
- attach_workspace:
Expand Down Expand Up @@ -291,11 +295,13 @@ jobs:
steps:
- checkout:
path: ~/dash
- run: sudo apt-get update
- run: echo $PYVERSION > ver.txt
- run: cat requires-*.txt > requires-all.txt
- restore_cache:
key: dep-{{ checksum ".circleci/config.yml" }}-{{ checksum "ver.txt" }}-{{ checksum "requires-all.txt" }}
- browser-tools/install-browser-tools:
chrome-version: 116.0.5845.110
install-firefox: false
install-geckodriver: false
- attach_workspace:
Expand Down Expand Up @@ -358,13 +364,15 @@ jobs:
steps:
- checkout:
path: ~/dash
- run: sudo apt-get update
- run: echo $PYVERSION > ver.txt
- run: cat requires-*.txt > requires-all.txt
- restore_cache:
key: dep-{{ checksum ".circleci/config.yml" }}-{{ checksum "ver.txt" }}-{{ checksum "requires-all.txt" }}
- restore_cache:
key: html-{{ checksum "components/dash-html-components/package.json" }}-{{ checksum "components/dash-html-components/package-lock.json" }}
- browser-tools/install-browser-tools:
chrome-version: 116.0.5845.110
install-firefox: false
install-geckodriver: false
- attach_workspace:
Expand Down Expand Up @@ -432,11 +440,13 @@ jobs:
steps:
- checkout:
path: ~/dash
- run: sudo apt-get update
- run: echo $PYVERSION > ver.txt
- run: cat requires-*.txt > requires-all.txt
- restore_cache:
key: dep-{{ checksum ".circleci/config.yml" }}-{{ checksum "ver.txt" }}-{{ checksum "requires-all.txt" }}
- browser-tools/install-browser-tools:
chrome-version: 116.0.5845.110
install-firefox: false
install-geckodriver: false
- attach_workspace:
Expand Down Expand Up @@ -484,13 +494,15 @@ jobs:
steps:
- checkout:
path: ~/dash
- run: sudo apt-get update
- run: echo $PYVERSION > ver.txt
- run: cat requires-*.txt > requires-all.txt
- restore_cache:
key: dep-{{ checksum ".circleci/config.yml" }}-{{ checksum "ver.txt" }}-{{ checksum "requires-all.txt" }}
- restore_cache:
key: table-{{ checksum "components/dash-table/package.json" }}-{{ checksum "components/dash-table/package-lock.json" }}
- browser-tools/install-browser-tools:
chrome-version: 116.0.5845.110
install-firefox: false
install-geckodriver: false
- attach_workspace:
Expand Down Expand Up @@ -524,9 +536,11 @@ jobs:
steps:
- checkout:
path: ~/dash
- run: sudo apt-get update
- restore_cache:
key: dep-{{ .Branch }}-{{ checksum "package-lock.json" }}-{{ checksum "package.json" }}
- browser-tools/install-browser-tools:
chrome-version: 116.0.5845.110
install-firefox: false
install-geckodriver: false
- run:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- [#2634](https://github.com/plotly/dash/pull/2634) Fix deprecation warning on pkg_resources, fix [#2631](https://github.com/plotly/dash/issues/2631)

## Changed

- [#2635](https://github.com/plotly/dash/pull/2635) Get proper app module name, remove need to give `__name__` to Dash constructor.

## [2.13.0] 2023-08-28
## Changed

Expand Down
44 changes: 26 additions & 18 deletions components/dash-core-components/src/components/Input.react.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isNil, omit} from 'ramda';
import {isNil, pick} from 'ramda';
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import isNumeric from 'fast-isnumeric';
Expand All @@ -9,6 +9,30 @@ const convert = val => (isNumeric(val) ? +val : NaN);

const isEquivalent = (v1, v2) => v1 === v2 || (isNaN(v1) && isNaN(v2));

const inputProps = [
'type',
'placeholder',
'inputMode',
'autoComplete',
'readOnly',
'required',
'autoFocus',
'disabled',
'list',
'multiple',
'spellCheck',
'name',
'min',
'max',
'step',
'minLength',
'maxLength',
'pattern',
'size',
'style',
'id',
];

/**
* A basic HTML input control for entering text, numbers, or passwords.
*
Expand Down Expand Up @@ -84,23 +108,7 @@ export default class Input extends PureComponent {
onChange={this.onChange}
onKeyPress={this.onKeyPress}
{...valprops}
{...omit(
[
'className',
'debounce',
'value',
'n_blur',
'n_blur_timestamp',
'n_submit',
'n_submit_timestamp',
'selectionDirection',
'selectionEnd',
'selectionStart',
'setProps',
'loading_state',
],
this.props
)}
{...pick(inputProps, this.props)}
/>
);
}
Expand Down
32 changes: 30 additions & 2 deletions components/dash-core-components/src/components/Textarea.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {omit} from 'ramda';
import {pick} from 'ramda';

const textAreaProps = [
'id',
'autoFocus',
'cols',
'disabled',
'form',
'maxLength',
'minLength',
'name',
'placeholder',
'readOnly',
'required',
'rows',
'wrap',
'accessKey',
'className',
'contentEditable',
'contextMenu',
'dir',
'draggable',
'hidden',
'lang',
'spellCheck',
'style',
'tabIndex',
'title',
];

/**
* A basic HTML textarea for entering multiline text.
Expand Down Expand Up @@ -31,7 +59,7 @@ export default class Textarea extends Component {
n_clicks_timestamp: Date.now(),
});
}}
{...omit(['setProps', 'value'], this.props)}
{...pick(textAreaProps, this.props)}
/>
);
}
Expand Down
30 changes: 16 additions & 14 deletions components/dash-core-components/src/fragments/RangeSlider.react.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Component} from 'react';
import {assoc, omit, isNil} from 'ramda';
import {assoc, pick, isNil} from 'ramda';
import {Range, createSliderWithTooltip} from 'rc-slider';
import computeSliderStyle from '../utils/computeSliderStyle';

Expand All @@ -12,6 +12,20 @@ import {
} from '../utils/computeSliderMarkers';
import {propTypes, defaultProps} from '../components/RangeSlider.react';

const sliderProps = [
'min',
'max',
'allowCross',
'pushable',
'disabled',
'count',
'dots',
'included',
'tooltip',
'vertical',
'id',
];

export default class RangeSlider extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -112,19 +126,7 @@ export default class RangeSlider extends Component {
? null
: calcStep(min, max, step)
}
{...omit(
[
'className',
'value',
'drag_value',
'setProps',
'marks',
'updatemode',
'verticalHeight',
'step',
],
this.props
)}
{...pick(sliderProps, this.props)}
/>
</div>
);
Expand Down
27 changes: 13 additions & 14 deletions components/dash-core-components/src/fragments/Slider.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';
import ReactSlider, {createSliderWithTooltip} from 'rc-slider';
import {assoc, isNil, omit} from 'ramda';
import {assoc, isNil, pick} from 'ramda';
import computeSliderStyle from '../utils/computeSliderStyle';

import 'rc-slider/assets/index.css';
Expand All @@ -12,6 +12,17 @@ import {
} from '../utils/computeSliderMarkers';
import {propTypes, defaultProps} from '../components/Slider.react';

const sliderProps = [
'min',
'max',
'disabled',
'dots',
'included',
'tooltip',
'vertical',
'id',
];

/**
* A slider component with a single handle.
*/
Expand Down Expand Up @@ -115,19 +126,7 @@ export default class Slider extends Component {
? null
: calcStep(min, max, step)
}
{...omit(
[
'className',
'setProps',
'updatemode',
'value',
'drag_value',
'marks',
'verticalHeight',
'step',
],
this.props
)}
{...pick(sliderProps, this.props)}
/>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import secrets
import string
import inspect
from html import escape
from functools import wraps
from typing import Union
Expand Down Expand Up @@ -281,3 +282,12 @@ def hooks_to_js_object(hooks: Union[RendererHooks, None]) -> str:

def parse_version(version):
return tuple(int(s) for s in version.split("."))


def get_caller_name(name: str):
stack = inspect.stack()
for s in stack:
for code in s.code_context:
if f"{name}(" in code:
return s.frame.f_locals.get("__name__", "__main__")
return "__main__"
Loading

0 comments on commit d9b8d17

Please sign in to comment.