mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Compare commits
279 Commits
choropleth
...
ts-migrate
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d1cd87a5c | ||
|
|
14e51da97a | ||
|
|
6b3f1f9e27 | ||
|
|
cbd51a896a | ||
|
|
0bf15ed559 | ||
|
|
79591657e0 | ||
|
|
b7ab070b62 | ||
|
|
6d86312d6f | ||
|
|
b0ec7a25d2 | ||
|
|
13dead75fa | ||
|
|
d0793c4ba8 | ||
|
|
7b8bcdf356 | ||
|
|
c290864ccd | ||
|
|
b70e95a323 | ||
|
|
18ee5343aa | ||
|
|
fdf636a393 | ||
|
|
88c13868a3 | ||
|
|
aab11dc79b | ||
|
|
00c77cf36e | ||
|
|
6e2631dec2 | ||
|
|
4b88959341 | ||
|
|
fa2b57a209 | ||
|
|
132fed64b3 | ||
|
|
fa7ecca485 | ||
|
|
8f484706b1 | ||
|
|
e2e8714155 | ||
|
|
c6bf8a1c55 | ||
|
|
12f71925c2 | ||
|
|
cae088f35b | ||
|
|
a3c79f26b9 | ||
|
|
c7c92a3192 | ||
|
|
55cf17aa47 | ||
|
|
8dd76a00c5 | ||
|
|
e242ac2b10 | ||
|
|
66463aedd4 | ||
|
|
8a6524c1ba | ||
|
|
9097feb100 | ||
|
|
db4e97fa6f | ||
|
|
0d4615a482 | ||
|
|
ff008a076b | ||
|
|
8d548ecbac | ||
|
|
2992c382d1 | ||
|
|
f4dcb2918a | ||
|
|
c821cab4cb | ||
|
|
4fb77867b0 | ||
|
|
a473611cb0 | ||
|
|
210008c714 | ||
|
|
aa5d4f5f4e | ||
|
|
6b811c5245 | ||
|
|
83726da48a | ||
|
|
72dc157bbe | ||
|
|
1b8ff8e810 | ||
|
|
31ddd0fb79 | ||
|
|
5cabf7a724 | ||
|
|
59b135ace7 | ||
|
|
32b41e4112 | ||
|
|
2e31b91054 | ||
|
|
205915e6db | ||
|
|
b7c245f925 | ||
|
|
681b2f1abd | ||
|
|
a31196aef8 | ||
|
|
596e5bee3a | ||
|
|
84d516bfd1 | ||
|
|
2cc3bd3d54 | ||
|
|
ac652c20bf | ||
|
|
1bc6cd8f41 | ||
|
|
4c70b5ce8e | ||
|
|
de052ff02b | ||
|
|
a596d6558c | ||
|
|
fc71acdc09 | ||
|
|
b326d36ae8 | ||
|
|
378cc57d42 | ||
|
|
83c6a6bcd2 | ||
|
|
5afd0554d0 | ||
|
|
eb603f63f0 | ||
|
|
6c00f7c4e3 | ||
|
|
f56f4c4899 | ||
|
|
d3b639a68a | ||
|
|
3332b656ac | ||
|
|
24c95379ca | ||
|
|
93b4be672f | ||
|
|
f3a47a9658 | ||
|
|
7804dfd68e | ||
|
|
2dacd08bea | ||
|
|
fd76a2ecfb | ||
|
|
7f98d7b694 | ||
|
|
a1255b4144 | ||
|
|
6c349ea70a | ||
|
|
95c28c47ad | ||
|
|
48924de700 | ||
|
|
41a691328a | ||
|
|
cb97364771 | ||
|
|
d12691dc2a | ||
|
|
6f9e79c641 | ||
|
|
461f98bbfc | ||
|
|
81e7c72d48 | ||
|
|
328f0f3f0c | ||
|
|
ecb9adf903 | ||
|
|
87e09f676e | ||
|
|
6fc5c803e0 | ||
|
|
6c57aa448e | ||
|
|
878b297601 | ||
|
|
9c0450c84e | ||
|
|
74f206614f | ||
|
|
2f26cf791c | ||
|
|
c6be5758ad | ||
|
|
8341592b05 | ||
|
|
a7edbf1e8d | ||
|
|
217f41b586 | ||
|
|
a8bd07e293 | ||
|
|
332c16b130 | ||
|
|
7940d36616 | ||
|
|
68b70ed63b | ||
|
|
e0297835df | ||
|
|
004bc7a2ac | ||
|
|
efcf22079f | ||
|
|
a83cb18cc5 | ||
|
|
1ecdf7b853 | ||
|
|
90024ebc92 | ||
|
|
a37b7babbf | ||
|
|
8f4ac958b1 | ||
|
|
637d9837f4 | ||
|
|
bdd3c3e735 | ||
|
|
6fc35510d3 | ||
|
|
6f842ef94a | ||
|
|
a563900f0a | ||
|
|
ee3930c64d | ||
|
|
10bff8b3b1 | ||
|
|
a8510d1ad5 | ||
|
|
3a543a4ab2 | ||
|
|
2b1ba1ee33 | ||
|
|
4a54ad9d06 | ||
|
|
676f560830 | ||
|
|
98a5154345 | ||
|
|
4c324ddc80 | ||
|
|
05c2233782 | ||
|
|
0ac24e38a1 | ||
|
|
d036df0ca1 | ||
|
|
56df870f39 | ||
|
|
05540164e1 | ||
|
|
bdb62365b1 | ||
|
|
6a12168f40 | ||
|
|
ac0b494953 | ||
|
|
77e8d70a64 | ||
|
|
8597b727a7 | ||
|
|
e233611840 | ||
|
|
dd6098d405 | ||
|
|
d38d3b6b4d | ||
|
|
100c7be5e0 | ||
|
|
733bc1c109 | ||
|
|
19cc7f1be8 | ||
|
|
43e5c2aa11 | ||
|
|
376b317e2e | ||
|
|
d550427485 | ||
|
|
d1044c1963 | ||
|
|
46e18b0c6f | ||
|
|
38dd3ff248 | ||
|
|
6bac19c1e4 | ||
|
|
ce6bc2d64a | ||
|
|
27c4992003 | ||
|
|
13e454de86 | ||
|
|
f4c9d7db1a | ||
|
|
0d11d7bec2 | ||
|
|
ec68e8bba3 | ||
|
|
831512e52d | ||
|
|
dfc873fb8b | ||
|
|
b117485571 | ||
|
|
3661d6cbc5 | ||
|
|
a2217cc4ec | ||
|
|
a7ea94f69a | ||
|
|
8010781f0d | ||
|
|
7c8874b8ee | ||
|
|
8907a86e33 | ||
|
|
22f0030864 | ||
|
|
baf16d2501 | ||
|
|
0446080d3f | ||
|
|
a8a2964cb0 | ||
|
|
9562718a6a | ||
|
|
e470347d7f | ||
|
|
76aeab02eb | ||
|
|
9568c74fd0 | ||
|
|
57287b2c0b | ||
|
|
6d857588a1 | ||
|
|
dc49585320 | ||
|
|
fc246aafc4 | ||
|
|
4f8d2caed4 | ||
|
|
27eab28405 | ||
|
|
8a9a2e7199 | ||
|
|
8d29e80013 | ||
|
|
0e3d25c40c | ||
|
|
fdc4205774 | ||
|
|
873c87b4b3 | ||
|
|
ae9bbe25e5 | ||
|
|
e3fff396cb | ||
|
|
f37e3d5a10 | ||
|
|
45e1478be3 | ||
|
|
2c90d920b3 | ||
|
|
bb767f3747 | ||
|
|
60bc1f8e35 | ||
|
|
de6d665c6e | ||
|
|
60f92a2efc | ||
|
|
ea8a075a2d | ||
|
|
6ee9b43ef9 | ||
|
|
cfc82156c2 | ||
|
|
ab6dc51540 | ||
|
|
70186ab835 | ||
|
|
e99c37a36a | ||
|
|
de40f1a07b | ||
|
|
2c1eb5c10d | ||
|
|
02cf895983 | ||
|
|
940bd564d7 | ||
|
|
9ba57a9491 | ||
|
|
b80abd11fb | ||
|
|
1d4ca5cf2e | ||
|
|
f7df6e0cdc | ||
|
|
3df1a86d66 | ||
|
|
bad1294402 | ||
|
|
3d26afef16 | ||
|
|
2d29240195 | ||
|
|
c698359cb8 | ||
|
|
2b3d9053e9 | ||
|
|
45ea5171cb | ||
|
|
6a5445b726 | ||
|
|
51b573230f | ||
|
|
54b04eaff7 | ||
|
|
1e96faed3b | ||
|
|
90bfba57d4 | ||
|
|
7f2a0af841 | ||
|
|
f9e3ac7534 | ||
|
|
4d266176d0 | ||
|
|
3373cfc1eb | ||
|
|
e3745f8ba3 | ||
|
|
3f6699032f | ||
|
|
adf8b2e42b | ||
|
|
8db1612689 | ||
|
|
fabaf73b7b | ||
|
|
45914f941f | ||
|
|
1e9b8f1126 | ||
|
|
52911b7be3 | ||
|
|
a10a3f1731 | ||
|
|
33131c1354 | ||
|
|
f6750428cf | ||
|
|
f4b69d4495 | ||
|
|
db71ff399c | ||
|
|
e552effd96 | ||
|
|
75cc6b3f53 | ||
|
|
bf3095c794 | ||
|
|
ee6dcab362 | ||
|
|
e0312fb717 | ||
|
|
791a0b3ec7 | ||
|
|
e03e58c5c7 | ||
|
|
78201c6108 | ||
|
|
d687befa59 | ||
|
|
9635d00476 | ||
|
|
418590003e | ||
|
|
3650f0c45b | ||
|
|
668403c126 | ||
|
|
4b94a5c88f | ||
|
|
a9cb87d4b3 | ||
|
|
b0f1cdd194 | ||
|
|
5d533a3277 | ||
|
|
5fa5cd958b | ||
|
|
c5f14e5538 | ||
|
|
7043951f00 | ||
|
|
9790b0731d | ||
|
|
3102e2df94 | ||
|
|
35250d64b9 | ||
|
|
cdfa102125 | ||
|
|
209ee16261 | ||
|
|
f1a2f8cb88 | ||
|
|
dd8e23040a | ||
|
|
d2cc2d20b6 | ||
|
|
7f8b103aea | ||
|
|
9eaa44da4a | ||
|
|
2833bb539f | ||
|
|
7ff5af1bf5 | ||
|
|
7124bc91d7 | ||
|
|
abbfd598d7 | ||
|
|
545da898ee |
@@ -1,12 +1,12 @@
|
||||
FROM cypress/browsers:chrome67
|
||||
FROM cypress/browsers:node14.0.0-chrome84
|
||||
|
||||
ENV APP /usr/src/app
|
||||
WORKDIR $APP
|
||||
|
||||
COPY package.json $APP/package.json
|
||||
RUN npm run cypress:install > /dev/null
|
||||
COPY package.json package-lock.json $APP/
|
||||
COPY viz-lib $APP/viz-lib
|
||||
RUN npm ci > /dev/null
|
||||
|
||||
COPY client/cypress $APP/client/cypress
|
||||
COPY cypress.json $APP/cypress.json
|
||||
COPY . $APP
|
||||
|
||||
RUN ./node_modules/.bin/cypress verify
|
||||
|
||||
@@ -2,10 +2,11 @@ version: 2.0
|
||||
|
||||
build-docker-image-job: &build-docker-image-job
|
||||
docker:
|
||||
- image: circleci/node:8
|
||||
- image: circleci/node:12
|
||||
steps:
|
||||
- setup_remote_docker
|
||||
- checkout
|
||||
- run: sudo apt update
|
||||
- run: sudo apt install python3-pip
|
||||
- run: sudo pip3 install -r requirements_bundles.txt
|
||||
- run: .circleci/update_version
|
||||
@@ -32,7 +33,7 @@ jobs:
|
||||
name: Build Docker Images
|
||||
command: |
|
||||
set -x
|
||||
docker-compose build --build-arg skip_ds_deps=true
|
||||
docker-compose build --build-arg skip_ds_deps=true --build-arg skip_frontend_build=true
|
||||
docker-compose up -d
|
||||
sleep 10
|
||||
- run:
|
||||
@@ -56,25 +57,37 @@ jobs:
|
||||
- store_artifacts:
|
||||
path: coverage.xml
|
||||
frontend-lint:
|
||||
environment:
|
||||
CYPRESS_INSTALL_BINARY: 0
|
||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
|
||||
docker:
|
||||
- image: circleci/node:8
|
||||
- image: circleci/node:12
|
||||
steps:
|
||||
- checkout
|
||||
- run: mkdir -p /tmp/test-results/eslint
|
||||
- run: npm install
|
||||
- run: npm ci
|
||||
- run: npm run lint:ci
|
||||
- store_test_results:
|
||||
path: /tmp/test-results
|
||||
frontend-unit-tests:
|
||||
environment:
|
||||
CYPRESS_INSTALL_BINARY: 0
|
||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
|
||||
docker:
|
||||
- image: circleci/node:8
|
||||
- image: circleci/node:12
|
||||
steps:
|
||||
- checkout
|
||||
- run: sudo apt update
|
||||
- run: sudo apt install python3-pip
|
||||
- run: sudo pip3 install -r requirements_bundles.txt
|
||||
- run: npm install
|
||||
- run: npm ci
|
||||
- run: npm run bundle
|
||||
- run: npm test
|
||||
- run:
|
||||
name: Run App Tests
|
||||
command: npm test
|
||||
- run:
|
||||
name: Run Visualizations Tests
|
||||
command: (cd viz-lib && npm test)
|
||||
- run: npm run lint
|
||||
frontend-e2e-tests:
|
||||
environment:
|
||||
@@ -83,23 +96,45 @@ jobs:
|
||||
PERCY_TOKEN_ENCODED: ZGRiY2ZmZDQ0OTdjMzM5ZWE0ZGQzNTZiOWNkMDRjOTk4Zjg0ZjMxMWRmMDZiM2RjOTYxNDZhOGExMjI4ZDE3MA==
|
||||
CYPRESS_PROJECT_ID_ENCODED: OTI0Y2th
|
||||
CYPRESS_RECORD_KEY_ENCODED: YzA1OTIxMTUtYTA1Yy00NzQ2LWEyMDMtZmZjMDgwZGI2ODgx
|
||||
CYPRESS_INSTALL_BINARY: 0
|
||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
|
||||
docker:
|
||||
- image: circleci/node:8
|
||||
- image: circleci/node:12
|
||||
steps:
|
||||
- setup_remote_docker
|
||||
- checkout
|
||||
- run:
|
||||
name: Enable Code Coverage report for master branch
|
||||
command: |
|
||||
if [ "$CIRCLE_BRANCH" = "master" ]; then
|
||||
echo 'export CODE_COVERAGE=true' >> $BASH_ENV
|
||||
source $BASH_ENV
|
||||
fi
|
||||
- run:
|
||||
name: Install npm dependencies
|
||||
command: |
|
||||
npm install
|
||||
npm ci
|
||||
- run:
|
||||
name: Setup Redash server
|
||||
command: |
|
||||
npm run cypress start
|
||||
npm run cypress build
|
||||
npm run cypress start -- --skip-db-seed
|
||||
docker-compose run cypress npm run cypress db-seed
|
||||
- run:
|
||||
name: Execute Cypress tests
|
||||
command: npm run cypress run-ci
|
||||
- run:
|
||||
name: "Failure: output container logs to console"
|
||||
command: |
|
||||
docker-compose logs
|
||||
when: on_fail
|
||||
- run:
|
||||
name: Copy Code Coverage results
|
||||
command: |
|
||||
docker cp cypress:/usr/src/app/coverage ./coverage || true
|
||||
when: always
|
||||
- store_artifacts:
|
||||
path: coverage
|
||||
build-docker-image: *build-docker-image-job
|
||||
build-preview-docker-image: *build-docker-image-job
|
||||
workflows:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
version: '3'
|
||||
version: '2.2'
|
||||
services:
|
||||
redash:
|
||||
build: ../
|
||||
|
||||
@@ -1,7 +1,20 @@
|
||||
version: '3'
|
||||
version: "2.2"
|
||||
x-redash-service: &redash-service
|
||||
build:
|
||||
context: ../
|
||||
args:
|
||||
skip_dev_deps: "true"
|
||||
skip_ds_deps: "true"
|
||||
code_coverage: ${CODE_COVERAGE}
|
||||
x-redash-environment: &redash-environment
|
||||
REDASH_LOG_LEVEL: "INFO"
|
||||
REDASH_REDIS_URL: "redis://redis:6379/0"
|
||||
REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
|
||||
REDASH_RATELIMIT_ENABLED: "false"
|
||||
REDASH_ENFORCE_CSRF: "true"
|
||||
services:
|
||||
server:
|
||||
build: ../
|
||||
<<: *redash-service
|
||||
command: server
|
||||
depends_on:
|
||||
- postgres
|
||||
@@ -9,29 +22,25 @@ services:
|
||||
ports:
|
||||
- "5000:5000"
|
||||
environment:
|
||||
<<: *redash-environment
|
||||
PYTHONUNBUFFERED: 0
|
||||
REDASH_LOG_LEVEL: "INFO"
|
||||
REDASH_REDIS_URL: "redis://redis:6379/0"
|
||||
REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
|
||||
REDASH_RATELIMIT_ENABLED: "false"
|
||||
scheduler:
|
||||
build: ../
|
||||
<<: *redash-service
|
||||
command: scheduler
|
||||
depends_on:
|
||||
- server
|
||||
environment:
|
||||
REDASH_REDIS_URL: "redis://redis:6379/0"
|
||||
<<: *redash-environment
|
||||
worker:
|
||||
build: ../
|
||||
<<: *redash-service
|
||||
command: worker
|
||||
depends_on:
|
||||
- server
|
||||
environment:
|
||||
<<: *redash-environment
|
||||
PYTHONUNBUFFERED: 0
|
||||
REDASH_LOG_LEVEL: "INFO"
|
||||
REDASH_REDIS_URL: "redis://redis:6379/0"
|
||||
REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
|
||||
cypress:
|
||||
ipc: host
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: .circleci/Dockerfile.cypress
|
||||
@@ -41,11 +50,13 @@ services:
|
||||
- scheduler
|
||||
environment:
|
||||
CYPRESS_baseUrl: "http://server:5000"
|
||||
CYPRESS_coverage: ${CODE_COVERAGE}
|
||||
PERCY_TOKEN: ${PERCY_TOKEN}
|
||||
PERCY_BRANCH: ${CIRCLE_BRANCH}
|
||||
PERCY_COMMIT: ${CIRCLE_SHA1}
|
||||
PERCY_PULL_REQUEST: ${CIRCLE_PR_NUMBER}
|
||||
COMMIT_INFO_BRANCH: ${CIRCLE_BRANCH}
|
||||
COMMIT_INFO_MESSAGE: ${COMMIT_INFO_MESSAGE}
|
||||
COMMIT_INFO_AUTHOR: ${CIRCLE_USERNAME}
|
||||
COMMIT_INFO_SHA: ${CIRCLE_SHA1}
|
||||
COMMIT_INFO_REMOTE: ${CIRCLE_REPOSITORY_URL}
|
||||
|
||||
@@ -6,11 +6,11 @@ docker login -u $DOCKER_USER -p $DOCKER_PASS
|
||||
|
||||
if [ $CIRCLE_BRANCH = master ] || [ $CIRCLE_BRANCH = preview-image ]
|
||||
then
|
||||
docker build -t redash/redash:preview -t redash/preview:$VERSION_TAG .
|
||||
docker build --build-arg skip_dev_deps=true -t redash/redash:preview -t redash/preview:$VERSION_TAG .
|
||||
docker push redash/redash:preview
|
||||
docker push redash/preview:$VERSION_TAG
|
||||
else
|
||||
docker build -t redash/redash:$VERSION_TAG .
|
||||
docker build --build-arg skip_dev_deps=true -t redash/redash:$VERSION_TAG .
|
||||
docker push redash/redash:$VERSION_TAG
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
client/.tmp/
|
||||
client/dist/
|
||||
node_modules/
|
||||
viz-lib/node_modules/
|
||||
.tmp/
|
||||
.venv/
|
||||
venv/
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,11 +5,12 @@ venv/
|
||||
.coveralls.yml
|
||||
.idea
|
||||
*.pyc
|
||||
.nyc_output
|
||||
coverage
|
||||
.coverage
|
||||
coverage.xml
|
||||
client/dist
|
||||
.DS_Store
|
||||
celerybeat-schedule*
|
||||
.#*
|
||||
\#*#
|
||||
*~
|
||||
|
||||
@@ -50,12 +50,14 @@ labels: ["Skip CI"]
|
||||
# Restylers to run, and how
|
||||
restylers:
|
||||
- name: black
|
||||
image: restyled/restyler-black:v19.10b0
|
||||
include:
|
||||
- redash
|
||||
- tests
|
||||
- migrations/versions
|
||||
- name: prettier
|
||||
image: restyled/restyler-prettier:v1.19.1-2
|
||||
include:
|
||||
- client/app/**/*.js
|
||||
- client/app/**/*.jsx
|
||||
- client/cypress/**/*.js
|
||||
- client/cypress/**/*.js
|
||||
|
||||
211
CHANGELOG.md
211
CHANGELOG.md
@@ -1,5 +1,149 @@
|
||||
# Change Log
|
||||
|
||||
## v9.0.0-beta - 2020-06-11
|
||||
|
||||
This release was long time in the making and has several major changes:
|
||||
|
||||
- Our backend code was updated to support Python 3 and we no longer support Python 2. If you're using our Docker images, this should be a transparent change for you.
|
||||
- We replaced Celery with RQ for background jobs processing. This will require some setup updates -- see instructions below.
|
||||
- The frontend code is now 100% React and we removed all the Angular dependencies.
|
||||
|
||||
This release was made possible by contributions from over 50 people: @ari-e, @ariarijp, @arihantsurana, @arikfr, @atharvai, @cemremengu, @chulucninh09, @citrin, @daniellangnet, @DavidHernandez, @deecay, @dmudro, @erans, @erels, @ezkl, @gabrieldutra, @gstaykov, @ialeinikov, @ikenji, @Jakdaw, @jezdez, @juanvasquezreyes, @koooge, @kravets-levko, @kykrueger, @leibowitz, @leosunmo, @lihan, @loganprice, @mickeey2525, @mnoorenberghe, @monicagangwar, @NicolasLM, @p-yang, @Ralnoc, @ranbena, @randyzwitch, @rauchy, @rxin, @saravananselvamohan, @satyamkrishna, @shinsuke-nara, @stefan-mees, @stevebuckingham, @susodapop, @taminif, @thewarpaint, @tsuyoshizawa, @uncletimmy3, @wengkham.
|
||||
|
||||
### Upgrading
|
||||
|
||||
Typically, if you are running your own instance of Redash and wish to upgrade, you would simply modify the Docker tag in your `docker-compose.yml` file. Since RQ has replaced Celery in this version, there are a couple extra modifications that need to be done in your `docker-compose.yml`:
|
||||
|
||||
1. Under `services/scheduler/environment`, omit `QUEUES` and `WORKERS_COUNT` (and omit `environment` altogether if it is empty).
|
||||
2. Under `services`, add a new service for general RQ jobs:
|
||||
|
||||
```yaml
|
||||
worker:
|
||||
<<: *redash-service
|
||||
command: worker
|
||||
environment:
|
||||
QUEUES: "periodic emails default"
|
||||
WORKERS_COUNT: 1
|
||||
```
|
||||
|
||||
Following that, force a recreation of your containers with `docker-compose up --force-recreate --build` and you should be good to go.
|
||||
|
||||
### UX
|
||||
|
||||
- Redesigned Query Results page:
|
||||
- Completely new layout is easier to read for non-technical Redash users.
|
||||
- Empty query results are clearly displayed. User is now prompted to edit or execute the query.
|
||||
- Mobile Experience Improvements:
|
||||
- UI element spacing has been redesigned for clarity
|
||||
- Admin pages now honor max-width. Tables scroll independent of the top menu.
|
||||
- Large legends no longer shrink the visualization on small screens.
|
||||
- Fix: it was sometimes impossible to scroll pages with dashboards because the visualizations captured every touch event.
|
||||
- Fix: Visualizations on small screens would not always show horizontal scroll bars.
|
||||
- Dashboards can now be un-archived using the API.
|
||||
- Dashboard UI performance was improved.
|
||||
- List pages were changed to show a user's name instead of avatar.
|
||||
- Search-enabled tables now show a prompt for which columns will be searched.
|
||||
- In the visualization editor, the settings pane now scrolls independent of the visualization preview.
|
||||
- Tokens in the schema viewer now sort alphabetically.
|
||||
- Links to settings panes that require Admin privileges are now hidden from non-Admins.
|
||||
- The Admin page now remembers which tab you were viewing after a page reload.
|
||||
|
||||
### Visualizations
|
||||
|
||||
- Feature: Allow bubble size control with either coefficient or sizemode.
|
||||
- Feature: Table visualization now treats Unix timestamps in query results as timestamps.
|
||||
- Feature: It's now possible to provide a description to each Table column, appearing in UI as a tooltip.
|
||||
- Feature: Added tooltip and popover templating to the map with markers visualization.
|
||||
- Feature: Added an organization setting to hide the Plotly mode bar on all visualizations.
|
||||
- Feature: Cohort visualization now has appearance settings.
|
||||
- Feature: Add option to explicitly set Chart legend position.
|
||||
- Change: Deprecated visualizations are now hidden.
|
||||
- Change: Table settings editor now extends vertically instead of horizontally.
|
||||
- Change: The maximum table pagination is now 500.
|
||||
- Change: Pie chart labels maintain contrast against lighter slices.
|
||||
- Fix: Chart series switched places when picking Y axis.
|
||||
- Fix: Third column was not selectable for Bubble and Heatmap charts.
|
||||
- Fix: On the counter visualizations, the “count rows” option showed an empty string instead of 0.
|
||||
- Fix: Table visualization with column named "children" rendered +/- buttons.
|
||||
- Fix: Sankey visualization now correctly occupies all available area even with fewer stages.
|
||||
- Fix: Pie chart ignores series labels.
|
||||
|
||||
### Data Sources
|
||||
|
||||
- New Data Sources: Amazon Cloudwatch, Amazon CloudWatch Logs Insights, Azure Kusto, Exasol.
|
||||
- Athena:
|
||||
- Added the option to specify a base cost in settings, displaying a price for each query when executed.
|
||||
- BigQuery:
|
||||
- Fix: large jobs continued running after the user clicked “Cancel” query execution.
|
||||
- Cassandra:
|
||||
- Updated driver to 3.21.0 which dramatically reduces Docker build times.
|
||||
- SSL options are now available.
|
||||
- Clickhouse:
|
||||
- You can now choose whether to verify the SSL certificate.
|
||||
- Databricks:
|
||||
- Databricks now use an ODBC-based connector.
|
||||
- Fix: Date column was coerced to DateTime in the front-end.
|
||||
- Druid:
|
||||
- Added username and password authentication option.
|
||||
- Microsoft SQL Server
|
||||
- Added support for ODBC connections via pyodbc. There are now two MSSQL data source types. One using TDS. The other is using ODBC.
|
||||
- MongoDB:
|
||||
- Added support for running queries on secondary in replicaset mode.
|
||||
- Fix: Connection test always succeeded.
|
||||
- Oracle:
|
||||
- Fix: Connection would fail if username or password contained special characters.
|
||||
- Fix: Comparisons would fail if scale was None.
|
||||
- RDS:
|
||||
- Updated rds-combined-ca-bundle.pem to the latest CA.
|
||||
- Redshift:
|
||||
- Added the ability to use IAM Roles and Users.
|
||||
- Fix: Redshift was unable to have its schema refreshed.
|
||||
- Rockset:
|
||||
- Fix: Allow Redash to load collections in all workspaces.
|
||||
- Snowflake:
|
||||
- You can now refresh the snowflake schema without waking the cluster.
|
||||
- Added support for all of Snowflake’s datetime types. Otherwise certain timestamps would only appear as strings in the front-end.
|
||||
- TreasureData:
|
||||
- Fix: API calls would fail when setting a non-default region.
|
||||
|
||||
### Alerts
|
||||
|
||||
- Feature: Added ability to mute alerts without deleting them.
|
||||
- Fix: numerical comparisons failed if value from query was a string.
|
||||
|
||||
### Parameters
|
||||
|
||||
- Added Last x Days options for date range parameters.
|
||||
- Fix: Parameters added in empty queries were always added as text parameters
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fix: Alembic migration schema was preventing v4 users from upgrading. In v5 we started encrypting data source credentials in the database.
|
||||
- Fix: System admin dashboard would not show correct database size if non-default name was used.
|
||||
- Fix: refresh_queries job would break if any query had a bad schedule object.
|
||||
- Fix: Orgs with LDAP enabled couldn’t disable password login.
|
||||
- Fix: SSL mode was sometimes sent as an empty string to the database instead of omitted entirely.
|
||||
- Fix: When creating new Map visualization with clustering disabled, map would crash on save.
|
||||
- Fix: It was possible on the New Query page to click “Save” multiple times, causing multiple new query records to be created.
|
||||
- Fix: Visualization render errors on a dashboard would crash the entire page.
|
||||
- Fix: A scheduled execution failure would modify the query’s “updated_at” timestamp.
|
||||
- Fix: Parameter UI would wrap awkwardly during some drag operations.
|
||||
- Fix: In dashboard edit mode, users couldn’t modify widgets.
|
||||
- Fix: Frontend error when parsing a NaN float.
|
||||
|
||||
### Other
|
||||
|
||||
- Added TSV as a download format (in addition to CSV and Excel).
|
||||
- Added maildev settings (helps with automated settings).
|
||||
- Refine permissions usage in Redash to allow for guest users
|
||||
- The query results API now explicitly handles 404 errors.
|
||||
- Forked queries now retain the tags of the original query.
|
||||
- We now allow setting custom Sentry environments.
|
||||
- Started using Black linter for our Python source code
|
||||
- Added CLI command to re-encrypt data source details with new secret key.
|
||||
- Favorites list is now loaded on menu click instead of on page load.
|
||||
- Administrators can now allow connections to private IP addresses.
|
||||
|
||||
## v8.0.0 - 2019-10-27
|
||||
|
||||
There were no changes in this release since `v8.0.0-beta.2`. This is just to mark a stable release.
|
||||
@@ -8,24 +152,23 @@ There were no changes in this release since `v8.0.0-beta.2`. This is just to mar
|
||||
|
||||
This is an update to the previous beta release, which includes:
|
||||
|
||||
* Add options for users to share anonymous usage information with us (see [docs](https://redash.io/help/open-source/admin-guide/usage-data) for details).
|
||||
* Visualizations:
|
||||
- Allow the user to decide how to handle null values in charts.
|
||||
* Upgrade Sentry-SDK to latest version.
|
||||
* Make horizontal table scroll visible in dashboard widgets without scrolling.
|
||||
* Data Sources:
|
||||
* Add support for Azure Data Explorer (Kusto).
|
||||
* MySQL: fix connections without SSL configuration failing.
|
||||
* Amazon Redshift: option to set query group for adhoc/scheduled queries.
|
||||
* Hive: make error message more friendly.
|
||||
* Qubole: add support to run Quantum queries.
|
||||
* Display data source icon in query editor.
|
||||
* Fix: allow users with view only acces to use the queries in Query Results
|
||||
* Dashboard: when updating parameters refersh only widgets that use those parameters.
|
||||
- Add options for users to share anonymous usage information with us (see [docs](https://redash.io/help/open-source/admin-guide/usage-data) for details).
|
||||
- Visualizations:
|
||||
- Allow the user to decide how to handle null values in charts.
|
||||
- Upgrade Sentry-SDK to latest version.
|
||||
- Make horizontal table scroll visible in dashboard widgets without scrolling.
|
||||
- Data Sources:
|
||||
- Add support for Azure Data Explorer (Kusto).
|
||||
- MySQL: fix connections without SSL configuration failing.
|
||||
- Amazon Redshift: option to set query group for adhoc/scheduled queries.
|
||||
- Hive: make error message more friendly.
|
||||
- Qubole: add support to run Quantum queries.
|
||||
- Display data source icon in query editor.
|
||||
- Fix: allow users with view only acces to use the queries in Query Results
|
||||
- Dashboard: when updating parameters refersh only widgets that use those parameters.
|
||||
|
||||
This release had contributions from 12 people: @arikfr, @cclauss, @gabrieldutra, @justinclift, @kravets-levko, @ranbena, @rauchy, @sandeepV2, @shinsuke-nara, @spacentropy, @sphenlee, @swfz.
|
||||
|
||||
|
||||
## v8.0.0-beta - 2019-08-18
|
||||
|
||||
After months of being heads down with hard work, it's finally time to wrap up the V8 release 🤩 This release includes many long awaited improvements to parameters, UX improvements, further React migration and other changes, fixes and improvements.
|
||||
@@ -39,10 +182,10 @@ This release was made possible by contributions from over 40 people: @aidarbek,
|
||||
### Parameters
|
||||
|
||||
- Parameter UI improvements:
|
||||
- Support for multi-select in dropdown (and query dropdown) parameters.
|
||||
- Support for dynamic values in date and date-range parameters.
|
||||
- Search dropdown parameter values.
|
||||
- New UX for applying parameter changes in queries and dashboards.
|
||||
- Support for multi-select in dropdown (and query dropdown) parameters.
|
||||
- Support for dynamic values in date and date-range parameters.
|
||||
- Search dropdown parameter values.
|
||||
- New UX for applying parameter changes in queries and dashboards.
|
||||
- Allow using Safe Parameters in visualization embeds and public dashboards. Safe Parameters are any parameter type except for the a text parameter (dropdowns are safe).
|
||||
|
||||
### Data Sources
|
||||
@@ -52,19 +195,19 @@ This release was made possible by contributions from over 40 people: @aidarbek,
|
||||
- Snowflake: update connector to latest version.
|
||||
- PostgreSQL: show only accessible tables in schema.
|
||||
- BigQuery:
|
||||
- Correctly handle NaN values.
|
||||
- Treat repeated fields as rrays.
|
||||
- [BigQuery] Fix: in some queries there is no mode field
|
||||
- Correctly handle NaN values.
|
||||
- Treat repeated fields as rrays.
|
||||
- [BigQuery] Fix: in some queries there is no mode field
|
||||
- DynamoDB:
|
||||
- Support for Unicode in queries.
|
||||
- Safe loading of schema.
|
||||
- Support for Unicode in queries.
|
||||
- Safe loading of schema.
|
||||
- Rockset: better handling of query errors.
|
||||
- Google Sheets:
|
||||
- Support for Team Drive.
|
||||
- Friendlier error message in case of an API error and more reliable test connection.
|
||||
- MySQL:
|
||||
- Support for calling Stored Procedures and better handling of query cancellation.
|
||||
- Switch to using `mysqlclient` (a maintained fork of `Python-MySQL`).
|
||||
- Support for Team Drive.
|
||||
- Friendlier error message in case of an API error and more reliable test connection.
|
||||
- MySQL:
|
||||
- Support for calling Stored Procedures and better handling of query cancellation.
|
||||
- Switch to using `mysqlclient` (a maintained fork of `Python-MySQL`).
|
||||
- MongoDB: Support serializing Decimal128 values.
|
||||
- Presto: support for passwords in connection settings.
|
||||
- Amazon Athena: allow to specify custom work group.
|
||||
@@ -75,15 +218,15 @@ This release was made possible by contributions from over 40 people: @aidarbek,
|
||||
### Visualizations
|
||||
|
||||
- Charts:
|
||||
- Fix: legend overlapping chart on small screens.
|
||||
- Fix: Pie chart not rendering when series doesn't exist in options.
|
||||
- Pie Chart: add option to set direction of slices.
|
||||
- Fix: legend overlapping chart on small screens.
|
||||
- Fix: Pie chart not rendering when series doesn't exist in options.
|
||||
- Pie Chart: add option to set direction of slices.
|
||||
- WordCloud: rewritten to support new options (provide frequency in query, limits), scale when resizing, handle long words and more.
|
||||
- Pivot Table: support hiding totals.
|
||||
- Counters: apply formatting to target value.
|
||||
- Maps:
|
||||
- Ability to customize marker icon and color.
|
||||
- Customization options for Choropleth maps.
|
||||
- Ability to customize marker icon and color.
|
||||
- Customization options for Choropleth maps.
|
||||
- New Visualization: Details View.
|
||||
|
||||
### **UX**
|
||||
|
||||
51
Dockerfile
51
Dockerfile
@@ -1,19 +1,35 @@
|
||||
FROM node:12 as frontend-builder
|
||||
|
||||
# Controls whether to build the frontend assets
|
||||
ARG skip_frontend_build
|
||||
|
||||
ENV CYPRESS_INSTALL_BINARY=0
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
|
||||
|
||||
RUN useradd -m -d /frontend redash
|
||||
USER redash
|
||||
|
||||
WORKDIR /frontend
|
||||
COPY package.json package-lock.json /frontend/
|
||||
RUN npm install
|
||||
COPY --chown=redash package.json package-lock.json /frontend/
|
||||
COPY --chown=redash viz-lib /frontend/viz-lib
|
||||
|
||||
COPY client /frontend/client
|
||||
COPY webpack.config.js /frontend/
|
||||
RUN npm run build
|
||||
# Controls whether to instrument code for coverage information
|
||||
ARG code_coverage
|
||||
ENV BABEL_ENV=${code_coverage:+test}
|
||||
|
||||
RUN if [ "x$skip_frontend_build" = "x" ] ; then npm ci --unsafe-perm; fi
|
||||
|
||||
COPY --chown=redash client /frontend/client
|
||||
COPY --chown=redash webpack.config.js /frontend/
|
||||
RUN if [ "x$skip_frontend_build" = "x" ] ; then npm run build; else mkdir -p /frontend/client/dist && touch /frontend/client/dist/multi_org.html && touch /frontend/client/dist/index.html; fi
|
||||
FROM python:3.7-slim
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
# Controls whether to install extra dependencies needed for all data sources.
|
||||
ARG skip_ds_deps
|
||||
# Controls whether to install dev dependencies.
|
||||
ARG skip_dev_deps
|
||||
|
||||
RUN useradd --create-home redash
|
||||
|
||||
@@ -30,22 +46,43 @@ RUN apt-get update && \
|
||||
wget \
|
||||
# Postgres client
|
||||
libpq-dev \
|
||||
# ODBC support:
|
||||
g++ unixodbc-dev \
|
||||
# for SAML
|
||||
xmlsec1 \
|
||||
# Additional packages required for data sources:
|
||||
libssl-dev \
|
||||
default-libmysqlclient-dev \
|
||||
freetds-dev \
|
||||
libsasl2-dev && \
|
||||
libsasl2-dev \
|
||||
unzip \
|
||||
libsasl2-modules-gssapi-mit && \
|
||||
# MSSQL ODBC Driver:
|
||||
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
|
||||
curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
|
||||
apt-get update && \
|
||||
ACCEPT_EULA=Y apt-get install -y msodbcsql17 && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG databricks_odbc_driver_url=https://databricks.com/wp-content/uploads/2.6.10.1010-2/SimbaSparkODBC-2.6.10.1010-2-Debian-64bit.zip
|
||||
ADD $databricks_odbc_driver_url /tmp/simba_odbc.zip
|
||||
RUN unzip /tmp/simba_odbc.zip -d /tmp/ \
|
||||
&& dpkg -i /tmp/SimbaSparkODBC-*/*.deb \
|
||||
&& echo "[Simba]\nDriver = /opt/simba/spark/lib/64/libsparkodbc_sb64.so" >> /etc/odbcinst.ini \
|
||||
&& rm /tmp/simba_odbc.zip \
|
||||
&& rm -rf /tmp/SimbaSparkODBC*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Disalbe PIP Cache and Version Check
|
||||
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||
ENV PIP_NO_CACHE_DIR=1
|
||||
|
||||
# We first copy only the requirements file, to avoid rebuilding on every file
|
||||
# change.
|
||||
COPY requirements.txt requirements_bundles.txt requirements_dev.txt requirements_all_ds.txt ./
|
||||
RUN pip install -r requirements.txt -r requirements_dev.txt
|
||||
RUN if [ "x$skip_dev_deps" = "x" ] ; then pip install -r requirements.txt -r requirements_dev.txt; else pip install -r requirements.txt; fi
|
||||
RUN if [ "x$skip_ds_deps" = "x" ] ; then pip install -r requirements_all_ds.txt ; else echo "Skipping pip install -r requirements_all_ds.txt" ; fi
|
||||
|
||||
COPY . /app
|
||||
|
||||
2
Makefile
2
Makefile
@@ -35,7 +35,7 @@ backend-unit-tests: up test_db
|
||||
docker-compose run --rm --name tests server tests
|
||||
|
||||
frontend-unit-tests: bundle
|
||||
npm install
|
||||
CYPRESS_INSTALL_BINARY=0 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 npm ci
|
||||
npm run bundle
|
||||
npm test
|
||||
|
||||
|
||||
73
README.md
73
README.md
@@ -6,28 +6,77 @@
|
||||
[](https://datree.io/?src=badge)
|
||||
[](https://circleci.com/gh/getredash/redash/tree/master)
|
||||
|
||||
**_Redash_** is our take on freeing the data within our company in a way that will better fit our culture and usage patterns.
|
||||
Redash is designed to enable anyone, regardless of the level of technical sophistication, to harness the power of data big and small. SQL users leverage Redash to explore, query, visualize, and share data from any data sources. Their work in turn enables anybody in their organization to use the data. Every day, millions of users at thousands of organizations around the world use Redash to develop insights and make data-driven decisions.
|
||||
|
||||
Prior to **_Redash_**, we tried to use traditional BI suites and discovered a set of bloated, technically challenged and slow tools/flows. What we were looking for was a more hacker'ish way to look at data, so we built one.
|
||||
Redash features:
|
||||
|
||||
**_Redash_** was built to allow fast and easy access to billions of records, that we process and collect using Amazon Redshift ("petabyte scale data warehouse" that "speaks" PostgreSQL).
|
||||
Today **_Redash_** has support for querying multiple databases, including: Redshift, Google BigQuery, PostgreSQL, MySQL, Graphite, Presto, Google Spreadsheets, Cloudera Impala, Hive and custom scripts.
|
||||
|
||||
**_Redash_** consists of two parts:
|
||||
|
||||
1. **Query Editor**: think of [JS Fiddle](https://jsfiddle.net) for SQL queries. It's your way to share data in the organization in an open way, by sharing both the dataset and the query that generated it. This way everyone can peer review not only the resulting dataset but also the process that generated it. Also it's possible to fork it and generate new datasets and reach new insights.
|
||||
2. **Visualizations and Dashboards**: once you have a dataset, you can create different visualizations out of it, and then combine several visualizations into a single dashboard. Currently Redash supports charts, pivot table, cohorts and [more](https://redash.io/help/user-guide/visualizations/visualization-types).
|
||||
1. **Browser-based**: Everything in your browser, with a shareable URL.
|
||||
2. **Ease-of-use**: Become immediately productive with data without the need to master complex software.
|
||||
3. **Query editor**: Quickly compose SQL and NoSQL queries with a schema browser and auto-complete.
|
||||
4. **Visualization and dashboards**: Create [beautiful visualizations](https://redash.io/help/user-guide/visualizations/visualization-types) with drag and drop, and combine them into a single dashboard.
|
||||
5. **Sharing**: Collaborate easily by sharing visualizations and their associated queries, enabling peer review of reports and queries.
|
||||
6. **Schedule refreshes**: Automatically update your charts and dashboards at regular intervals you define.
|
||||
7. **Alerts**: Define conditions and be alerted instantly when your data changes.
|
||||
8. **REST API**: Everything that can be done in the UI is also available through REST API.
|
||||
9. **Broad support for data sources**: Extensible data source API with native support for a long list of common databases and platforms.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/getredash/website/8e820cd02c73a8ddf4f946a9d293c54fd3fb08b9/website/_assets/images/redash-anim.gif" width="80%"/>
|
||||
|
||||
## Getting Started
|
||||
|
||||
* [Setting up Redash instance](https://redash.io/help/open-source/setup) (includes links to ready made AWS/GCE images).
|
||||
* [Setting up Redash instance](https://redash.io/help/open-source/setup) (includes links to ready-made AWS/GCE images).
|
||||
* [Documentation](https://redash.io/help/).
|
||||
|
||||
## Supported Data Sources
|
||||
|
||||
Redash supports more than 35 [data sources](https://redash.io/help/data-sources/supported-data-sources).
|
||||
Redash supports more than 35 SQL and NoSQL [data sources](https://redash.io/help/data-sources/supported-data-sources). It can also be extended to support more. Below is a list of built-in sources:
|
||||
|
||||
- Amazon Athena
|
||||
- Amazon DynamoDB
|
||||
- Amazon Redshift
|
||||
- Axibase Time Series Database
|
||||
- Cassandra
|
||||
- ClickHouse
|
||||
- CockroachDB
|
||||
- CSV
|
||||
- Databricks (Apache Spark)
|
||||
- DB2 by IBM
|
||||
- Druid
|
||||
- Elasticsearch
|
||||
- Google Analytics
|
||||
- Google BigQuery
|
||||
- Google Spreadsheets
|
||||
- Graphite
|
||||
- Greenplum
|
||||
- Hive
|
||||
- Impala
|
||||
- InfluxDB
|
||||
- JIRA
|
||||
- JSON
|
||||
- Apache Kylin
|
||||
- OmniSciDB (Formerly MapD)
|
||||
- MemSQL
|
||||
- Microsoft Azure Data Warehouse / Synapse
|
||||
- Microsoft Azure SQL Database
|
||||
- Microsoft SQL Server
|
||||
- MongoDB
|
||||
- MySQL
|
||||
- Oracle
|
||||
- PostgreSQL
|
||||
- Presto
|
||||
- Prometheus
|
||||
- Python
|
||||
- Qubole
|
||||
- Rockset
|
||||
- Salesforce
|
||||
- ScyllaDB
|
||||
- Shell Scripts
|
||||
- Snowflake
|
||||
- SQLite
|
||||
- TreasureData
|
||||
- Vertica
|
||||
- Yandex AppMetrrica
|
||||
- Yandex Metrica
|
||||
|
||||
## Getting Help
|
||||
|
||||
@@ -37,7 +86,7 @@ Redash supports more than 35 [data sources](https://redash.io/help/data-sources/
|
||||
## Reporting Bugs and Contributing Code
|
||||
|
||||
* Want to report a bug or request a feature? Please open [an issue](https://github.com/getredash/redash/issues/new).
|
||||
* Want to help us build **_Redash_**? Fork the project, edit in a [dev environment](https://redash.io/help-onpremise/dev/guide.html), and make a pull request. We need all the help we can get!
|
||||
* Want to help us build **_Redash_**? Fork the project, edit in a [dev environment](https://redash.io/help-onpremise/dev/guide.html) and make a pull request. We need all the help we can get!
|
||||
|
||||
## Security
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ from pathlib import Path
|
||||
from shutil import copy
|
||||
from collections import OrderedDict as odict
|
||||
|
||||
from importlib_metadata import entry_points
|
||||
from importlib_resources import contents, is_resource, path
|
||||
import importlib_metadata
|
||||
import importlib_resources
|
||||
|
||||
# Name of the subdirectory
|
||||
BUNDLE_DIRECTORY = "bundle"
|
||||
@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
# Make a directory for extensions and set it as an environment variable
|
||||
# to be picked up by webpack.
|
||||
extensions_relative_path = Path('client', 'app', 'extensions')
|
||||
extensions_relative_path = Path("client", "app", "extensions")
|
||||
extensions_directory = Path(__file__).parent.parent / extensions_relative_path
|
||||
|
||||
if not extensions_directory.exists():
|
||||
@@ -25,18 +25,6 @@ if not extensions_directory.exists():
|
||||
os.environ["EXTENSIONS_DIRECTORY"] = str(extensions_relative_path)
|
||||
|
||||
|
||||
def resource_isdir(module, resource):
|
||||
"""Whether a given resource is a directory in the given module
|
||||
|
||||
https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-isdir
|
||||
"""
|
||||
try:
|
||||
return resource in contents(module) and not is_resource(module, resource)
|
||||
except (ImportError, TypeError):
|
||||
# module isn't a package, so can't have a subdirectory/-package
|
||||
return False
|
||||
|
||||
|
||||
def entry_point_module(entry_point):
|
||||
"""Returns the dotted module path for the given entry point"""
|
||||
return entry_point.pattern.match(entry_point.value).group("module")
|
||||
@@ -77,26 +65,36 @@ def load_bundles():
|
||||
|
||||
"""
|
||||
bundles = odict()
|
||||
for entry_point in entry_points().get("redash.bundles", []):
|
||||
for entry_point in importlib_metadata.entry_points().get("redash.bundles", []):
|
||||
logger.info('Loading Redash bundle "%s".', entry_point.name)
|
||||
module = entry_point_module(entry_point)
|
||||
# Try to get a list of bundle files
|
||||
if not resource_isdir(module, BUNDLE_DIRECTORY):
|
||||
try:
|
||||
bundle_dir = importlib_resources.files(module).joinpath(BUNDLE_DIRECTORY)
|
||||
except (ImportError, TypeError):
|
||||
# Module isn't a package, so can't have a subdirectory/-package
|
||||
logger.error(
|
||||
'Redash bundle directory "%s" could not be found.', entry_point.name
|
||||
'Redash bundle module "%s" could not be imported: "%s"',
|
||||
entry_point.name,
|
||||
module,
|
||||
)
|
||||
continue
|
||||
with path(module, BUNDLE_DIRECTORY) as bundle_dir:
|
||||
bundles[entry_point.name] = list(bundle_dir.rglob("*"))
|
||||
|
||||
if not bundle_dir.is_dir():
|
||||
logger.error(
|
||||
'Redash bundle directory "%s" could not be found or is not a directory: "%s"',
|
||||
entry_point.name,
|
||||
bundle_dir,
|
||||
)
|
||||
continue
|
||||
bundles[entry_point.name] = list(bundle_dir.rglob("*"))
|
||||
return bundles
|
||||
|
||||
|
||||
bundles = load_bundles().items()
|
||||
if bundles:
|
||||
print('Number of extension bundles found: {}'.format(len(bundles)))
|
||||
print("Number of extension bundles found: {}".format(len(bundles)))
|
||||
else:
|
||||
print('No extension bundles found.')
|
||||
print("No extension bundles found.")
|
||||
|
||||
for bundle_name, paths in bundles:
|
||||
# Shortcut in case not paths were found for the bundle
|
||||
|
||||
@@ -18,8 +18,8 @@ worker() {
|
||||
|
||||
export WORKERS_COUNT=${WORKERS_COUNT:-2}
|
||||
export QUEUES=${QUEUES:-}
|
||||
|
||||
supervisord -c worker.conf
|
||||
|
||||
exec supervisord -c worker.conf
|
||||
}
|
||||
|
||||
dev_worker() {
|
||||
@@ -39,10 +39,6 @@ create_db() {
|
||||
exec /app/manage.py database create_tables
|
||||
}
|
||||
|
||||
rq_healthcheck() {
|
||||
exec /app/manage.py rq healthcheck
|
||||
}
|
||||
|
||||
help() {
|
||||
echo "Redash Docker."
|
||||
echo ""
|
||||
@@ -54,7 +50,6 @@ help() {
|
||||
echo "dev_worker -- start a single RQ worker with code reloading"
|
||||
echo "scheduler -- start an rq-scheduler instance"
|
||||
echo "dev_scheduler -- start an rq-scheduler instance with code reloading"
|
||||
echo "rq_healthcheck -- runs a RQ healthcheck that verifies that all local workers are active. Useful for Docker's HEALTHCHECK mechanism."
|
||||
echo ""
|
||||
echo "shell -- open shell"
|
||||
echo "dev_server -- start Flask development server with debugger and auto reload"
|
||||
@@ -96,9 +91,9 @@ case "$1" in
|
||||
shift
|
||||
dev_worker
|
||||
;;
|
||||
rq_healthcheck)
|
||||
celery_healthcheck)
|
||||
shift
|
||||
rq_healthcheck
|
||||
echo "DEPRECATED: Celery has been replaced with RQ and now performs healthchecks autonomously as part of the 'worker' entrypoint."
|
||||
;;
|
||||
dev_server)
|
||||
export FLASK_DEBUG=1
|
||||
@@ -131,4 +126,3 @@ case "$1" in
|
||||
exec "$@"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Heroku pre_compile script
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
pushd $DIR/..
|
||||
|
||||
# heroku requires cffi to be in requirements.txt in order for libffi to be installed.
|
||||
# https://github.com/heroku/heroku-buildpack-python/blob/master/bin/steps/cryptography
|
||||
# to avoid making it a requirement for other build systems, we'll inject it now
|
||||
# into the requirements.txt file
|
||||
|
||||
# Remove Heroku unsupported Python packages:
|
||||
grep -v -E "^(pymssql|thrift|sasl|pyhive)" requirements_all_ds.txt >> requirements.txt
|
||||
|
||||
# make the heroku Procfile the active one
|
||||
cp Procfile.heroku Procfile
|
||||
|
||||
popd
|
||||
@@ -1,19 +1,29 @@
|
||||
{
|
||||
"presets": [
|
||||
["@babel/preset-env", {
|
||||
"exclude": [
|
||||
"@babel/plugin-transform-async-to-generator",
|
||||
"@babel/plugin-transform-arrow-functions"
|
||||
],
|
||||
"useBuiltIns": "usage"
|
||||
}],
|
||||
"@babel/preset-react"
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"exclude": ["@babel/plugin-transform-async-to-generator", "@babel/plugin-transform-arrow-functions"],
|
||||
"corejs": "2",
|
||||
"useBuiltIns": "usage"
|
||||
}
|
||||
],
|
||||
"@babel/preset-react",
|
||||
"@babel/preset-typescript"
|
||||
],
|
||||
"plugins": [
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
"@babel/plugin-transform-object-assign",
|
||||
["babel-plugin-transform-builtin-extend", {
|
||||
"globals": ["Error"]
|
||||
}]
|
||||
]
|
||||
[
|
||||
"babel-plugin-transform-builtin-extend",
|
||||
{
|
||||
"globals": ["Error"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"env": {
|
||||
"test": {
|
||||
"plugins": ["istanbul"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,58 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ["react-app", "plugin:compat/recommended", "prettier"],
|
||||
plugins: ["jest", "compat", "no-only-tests"],
|
||||
parser: "@typescript-eslint/parser",
|
||||
extends: [
|
||||
"react-app",
|
||||
"plugin:compat/recommended",
|
||||
"prettier",
|
||||
// Remove any typescript-eslint rules that would conflict with prettier
|
||||
"prettier/@typescript-eslint",
|
||||
],
|
||||
plugins: ["jest", "compat", "no-only-tests", "@typescript-eslint"],
|
||||
settings: {
|
||||
"import/resolver": "webpack"
|
||||
"import/resolver": "webpack",
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
node: true
|
||||
node: true,
|
||||
},
|
||||
rules: {
|
||||
// allow debugger during development
|
||||
"no-debugger": process.env.NODE_ENV === "production" ? 2 : 0,
|
||||
"jsx-a11y/anchor-is-valid": "off",
|
||||
}
|
||||
"no-console": ["warn", { allow: ["warn", "error"] }],
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
paths: [
|
||||
{
|
||||
name: "antd",
|
||||
message: "Please use 'import XXX from antd/lib/XXX' import instead.",
|
||||
},
|
||||
{
|
||||
name: "antd/lib",
|
||||
message: "Please use 'import XXX from antd/lib/XXX' import instead.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
// Only run typescript-eslint on TS files
|
||||
files: ["*.ts", "*.tsx", ".*.ts", ".*.tsx"],
|
||||
extends: ["plugin:@typescript-eslint/recommended"],
|
||||
rules: {
|
||||
// Do not require functions (especially react components) to have explicit returns
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
// Do not require to type every import from a JS file to speed up development
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
// Do not complain about useless contructors in declaration files
|
||||
"no-useless-constructor": "off",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
// Many API fields and generated types use camelcase
|
||||
"@typescript-eslint/camelcase": "off","@typescript-eslint/no-empty-function": "off",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 2.8 KiB |
BIN
client/app/assets/images/db-logos/mssql_odbc.png
Normal file
BIN
client/app/assets/images/db-logos/mssql_odbc.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
client/app/assets/images/fixtures/map-tile.png
Normal file
BIN
client/app/assets/images/fixtures/map-tile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
13
client/app/assets/images/illustrations/no-query-results.svg
Normal file
13
client/app/assets/images/illustrations/no-query-results.svg
Normal file
@@ -0,0 +1,13 @@
|
||||
<svg width="274" height="199" viewBox="0 0 274 199" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path opacity="0.5" d="M57.9111 49.2668L202.769 30" stroke="#F2F2F2" stroke-width="59" stroke-linecap="round"/>
|
||||
<path opacity="0.5" d="M39.2842 92.7371L244.24 64.886" stroke="#F2F2F2" stroke-width="59" stroke-linecap="round"/>
|
||||
<path opacity="0.5" d="M30 136.299L232.813 107.734" stroke="#F2F2F2" stroke-width="59" stroke-linecap="round"/>
|
||||
<path opacity="0.5" d="M86.4541 169.149L234.166 150.596" stroke="#F2F2F2" stroke-width="59" stroke-linecap="round"/>
|
||||
<path d="M167.829 69.1349H96.458L117.605 51.9531H183.028L167.829 69.1349Z" fill="#C0D5FF"/>
|
||||
<path d="M171.133 70.4566H92.4933V85.6559V143.149H171.133V70.4566Z" fill="#E8F4FF"/>
|
||||
<path d="M190.298 48.6489L171.133 70.4566L186.993 94.9076L192.28 89.9514L206.818 73.7608L190.298 48.6489Z" fill="#E8F4FF"/>
|
||||
<path d="M171.133 70.4566V143.149L192.28 118.037V89.9514L186.993 94.9076L171.133 70.4566Z" fill="#E8F4FF"/>
|
||||
<path d="M92.4933 70.4566L81.9199 89.9514L92.4933 85.6559V70.4566Z" fill="#E8F4FF"/>
|
||||
<path d="M92.4933 70.4566H171.133M92.4933 70.4566L118.927 48.6489H190.298M92.4933 70.4566L81.9199 89.9514L92.4933 85.6559M92.4933 70.4566V85.6559M171.133 70.4566V143.149M171.133 70.4566L190.298 48.6489M171.133 70.4566L186.993 94.9076L192.28 89.9514M171.133 143.149H92.4933V85.6559M171.133 143.149L192.28 118.037V89.9514M190.298 48.6489L206.818 73.7608L192.28 89.9514" stroke="black" stroke-width="3" stroke-linejoin="round"/>
|
||||
<path d="M117.605 89.6208H147.343" stroke="black" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -1,42 +1,43 @@
|
||||
@import '~antd/lib/style/core/iconfont';
|
||||
@import '~antd/lib/style/core/motion';
|
||||
@import '~antd/lib/alert/style/index';
|
||||
@import '~antd/lib/input/style/index';
|
||||
@import '~antd/lib/input-number/style/index';
|
||||
@import '~antd/lib/date-picker/style/index';
|
||||
@import '~antd/lib/modal/style/index';
|
||||
@import '~antd/lib/tooltip/style/index';
|
||||
@import '~antd/lib/select/style/index';
|
||||
@import '~antd/lib/checkbox/style/index';
|
||||
@import '~antd/lib/upload/style/index';
|
||||
@import '~antd/lib/form/style/index';
|
||||
@import '~antd/lib/button/style/index';
|
||||
@import '~antd/lib/radio/style/index';
|
||||
@import '~antd/lib/time-picker/style/index';
|
||||
@import '~antd/lib/pagination/style/index';
|
||||
@import '~antd/lib/table/style/index';
|
||||
@import '~antd/lib/popover/style/index';
|
||||
@import '~antd/lib/icon/style/index';
|
||||
@import '~antd/lib/tag/style/index';
|
||||
@import '~antd/lib/grid/style/index';
|
||||
@import '~antd/lib/switch/style/index';
|
||||
@import '~antd/lib/empty/style/index';
|
||||
@import '~antd/lib/drawer/style/index';
|
||||
@import '~antd/lib/card/style/index';
|
||||
@import '~antd/lib/steps/style/index';
|
||||
@import '~antd/lib/divider/style/index';
|
||||
@import '~antd/lib/dropdown/style/index';
|
||||
@import '~antd/lib/menu/style/index';
|
||||
@import '~antd/lib/list/style/index';
|
||||
@import "~antd/lib/style/core/iconfont";
|
||||
@import "~antd/lib/style/core/motion";
|
||||
@import "~antd/lib/alert/style/index";
|
||||
@import "~antd/lib/input/style/index";
|
||||
@import "~antd/lib/input-number/style/index";
|
||||
@import "~antd/lib/date-picker/style/index";
|
||||
@import "~antd/lib/modal/style/index";
|
||||
@import "~antd/lib/tooltip/style/index";
|
||||
@import "~antd/lib/select/style/index";
|
||||
@import "~antd/lib/checkbox/style/index";
|
||||
@import "~antd/lib/upload/style/index";
|
||||
@import "~antd/lib/form/style/index";
|
||||
@import "~antd/lib/button/style/index";
|
||||
@import "~antd/lib/radio/style/index";
|
||||
@import "~antd/lib/time-picker/style/index";
|
||||
@import "~antd/lib/pagination/style/index";
|
||||
@import "~antd/lib/table/style/index";
|
||||
@import "~antd/lib/popover/style/index";
|
||||
@import "~antd/lib/tag/style/index";
|
||||
@import "~antd/lib/grid/style/index";
|
||||
@import "~antd/lib/switch/style/index";
|
||||
@import "~antd/lib/empty/style/index";
|
||||
@import "~antd/lib/drawer/style/index";
|
||||
@import "~antd/lib/card/style/index";
|
||||
@import "~antd/lib/steps/style/index";
|
||||
@import "~antd/lib/divider/style/index";
|
||||
@import "~antd/lib/dropdown/style/index";
|
||||
@import "~antd/lib/menu/style/index";
|
||||
@import "~antd/lib/list/style/index";
|
||||
@import "~antd/lib/badge/style/index";
|
||||
@import "~antd/lib/card/style/index";
|
||||
@import "~antd/lib/spin/style/index";
|
||||
@import "~antd/lib/skeleton/style/index";
|
||||
@import "~antd/lib/tabs/style/index";
|
||||
@import "~antd/lib/notification/style/index";
|
||||
@import "~antd/lib/collapse/style/index";
|
||||
@import "~antd/lib/progress/style/index";
|
||||
@import "~antd/lib/typography/style/index";
|
||||
@import 'inc/ant-variables';
|
||||
@import "~antd/lib/descriptions/style/index";
|
||||
@import "inc/ant-variables";
|
||||
|
||||
// Increase z-indexes to avoid conflicts with some other libraries (e.g. Plotly)
|
||||
@zindex-modal: 2000;
|
||||
@@ -237,11 +238,11 @@
|
||||
&-item {
|
||||
// custom rule
|
||||
&.selected {
|
||||
background-color: #F6F8F9;
|
||||
background-color: #f6f8f9;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
background-color: fade(#F6F8F9, 40%);
|
||||
background-color: fade(#f6f8f9, 40%);
|
||||
|
||||
& > * {
|
||||
opacity: 0.4;
|
||||
@@ -367,7 +368,7 @@
|
||||
top: auto !important;
|
||||
bottom: 8px;
|
||||
|
||||
// makes the icon white instead of see-through
|
||||
// makes the icon white instead of see-through
|
||||
& svg {
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
@@ -394,9 +395,20 @@
|
||||
}
|
||||
|
||||
// overrides for checkbox
|
||||
@checkbox-prefix-cls: ~'@{ant-prefix}-checkbox';
|
||||
@checkbox-prefix-cls: ~"@{ant-prefix}-checkbox";
|
||||
|
||||
.@{checkbox-prefix-cls}-wrapper + span,
|
||||
.@{checkbox-prefix-cls} + span {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
// make sure Multiple select has room for icons
|
||||
.@{select-prefix-cls}-multiple {
|
||||
&.@{select-prefix-cls}-show-arrow,
|
||||
&.@{select-prefix-cls}-show-search,
|
||||
&.@{select-prefix-cls}-loading {
|
||||
.@{select-prefix-cls}-selector {
|
||||
padding-right: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,49 @@
|
||||
.alert-page h3 {
|
||||
flex-grow: 1;
|
||||
|
||||
input {
|
||||
margin: -0.2em 0;
|
||||
width: 100%;
|
||||
min-width: 170px;
|
||||
}
|
||||
flex-grow: 1;
|
||||
|
||||
input {
|
||||
margin: -0.2em 0;
|
||||
width: 100%;
|
||||
min-width: 170px;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-create-alert[disabled] {
|
||||
display: block;
|
||||
margin-top: -20px;
|
||||
display: block;
|
||||
margin-top: -20px;
|
||||
}
|
||||
|
||||
.alert-state {
|
||||
border-bottom: 1px solid @input-border;
|
||||
padding-bottom: 30px;
|
||||
border-bottom: 1px solid @input-border;
|
||||
padding-bottom: 30px;
|
||||
|
||||
.alert-state-indicator {
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
padding: 5px 8px;
|
||||
}
|
||||
.alert-state-indicator {
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
padding: 5px 8px;
|
||||
}
|
||||
|
||||
.alert-last-triggered {
|
||||
color: @headings-color;
|
||||
}
|
||||
.ant-form-item-explain {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.alert-last-triggered {
|
||||
color: @headings-color;
|
||||
}
|
||||
}
|
||||
|
||||
.alert-query-selector {
|
||||
min-width: 250px;
|
||||
width: auto !important;
|
||||
min-width: 250px;
|
||||
width: auto !important;
|
||||
}
|
||||
|
||||
// allow form item labels to gracefully break line
|
||||
.alert-form-item label {
|
||||
white-space: initial;
|
||||
padding-right: 8px;
|
||||
line-height: 21px;
|
||||
white-space: initial;
|
||||
padding-right: 8px;
|
||||
line-height: 21px;
|
||||
|
||||
&::after {
|
||||
margin-right: 0 !important;
|
||||
}
|
||||
&::after {
|
||||
margin-right: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.alert-actions {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
margin-right: -15px;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
/* --------------------------------------------------------
|
||||
Colors
|
||||
-----------------------------------------------------------*/
|
||||
@lightblue: #03A9F4;
|
||||
@primary-color: #2196F3;
|
||||
@lightblue: #03a9f4;
|
||||
@primary-color: #2196f3;
|
||||
|
||||
@redash-gray: rgba(102, 136, 153, 1);
|
||||
@redash-orange: rgba(255, 120, 100, 1);
|
||||
@@ -12,41 +12,31 @@
|
||||
/* --------------------------------------------------------
|
||||
Font
|
||||
-----------------------------------------------------------*/
|
||||
@redash-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
@font-family-no-number: @redash-font;
|
||||
@font-family: @redash-font;
|
||||
@code-family: @redash-font;
|
||||
@font-size-base: 13px;
|
||||
|
||||
@redash-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue",
|
||||
sans-serif;
|
||||
@font-family-no-number: @redash-font;
|
||||
@font-family: @redash-font;
|
||||
@code-family: @redash-font;
|
||||
@font-size-base: 13px;
|
||||
|
||||
/* --------------------------------------------------------
|
||||
Borders
|
||||
-----------------------------------------------------------*/
|
||||
@border-color-split: #f0f0f0;
|
||||
|
||||
@border-color-split: #f0f0f0;
|
||||
|
||||
/* --------------------------------------------------------
|
||||
Typograpgy
|
||||
-----------------------------------------------------------*/
|
||||
@text-color: #595959;
|
||||
|
||||
@text-color: #595959;
|
||||
|
||||
/* --------------------------------------------------------
|
||||
Form
|
||||
-----------------------------------------------------------*/
|
||||
@input-height-base: 35px;
|
||||
@input-color: #595959;
|
||||
@input-color-placeholder: #b4b4b4;
|
||||
@input-height-base: 35px;
|
||||
@input-color: #595959;
|
||||
@input-color-placeholder: #b4b4b4;
|
||||
@border-radius-base: 2px;
|
||||
@border-color-base: #E8E8E8;
|
||||
|
||||
|
||||
/* --------------------------------------------------------
|
||||
Button
|
||||
-----------------------------------------------------------*/
|
||||
@btn-danger-bg: fade(@redash-gray, 10%);
|
||||
@btn-danger-border: fade(@redash-gray, 15%);
|
||||
|
||||
@border-color-base: #e8e8e8;
|
||||
|
||||
/* --------------------------------------------------------
|
||||
Pagination
|
||||
@@ -55,14 +45,13 @@
|
||||
@pagination-font-family: @redash-font;
|
||||
@pagination-font-weight-active: normal;
|
||||
|
||||
@pagination-bg: fade(@redash-gray, 15%);
|
||||
@pagination-color: #7E7E7E;
|
||||
@pagination-active-bg: @lightblue;
|
||||
@pagination-active-color: #FFF;
|
||||
@pagination-disabled-bg: fade(@redash-gray, 15%);
|
||||
@pagination-hover-color: #333;
|
||||
@pagination-hover-bg: fade(@redash-gray, 25%);
|
||||
|
||||
@pagination-bg: fade(@redash-gray, 15%);
|
||||
@pagination-color: #7e7e7e;
|
||||
@pagination-active-bg: @lightblue;
|
||||
@pagination-active-color: #fff;
|
||||
@pagination-disabled-bg: fade(@redash-gray, 15%);
|
||||
@pagination-hover-color: #333;
|
||||
@pagination-hover-bg: fade(@redash-gray, 25%);
|
||||
|
||||
/* --------------------------------------------------------
|
||||
Table
|
||||
|
||||
@@ -32,17 +32,6 @@ body {
|
||||
#application-root {
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
&.headless {
|
||||
#application-root {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.app-header-wrapper {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#application-root {
|
||||
@@ -89,46 +78,16 @@ strong {
|
||||
}
|
||||
}
|
||||
|
||||
// Fixed width layout for specific pages
|
||||
@media (min-width: 768px) {
|
||||
.settings-screen,
|
||||
.home-page,
|
||||
.page-dashboard-list,
|
||||
.page-queries-list,
|
||||
.page-alerts-list,
|
||||
.alert-page,
|
||||
.fixed-container {
|
||||
.container {
|
||||
width: 750px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.settings-screen,
|
||||
.home-page,
|
||||
.page-dashboard-list,
|
||||
.page-queries-list,
|
||||
.page-alerts-list,
|
||||
.alert-page,
|
||||
.fixed-container {
|
||||
.container {
|
||||
width: 970px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
.settings-screen,
|
||||
.home-page,
|
||||
.page-dashboard-list,
|
||||
.page-queries-list,
|
||||
.page-alerts-list,
|
||||
.alert-page,
|
||||
.fixed-container {
|
||||
.container {
|
||||
width: 1170px;
|
||||
}
|
||||
.settings-screen,
|
||||
.home-page,
|
||||
.page-dashboard-list,
|
||||
.page-queries-list,
|
||||
.page-alerts-list,
|
||||
.alert-page,
|
||||
.admin-page-layout {
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,10 +203,6 @@ text.slicetext {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
h3 {
|
||||
margin-right: 5px !important;
|
||||
}
|
||||
|
||||
.label {
|
||||
margin-top: 3px;
|
||||
display: inline-block;
|
||||
@@ -255,11 +210,10 @@ text.slicetext {
|
||||
|
||||
.favorites-control {
|
||||
font-size: 19px;
|
||||
margin-right: 5px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.page-header-wrapper,
|
||||
.page-header--new {
|
||||
h3 {
|
||||
margin: 0.2em 0;
|
||||
|
||||
@@ -6,6 +6,7 @@ div.table-name {
|
||||
padding: 2px 22px 2px 10px;
|
||||
border-radius: @redash-radius;
|
||||
position: relative;
|
||||
height: 22px;
|
||||
|
||||
.copy-to-editor {
|
||||
display: none;
|
||||
@@ -27,13 +28,19 @@ div.table-name {
|
||||
}
|
||||
|
||||
.schema-browser {
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
overflow: hidden;
|
||||
border: none;
|
||||
margin-top: 10px;
|
||||
padding-top: 10px;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
|
||||
.schema-loading-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.collapse.in {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -57,6 +64,14 @@ div.table-name {
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
height: 18px;
|
||||
|
||||
.column-type {
|
||||
color: fade(@text-color, 80%);
|
||||
font-size: 10px;
|
||||
margin-left: 2px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.copy-to-editor {
|
||||
display: none;
|
||||
|
||||
@@ -1,149 +1,153 @@
|
||||
.table {
|
||||
margin-bottom: 0;
|
||||
|
||||
th.sortable-column {
|
||||
cursor: pointer;
|
||||
margin-bottom: 0;
|
||||
|
||||
th.sortable-column {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&:not(.table-striped) > thead > tr > th {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
[class*="bg-"] {
|
||||
& > tr > th {
|
||||
color: #fff;
|
||||
border-bottom: 0;
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
&:not(.table-striped) > thead > tr > th {
|
||||
background-color: #FAFAFA;
|
||||
|
||||
& + tbody > tr:first-child > td {
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
[class*="bg-"] {
|
||||
& > tr > th {
|
||||
color: #fff;
|
||||
border-bottom: 0;
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
& + tbody > tr:first-child > td {
|
||||
border-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
& > thead > tr > th {
|
||||
vertical-align: middle;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
border-width: 1px;
|
||||
text-transform: uppercase;
|
||||
padding: 15px 10px;
|
||||
}
|
||||
|
||||
& > thead > tr,
|
||||
& > tbody > tr,
|
||||
& > tfoot > tr {
|
||||
|
||||
& > th, & > td {
|
||||
|
||||
&:first-child {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
padding-right: 30px;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
tbody > tr:last-child > td {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
& > thead > tr > th {
|
||||
vertical-align: middle;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
border-width: 1px;
|
||||
text-transform: uppercase;
|
||||
padding: 15px 10px;
|
||||
}
|
||||
|
||||
& > thead > tr,
|
||||
& > tbody > tr,
|
||||
& > tfoot > tr {
|
||||
& > th,
|
||||
& > td {
|
||||
&:first-child {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
padding-right: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tbody > tr:last-child > td {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.table-bordered {
|
||||
border: 0;
|
||||
|
||||
& > tbody > tr {
|
||||
& > td, & > th {
|
||||
border-bottom: 0;
|
||||
border-left: 0;
|
||||
|
||||
&:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
}
|
||||
border: 0;
|
||||
|
||||
& > tbody > tr {
|
||||
& > td,
|
||||
& > th {
|
||||
border-bottom: 0;
|
||||
border-left: 0;
|
||||
|
||||
&:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
& > thead > tr > th {
|
||||
border-left: 0;
|
||||
|
||||
&:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
& > thead > tr > th {
|
||||
border-left: 0;
|
||||
|
||||
&:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.table-vmiddle {
|
||||
td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
}
|
||||
|
||||
.table-responsive {
|
||||
border: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.tile .table {
|
||||
|
||||
& > thead:not([class*="bg-"]) > tr > th {
|
||||
border-top: 1px solid @table-border-color;
|
||||
|
||||
}
|
||||
.tile .table {
|
||||
& > thead:not([class*="bg-"]) > tr > th {
|
||||
border-top: 1px solid @table-border-color;
|
||||
}
|
||||
}
|
||||
|
||||
.table-hover > tbody > tr:hover {
|
||||
background-color: #f4f4f4;
|
||||
background-color: #f4f4f4;
|
||||
}
|
||||
|
||||
.table-data {
|
||||
tbody > tr > td {
|
||||
padding-top: 5px !important;
|
||||
}
|
||||
|
||||
.btn-favourite, .btn-archive {
|
||||
font-size: 15px;
|
||||
}
|
||||
thead > tr > th {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
tbody > tr > td {
|
||||
padding-top: 5px !important;
|
||||
}
|
||||
|
||||
.btn-favourite,
|
||||
.btn-archive {
|
||||
font-size: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
.table-main-title {
|
||||
font-weight: 500;
|
||||
line-height: 1.7 !important;
|
||||
font-weight: 500;
|
||||
line-height: 1.7 !important;
|
||||
}
|
||||
|
||||
.btn-favourite {
|
||||
color: #d4d4d4;
|
||||
transition: all .25s ease-in-out;
|
||||
|
||||
&:hover, &:focus {
|
||||
color: @yellow-darker;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fa-star {
|
||||
color: @yellow-darker;
|
||||
}
|
||||
color: #d4d4d4;
|
||||
transition: all 0.25s ease-in-out;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
color: @yellow-darker;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fa-star {
|
||||
color: @yellow-darker;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-archive {
|
||||
color: #d4d4d4;
|
||||
transition: all .25s ease-in-out;
|
||||
|
||||
&:hover, &:focus {
|
||||
color: @gray-light;
|
||||
}
|
||||
|
||||
.fa-archive {
|
||||
color: @gray-light;
|
||||
}
|
||||
color: #d4d4d4;
|
||||
transition: all 0.25s ease-in-out;
|
||||
|
||||
&:hover,
|
||||
&:focus {
|
||||
color: @gray-light;
|
||||
}
|
||||
|
||||
.fa-archive {
|
||||
color: @gray-light;
|
||||
}
|
||||
}
|
||||
|
||||
.table > thead > tr > th {
|
||||
text-transform: none;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.table-data .label-tag {
|
||||
display: inline-block;
|
||||
max-width: 135px;
|
||||
}
|
||||
display: inline-block;
|
||||
max-width: 135px;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
/** Load Vendors Dependencies **/
|
||||
@import "~font-awesome/less/font-awesome";
|
||||
@import "~material-design-iconic-font/dist/css/material-design-iconic-font.css";
|
||||
@import "~pace-progress/themes/blue/pace-theme-minimal.css";
|
||||
|
||||
@import "inc/variables";
|
||||
@import "inc/mixins";
|
||||
|
||||
@@ -4,47 +4,18 @@ body.fixed-layout {
|
||||
|
||||
#application-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-direction: row;
|
||||
padding-bottom: 0;
|
||||
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
|
||||
> div {
|
||||
flex-grow: 1;
|
||||
.application-layout-content > div {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.bottom-controller {
|
||||
padding: 10px 15px;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
button,
|
||||
div,
|
||||
span {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
div:last-child {
|
||||
flex-grow: 1;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
&:before {
|
||||
content: "";
|
||||
height: 50px;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
pointer-events: none;
|
||||
left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.p-b-60 {
|
||||
padding-bottom: 60px !important;
|
||||
}
|
||||
@@ -101,9 +72,6 @@ body.fixed-layout {
|
||||
}
|
||||
}
|
||||
|
||||
.embed__vis {
|
||||
}
|
||||
|
||||
.query__vis {
|
||||
table {
|
||||
border: 1px solid #f0f0f0;
|
||||
@@ -122,6 +90,7 @@ body.fixed-layout {
|
||||
.embed__vis {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.embed-heading {
|
||||
@@ -140,6 +109,14 @@ body.fixed-layout {
|
||||
}
|
||||
}
|
||||
|
||||
// Don't let filters take all visualization space on query fixed layout
|
||||
.query-fixed-layout {
|
||||
.filters-wrapper {
|
||||
max-height: 40%;
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.page-header--new {
|
||||
.query-tags,
|
||||
.query-tags__mobile {
|
||||
@@ -150,25 +127,6 @@ body.fixed-layout {
|
||||
}
|
||||
}
|
||||
|
||||
.page-header--query {
|
||||
.page-title {
|
||||
display: block;
|
||||
margin-left: 15px;
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
.tags-control a {
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
.tags-control a {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a.label-tag {
|
||||
background: fade(@redash-gray, 15%);
|
||||
color: darken(@redash-gray, 15%);
|
||||
@@ -179,14 +137,11 @@ a.label-tag {
|
||||
}
|
||||
}
|
||||
|
||||
.schema-browser {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.query-page-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-grow: 1;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.query-fullscreen {
|
||||
@@ -195,7 +150,6 @@ a.label-tag {
|
||||
box-shadow: rgba(102, 136, 153, 0.15) 0 4px 9px -3px;
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
width: 100vw;
|
||||
|
||||
.resizable-component.react-resizable {
|
||||
.react-resizable-handle-horizontal {
|
||||
@@ -275,11 +229,6 @@ a.label-tag {
|
||||
align-content: space-around;
|
||||
padding: 0;
|
||||
overflow-x: hidden;
|
||||
|
||||
.pivot-table-visualization-container > table,
|
||||
.visualization-renderer > .visualization-renderer-wrapper {
|
||||
overflow: visible;
|
||||
}
|
||||
}
|
||||
.row {
|
||||
background: #fff;
|
||||
@@ -446,12 +395,10 @@ nav .rg-bottom {
|
||||
.query-tags {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
margin-top: -3px; // padding-top of tags
|
||||
}
|
||||
|
||||
.query-tags__mobile {
|
||||
display: none;
|
||||
padding: 0 0 0 23px;
|
||||
}
|
||||
|
||||
.table--permission {
|
||||
@@ -479,21 +426,6 @@ nav .rg-bottom {
|
||||
// Smaller screens
|
||||
|
||||
@media (max-width: 880px) {
|
||||
.page-header--query {
|
||||
.page-title {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.query-tags:not(.query-tags__empty) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.query-tags__mobile:not(.query-tags__empty) {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.btn--showhide,
|
||||
.query-actions-menu .dropdown-toggle {
|
||||
margin-bottom: 5px;
|
||||
@@ -547,13 +479,6 @@ nav .rg-bottom {
|
||||
}
|
||||
}
|
||||
|
||||
.query-page-wrapper {
|
||||
.container {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.datasource-small {
|
||||
visibility: visible;
|
||||
}
|
||||
@@ -569,12 +494,3 @@ nav .rg-bottom {
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Responsive fixes
|
||||
@media (max-width: 767px) {
|
||||
.query-page-wrapper {
|
||||
h3 {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.tag-separator {
|
||||
margin: 4px 3px 0 0;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ import AceEditor from "react-ace";
|
||||
|
||||
import "./AceEditorInput.less";
|
||||
|
||||
function AceEditorInput(props, ref) {
|
||||
function AceEditorInput(props: any, ref: any) {
|
||||
return (
|
||||
<div className="ace-editor-input">
|
||||
<div className="ace-editor-input" data-test={props["data-test"]}>
|
||||
<AceEditor
|
||||
ref={ref}
|
||||
mode="sql"
|
||||
@@ -1,79 +0,0 @@
|
||||
import React, { useState, useMemo, useCallback, useEffect } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { isEmpty, template } from "lodash";
|
||||
|
||||
import Dropdown from "antd/lib/dropdown";
|
||||
import Icon from "antd/lib/icon";
|
||||
import Menu from "antd/lib/menu";
|
||||
|
||||
import HelpTrigger from "@/components/HelpTrigger";
|
||||
|
||||
export default function FavoritesDropdown({ fetch, urlTemplate }) {
|
||||
const [items, setItems] = useState();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const noItems = isEmpty(items);
|
||||
const urlCompiled = useMemo(() => template(urlTemplate), [urlTemplate]);
|
||||
|
||||
const fetchItems = useCallback(
|
||||
(showLoadingState = true) => {
|
||||
setLoading(showLoadingState);
|
||||
fetch()
|
||||
.then(({ results }) => {
|
||||
setItems(results);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
},
|
||||
[fetch]
|
||||
);
|
||||
|
||||
// fetch items on init
|
||||
useEffect(() => {
|
||||
fetchItems(false);
|
||||
}, [fetchItems]);
|
||||
|
||||
// fetch items on click
|
||||
const onVisibleChange = visible => visible && fetchItems();
|
||||
|
||||
const menu = (
|
||||
<Menu className="favorites-dropdown">
|
||||
{noItems ? (
|
||||
<Menu.Item>
|
||||
<span className="btn-favourite m-r-5">
|
||||
<i className="fa fa-star" />
|
||||
</span>
|
||||
No favorites selected yet <HelpTrigger type="FAVORITES" />
|
||||
</Menu.Item>
|
||||
) : (
|
||||
items.map(item => (
|
||||
<Menu.Item key={item.id}>
|
||||
<a href={urlCompiled(item)}>
|
||||
<span className="btn-favourite m-r-5">
|
||||
<i className="fa fa-star" />
|
||||
</span>
|
||||
{item.name}
|
||||
</a>
|
||||
</Menu.Item>
|
||||
))
|
||||
)}
|
||||
</Menu>
|
||||
);
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
disabled={loading}
|
||||
trigger={["click"]}
|
||||
placement="bottomLeft"
|
||||
onVisibleChange={onVisibleChange}
|
||||
overlay={menu}>
|
||||
{loading ? <Icon type="loading" spin /> : <Icon type="down" />}
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
FavoritesDropdown.propTypes = {
|
||||
fetch: PropTypes.func.isRequired,
|
||||
urlTemplate: PropTypes.string.isRequired,
|
||||
};
|
||||
@@ -1,262 +0,0 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
|
||||
import React, { useCallback, useRef } from "react";
|
||||
|
||||
import Dropdown from "antd/lib/dropdown";
|
||||
import Button from "antd/lib/button";
|
||||
import Icon from "antd/lib/icon";
|
||||
import Menu from "antd/lib/menu";
|
||||
import Input from "antd/lib/input";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
|
||||
import HelpTrigger from "@/components/HelpTrigger";
|
||||
import CreateDashboardDialog from "@/components/dashboards/CreateDashboardDialog";
|
||||
import navigateTo from "@/components/ApplicationArea/navigateTo";
|
||||
|
||||
import { currentUser, Auth, clientConfig } from "@/services/auth";
|
||||
import { Dashboard } from "@/services/dashboard";
|
||||
import { Query } from "@/services/query";
|
||||
import frontendVersion from "@/version.json";
|
||||
import logoUrl from "@/assets/images/redash_icon_small.png";
|
||||
|
||||
import FavoritesDropdown from "./FavoritesDropdown";
|
||||
import "./index.less";
|
||||
|
||||
function onSearch(q) {
|
||||
navigateTo(`queries?q=${encodeURIComponent(q)}`);
|
||||
}
|
||||
|
||||
function DesktopNavbar() {
|
||||
const showCreateDashboardDialog = useCallback(() => {
|
||||
CreateDashboardDialog.showModal().result.catch(() => {}); // ignore dismiss
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="app-header" data-platform="desktop">
|
||||
<div>
|
||||
<Menu mode="horizontal" selectable={false}>
|
||||
{currentUser.hasPermission("list_dashboards") && (
|
||||
<Menu.Item key="dashboards" className="dropdown-menu-item">
|
||||
<Button href="dashboards">Dashboards</Button>
|
||||
<FavoritesDropdown fetch={Dashboard.favorites} urlTemplate="dashboard/${slug}" />
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("view_query") && (
|
||||
<Menu.Item key="queries" className="dropdown-menu-item">
|
||||
<Button href="queries">Queries</Button>
|
||||
<FavoritesDropdown fetch={Query.favorites} urlTemplate="queries/${id}" />
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("list_alerts") && (
|
||||
<Menu.Item key="alerts">
|
||||
<Button href="alerts">Alerts</Button>
|
||||
</Menu.Item>
|
||||
)}
|
||||
</Menu>
|
||||
{currentUser.canCreate() && (
|
||||
<Dropdown
|
||||
trigger={["click"]}
|
||||
overlay={
|
||||
<Menu>
|
||||
{currentUser.hasPermission("create_query") && (
|
||||
<Menu.Item key="new-query">
|
||||
<a href="queries/new">New Query</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("create_dashboard") && (
|
||||
<Menu.Item key="new-dashboard">
|
||||
<a onMouseUp={showCreateDashboardDialog}>New Dashboard</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("list_alerts") && (
|
||||
<Menu.Item key="new-alert">
|
||||
<a href="alerts/new">New Alert</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
</Menu>
|
||||
}>
|
||||
<Button type="primary" data-test="CreateButton">
|
||||
Create <Icon type="down" />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
)}
|
||||
</div>
|
||||
<div className="header-logo">
|
||||
<a href="./">
|
||||
<img src={logoUrl} alt="Redash" />
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<Input.Search
|
||||
className="searchbar"
|
||||
placeholder="Search queries..."
|
||||
data-test="AppHeaderSearch"
|
||||
onSearch={onSearch}
|
||||
/>
|
||||
<Menu mode="horizontal" selectable={false}>
|
||||
<Menu.Item key="help">
|
||||
<HelpTrigger type="HOME" className="menu-item-button" />
|
||||
</Menu.Item>
|
||||
{currentUser.isAdmin && (
|
||||
<Menu.Item key="settings">
|
||||
<Tooltip title="Settings">
|
||||
<Button href="data_sources" className="menu-item-button">
|
||||
<i className="fa fa-sliders" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Menu.Item>
|
||||
)}
|
||||
<Menu.Item key="profile">
|
||||
<Dropdown
|
||||
overlayStyle={{ minWidth: 200 }}
|
||||
placement="bottomRight"
|
||||
trigger={["click"]}
|
||||
overlay={
|
||||
<Menu>
|
||||
<Menu.Item key="profile">
|
||||
<a href="users/me">Edit Profile</a>
|
||||
</Menu.Item>
|
||||
{currentUser.hasPermission("super_admin") && <Menu.Divider />}
|
||||
{currentUser.isAdmin && (
|
||||
<Menu.Item key="datasources">
|
||||
<a href="data_sources">Data Sources</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("list_users") && (
|
||||
<Menu.Item key="groups">
|
||||
<a href="groups">Groups</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("list_users") && (
|
||||
<Menu.Item key="users">
|
||||
<a href="users">Users</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("create_query") && (
|
||||
<Menu.Item key="snippets">
|
||||
<a href="query_snippets">Query Snippets</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.isAdmin && (
|
||||
<Menu.Item key="destinations">
|
||||
<a href="destinations">Alert Destinations</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("super_admin") && <Menu.Divider />}
|
||||
{currentUser.hasPermission("super_admin") && (
|
||||
<Menu.Item key="status">
|
||||
<a href="admin/status">System Status</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
<Menu.Divider />
|
||||
<Menu.Item key="logout" onClick={() => Auth.logout()}>
|
||||
Log out
|
||||
</Menu.Item>
|
||||
<Menu.Divider />
|
||||
<Menu.Item key="version" disabled>
|
||||
Version: {clientConfig.version}
|
||||
{frontendVersion !== clientConfig.version && ` (${frontendVersion.substring(0, 8)})`}
|
||||
{clientConfig.newVersionAvailable && currentUser.hasPermission("super_admin") && (
|
||||
<Tooltip title="Update Available" placement="rightTop">
|
||||
{" "}
|
||||
{/* eslint-disable react/jsx-no-target-blank */}
|
||||
<a
|
||||
href="https://version.redash.io/"
|
||||
className="update-available"
|
||||
target="_blank"
|
||||
rel="noopener">
|
||||
<i className="fa fa-arrow-circle-down" />
|
||||
</a>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
}>
|
||||
<Button data-test="ProfileDropdown" className="profile-dropdown">
|
||||
<img src={currentUser.profile_image_url} alt={currentUser.name} />
|
||||
<span>{currentUser.name}</span>
|
||||
<Icon type="down" />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MobileNavbar() {
|
||||
const ref = useRef();
|
||||
|
||||
return (
|
||||
<div className="app-header" data-platform="mobile" ref={ref}>
|
||||
<div className="header-logo">
|
||||
<a href="./">
|
||||
<img src={logoUrl} alt="Redash" />
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<Dropdown
|
||||
overlayStyle={{ minWidth: 200 }}
|
||||
trigger={["click"]}
|
||||
getPopupContainer={() => ref.current} // so the overlay menu stays with the fixed header when page scrolls
|
||||
overlay={
|
||||
<Menu mode="vertical" selectable={false}>
|
||||
{currentUser.hasPermission("list_dashboards") && (
|
||||
<Menu.Item key="dashboards">
|
||||
<a href="dashboards">Dashboards</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("view_query") && (
|
||||
<Menu.Item key="queries">
|
||||
<a href="queries">Queries</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("list_alerts") && (
|
||||
<Menu.Item key="alerts">
|
||||
<a href="alerts">Alerts</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
<Menu.Item key="profile">
|
||||
<a href="users/me">Edit Profile</a>
|
||||
</Menu.Item>
|
||||
<Menu.Divider />
|
||||
{currentUser.isAdmin && (
|
||||
<Menu.Item key="settings">
|
||||
<a href="data_sources">Settings</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("super_admin") && (
|
||||
<Menu.Item key="status">
|
||||
<a href="admin/status">System Status</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{currentUser.hasPermission("super_admin") && <Menu.Divider />}
|
||||
<Menu.Item key="help">
|
||||
{/* eslint-disable-next-line react/jsx-no-target-blank */}
|
||||
<a href="https://redash.io/help" target="_blank" rel="noopener">
|
||||
Help
|
||||
</a>
|
||||
</Menu.Item>
|
||||
<Menu.Item key="logout" onClick={() => Auth.logout()}>
|
||||
Log out
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
}>
|
||||
<Button>
|
||||
<Icon type="menu" />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ApplicationHeader() {
|
||||
return (
|
||||
<nav className="app-header-wrapper">
|
||||
<DesktopNavbar />
|
||||
<MobileNavbar />
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
@mobileBreakpoint: ~"(max-width: 767px)";
|
||||
|
||||
nav .app-header {
|
||||
height: 49px;
|
||||
padding-bottom: 1px;
|
||||
box-sizing: content-box;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10px;
|
||||
background: white;
|
||||
box-shadow: 0 4px 9px -3px rgba(102, 136, 153, 0.15);
|
||||
|
||||
.darker {
|
||||
color: #333 !important;
|
||||
|
||||
&:hover {
|
||||
color: #2196f3 !important;
|
||||
}
|
||||
}
|
||||
|
||||
& > * {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&[data-platform="mobile"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu-item-button {
|
||||
padding: 0 15px;
|
||||
font-size: 18px;
|
||||
.darker();
|
||||
}
|
||||
|
||||
.ant-menu-root {
|
||||
margin: 0 10px;
|
||||
line-height: 50px;
|
||||
height: 50px;
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.ant-btn {
|
||||
font-weight: 500;
|
||||
|
||||
.anticon {
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&[data-platform="desktop"] .ant-btn:not(.ant-btn-primary) {
|
||||
border: 0;
|
||||
box-shadow: none;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
background-color: transparent; //so it doesn't interfere with click animation of adjacent buttons
|
||||
.darker();
|
||||
}
|
||||
|
||||
.ant-menu-item {
|
||||
padding: 0;
|
||||
height: 52px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
.anticon-down {
|
||||
font-size: 13px !important;
|
||||
transform: none;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
|
||||
svg {
|
||||
transition: transform 0.2s cubic-bezier(0.75, 0, 0.25, 1);
|
||||
}
|
||||
}
|
||||
|
||||
.ant-dropdown-open .anticon-down svg,
|
||||
.anticon-down.ant-dropdown-open svg {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown-menu-item {
|
||||
.ant-btn {
|
||||
padding-right: 5px;
|
||||
padding-left: 5px;
|
||||
margin-right: 30px;
|
||||
margin-left: 10px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
// this is a trick to get the dropdown menu to be placed at the bottom left
|
||||
// of the menu item and not the dropdown trigger
|
||||
.ant-dropdown-trigger {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 0;
|
||||
left: 10px;
|
||||
bottom: 5px;
|
||||
text-align: right;
|
||||
padding-top: 14px;
|
||||
padding-right: 10px;
|
||||
margin-right: 0;
|
||||
user-select: none; // or else double clicking it causes the header logo to get selected
|
||||
.darker();
|
||||
}
|
||||
}
|
||||
|
||||
.header-logo img {
|
||||
height: 40px;
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.searchbar {
|
||||
width: 185px;
|
||||
}
|
||||
|
||||
.profile-dropdown {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
span {
|
||||
max-width: 130px; // arbitrary, prevents layout mess up if username long
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
img {
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
border-radius: 50%;
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.ant-btn,
|
||||
.menu-item-button {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.ant-menu-root {
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.profile-dropdown {
|
||||
span {
|
||||
display: none;
|
||||
}
|
||||
|
||||
img {
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.searchbar {
|
||||
width: 140px;
|
||||
}
|
||||
}
|
||||
|
||||
@media @mobileBreakpoint {
|
||||
&[data-platform="desktop"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&[data-platform="mobile"] {
|
||||
display: flex;
|
||||
padding: 0 15px;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
z-index: 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media @mobileBreakpoint {
|
||||
.app-header-wrapper {
|
||||
margin-top: 59px !important; // compensate for app header fixed position
|
||||
}
|
||||
}
|
||||
|
||||
.update-available {
|
||||
display: inline !important;
|
||||
|
||||
.fa {
|
||||
color: #52c41a;
|
||||
vertical-align: text-bottom;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-dropdown-menu-item .help-trigger {
|
||||
display: inline;
|
||||
color: #2196f3;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
.ant-dropdown-menu.favorites-dropdown {
|
||||
margin-left: -10px;
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
@backgroundColor: #001529;
|
||||
@dividerColor: rgba(255, 255, 255, 0.5);
|
||||
@textColor: rgba(255, 255, 255, 0.75);
|
||||
@brandColor: #ff7964; // Redash logo color
|
||||
@activeItemColor: @brandColor;
|
||||
@iconSize: 26px;
|
||||
|
||||
.desktop-navbar {
|
||||
background: @backgroundColor;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
width: 80px;
|
||||
overflow: hidden;
|
||||
|
||||
&-spacer {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
&-logo.ant-menu {
|
||||
padding-top: 20px;
|
||||
padding-bottom: 20px;
|
||||
text-align: center;
|
||||
|
||||
img {
|
||||
height: 40px;
|
||||
transition: all 270ms;
|
||||
}
|
||||
}
|
||||
|
||||
.help-trigger {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.ant-menu {
|
||||
.ant-menu-item,
|
||||
.ant-menu-submenu {
|
||||
font-weight: 500;
|
||||
color: @textColor;
|
||||
|
||||
&.navbar-active-item {
|
||||
box-shadow: inset 3px 0 0 @activeItemColor;
|
||||
|
||||
.anticon {
|
||||
color: @activeItemColor;
|
||||
}
|
||||
}
|
||||
|
||||
&.ant-menu-submenu-open,
|
||||
&.ant-menu-submenu-active,
|
||||
&:hover,
|
||||
&:active {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.anticon {
|
||||
font-size: @iconSize;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.desktop-navbar-label {
|
||||
margin-top: 4px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
a,
|
||||
span,
|
||||
.anticon {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu-submenu-arrow {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ant-menu-item,
|
||||
.ant-menu-submenu {
|
||||
padding: 0;
|
||||
height: 60px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.ant-menu-submenu-title {
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
a,
|
||||
&.ant-menu-vertical > .ant-menu-submenu > .ant-menu-submenu-title,
|
||||
.ant-menu-submenu-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
line-height: normal;
|
||||
height: auto;
|
||||
background: none;
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.desktop-navbar-profile-menu {
|
||||
.desktop-navbar-profile-menu-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
|
||||
.profile__image_thumb {
|
||||
margin: 0;
|
||||
vertical-align: middle;
|
||||
width: @iconSize;
|
||||
height: @iconSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.desktop-navbar-submenu {
|
||||
.ant-menu {
|
||||
.ant-menu-item-divider {
|
||||
background: @dividerColor;
|
||||
}
|
||||
|
||||
.ant-menu-item {
|
||||
font-weight: 500;
|
||||
color: @textColor;
|
||||
|
||||
&:hover,
|
||||
&:active {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
a,
|
||||
span,
|
||||
.anticon {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.zmdi,
|
||||
.fa {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
&.version-info {
|
||||
height: auto;
|
||||
line-height: normal;
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
|
||||
a {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
|
||||
&:hover,
|
||||
&:active {
|
||||
color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import React, { useMemo } from "react";
|
||||
import { first, includes } from "lodash";
|
||||
import Menu from "antd/lib/menu";
|
||||
import Link from "@/components/Link";
|
||||
import HelpTrigger from "@/components/HelpTrigger";
|
||||
import CreateDashboardDialog from "@/components/dashboards/CreateDashboardDialog";
|
||||
import { useCurrentRoute } from "@/components/ApplicationArea/Router";
|
||||
import { Auth, currentUser } from "@/services/auth";
|
||||
import settingsMenu from "@/services/settingsMenu";
|
||||
// @ts-expect-error ts-migrate(2307) FIXME: Cannot find module '@/assets/images/redash_icon_sm... Remove this comment to see the full error message
|
||||
import logoUrl from "@/assets/images/redash_icon_small.png";
|
||||
import DesktopOutlinedIcon from "@ant-design/icons/DesktopOutlined";
|
||||
import CodeOutlinedIcon from "@ant-design/icons/CodeOutlined";
|
||||
import AlertOutlinedIcon from "@ant-design/icons/AlertOutlined";
|
||||
import PlusOutlinedIcon from "@ant-design/icons/PlusOutlined";
|
||||
import QuestionCircleOutlinedIcon from "@ant-design/icons/QuestionCircleOutlined";
|
||||
import SettingOutlinedIcon from "@ant-design/icons/SettingOutlined";
|
||||
import VersionInfo from "./VersionInfo";
|
||||
import "./DesktopNavbar.less";
|
||||
function NavbarSection({ children, ...props }: any) {
|
||||
return (<Menu selectable={false} mode="vertical" theme="dark" {...props}>
|
||||
{children}
|
||||
</Menu>);
|
||||
}
|
||||
function useNavbarActiveState() {
|
||||
const currentRoute = useCurrentRoute();
|
||||
return useMemo(() => ({
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
dashboards: includes(["Dashboards.List", "Dashboards.Favorites", "Dashboards.ViewOrEdit", "Dashboards.LegacyViewOrEdit"], currentRoute.id),
|
||||
queries: includes([
|
||||
"Queries.List",
|
||||
"Queries.Favorites",
|
||||
"Queries.Archived",
|
||||
"Queries.My",
|
||||
"Queries.View",
|
||||
"Queries.New",
|
||||
"Queries.Edit",
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
], currentRoute.id),
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
dataSources: includes(["DataSources.List"], currentRoute.id),
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
alerts: includes(["Alerts.List", "Alerts.New", "Alerts.View", "Alerts.Edit"], currentRoute.id),
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
}), [currentRoute.id]);
|
||||
}
|
||||
export default function DesktopNavbar() {
|
||||
const firstSettingsTab = first(settingsMenu.getAvailableItems());
|
||||
const activeState = useNavbarActiveState();
|
||||
const canCreateQuery = currentUser.hasPermission("create_query");
|
||||
const canCreateDashboard = currentUser.hasPermission("create_dashboard");
|
||||
const canCreateAlert = currentUser.hasPermission("list_alerts");
|
||||
return (<div className="desktop-navbar">
|
||||
<NavbarSection className="desktop-navbar-logo">
|
||||
<div>
|
||||
<Link href="./">
|
||||
<img src={logoUrl} alt="Redash"/>
|
||||
</Link>
|
||||
</div>
|
||||
</NavbarSection>
|
||||
|
||||
<NavbarSection>
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
{currentUser.hasPermission("list_dashboards") && (<Menu.Item key="dashboards" className={activeState.dashboards ? "navbar-active-item" : null}>
|
||||
<Link href="dashboards">
|
||||
<DesktopOutlinedIcon />
|
||||
<span className="desktop-navbar-label">Dashboards</span>
|
||||
</Link>
|
||||
</Menu.Item>)}
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
{currentUser.hasPermission("view_query") && (<Menu.Item key="queries" className={activeState.queries ? "navbar-active-item" : null}>
|
||||
<Link href="queries">
|
||||
<CodeOutlinedIcon />
|
||||
<span className="desktop-navbar-label">Queries</span>
|
||||
</Link>
|
||||
</Menu.Item>)}
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
{currentUser.hasPermission("list_alerts") && (<Menu.Item key="alerts" className={activeState.alerts ? "navbar-active-item" : null}>
|
||||
<Link href="alerts">
|
||||
<AlertOutlinedIcon />
|
||||
<span className="desktop-navbar-label">Alerts</span>
|
||||
</Link>
|
||||
</Menu.Item>)}
|
||||
</NavbarSection>
|
||||
|
||||
<NavbarSection className="desktop-navbar-spacer">
|
||||
{(canCreateQuery || canCreateDashboard || canCreateAlert) && (<Menu.SubMenu key="create" popupClassName="desktop-navbar-submenu" data-test="CreateButton" title={<React.Fragment>
|
||||
<PlusOutlinedIcon />
|
||||
<span className="desktop-navbar-label">Create</span>
|
||||
</React.Fragment>}>
|
||||
{canCreateQuery && (<Menu.Item key="new-query">
|
||||
<Link href="queries/new" data-test="CreateQueryMenuItem">
|
||||
New Query
|
||||
</Link>
|
||||
</Menu.Item>)}
|
||||
{canCreateDashboard && (<Menu.Item key="new-dashboard">
|
||||
{/* @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. */}
|
||||
<a data-test="CreateDashboardMenuItem" onMouseUp={() => CreateDashboardDialog.showModal()}>
|
||||
New Dashboard
|
||||
</a>
|
||||
</Menu.Item>)}
|
||||
{canCreateAlert && (<Menu.Item key="new-alert">
|
||||
<Link data-test="CreateAlertMenuItem" href="alerts/new">
|
||||
New Alert
|
||||
</Link>
|
||||
</Menu.Item>)}
|
||||
</Menu.SubMenu>)}
|
||||
</NavbarSection>
|
||||
|
||||
<NavbarSection>
|
||||
<Menu.Item key="help">
|
||||
{/* @ts-expect-error ts-migrate(2746) FIXME: This JSX tag's 'children' prop expects a single ch... Remove this comment to see the full error message */}
|
||||
<HelpTrigger showTooltip={false} type="HOME">
|
||||
<QuestionCircleOutlinedIcon />
|
||||
<span className="desktop-navbar-label">Help</span>
|
||||
</HelpTrigger>
|
||||
</Menu.Item>
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
{firstSettingsTab && (<Menu.Item key="settings" className={activeState.dataSources ? "navbar-active-item" : null}>
|
||||
<Link href={(firstSettingsTab as any).path} data-test="SettingsLink">
|
||||
<SettingOutlinedIcon />
|
||||
<span className="desktop-navbar-label">Settings</span>
|
||||
</Link>
|
||||
</Menu.Item>)}
|
||||
</NavbarSection>
|
||||
|
||||
<NavbarSection className="desktop-navbar-profile-menu">
|
||||
<Menu.SubMenu key="profile" popupClassName="desktop-navbar-submenu" title={<span data-test="ProfileDropdown" className="desktop-navbar-profile-menu-title">
|
||||
<img className="profile__image_thumb" src={(currentUser as any).profile_image_url} alt={(currentUser as any).name}/>
|
||||
</span>}>
|
||||
<Menu.Item key="profile">
|
||||
<Link href="users/me">Profile</Link>
|
||||
</Menu.Item>
|
||||
{currentUser.hasPermission("super_admin") && (<Menu.Item key="status">
|
||||
<Link href="admin/status">System Status</Link>
|
||||
</Menu.Item>)}
|
||||
<Menu.Divider />
|
||||
<Menu.Item key="logout">
|
||||
<a data-test="LogOutButton" onClick={() => Auth.logout()}>
|
||||
Log out
|
||||
</a>
|
||||
</Menu.Item>
|
||||
<Menu.Divider />
|
||||
<Menu.Item key="version" disabled className="version-info">
|
||||
<VersionInfo />
|
||||
</Menu.Item>
|
||||
</Menu.SubMenu>
|
||||
</NavbarSection>
|
||||
</div>);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
@backgroundColor: #001529;
|
||||
@dividerColor: rgba(255, 255, 255, 0.5);
|
||||
@textColor: rgba(255, 255, 255, 0.75);
|
||||
|
||||
.mobile-navbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: @backgroundColor;
|
||||
box-shadow: 0 4px 9px -3px rgba(102, 136, 153, 0.15);
|
||||
padding: 0 15px;
|
||||
height: 100%;
|
||||
|
||||
&-logo {
|
||||
img {
|
||||
height: 40px;
|
||||
width: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-btn.mobile-navbar-toggle-button {
|
||||
padding: 0 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.mobile-navbar-menu {
|
||||
.ant-dropdown-menu-item {
|
||||
font-weight: 500;
|
||||
color: @textColor;
|
||||
}
|
||||
|
||||
.ant-dropdown-menu-item-divider {
|
||||
background: @dividerColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { first } from "lodash";
|
||||
import React from "react";
|
||||
import Button from "antd/lib/button";
|
||||
import MenuOutlinedIcon from "@ant-design/icons/MenuOutlined";
|
||||
import Dropdown from "antd/lib/dropdown";
|
||||
import Menu from "antd/lib/menu";
|
||||
import Link from "@/components/Link";
|
||||
import { Auth, currentUser } from "@/services/auth";
|
||||
import settingsMenu from "@/services/settingsMenu";
|
||||
// @ts-expect-error ts-migrate(2307) FIXME: Cannot find module '@/assets/images/redash_icon_sm... Remove this comment to see the full error message
|
||||
import logoUrl from "@/assets/images/redash_icon_small.png";
|
||||
import "./MobileNavbar.less";
|
||||
type OwnProps = {
|
||||
getPopupContainer?: (...args: any[]) => any;
|
||||
};
|
||||
type Props = OwnProps & typeof MobileNavbar.defaultProps;
|
||||
export default function MobileNavbar({ getPopupContainer }: Props) {
|
||||
const firstSettingsTab = first(settingsMenu.getAvailableItems());
|
||||
return (<div className="mobile-navbar">
|
||||
<div className="mobile-navbar-logo">
|
||||
<Link href="./">
|
||||
<img src={logoUrl} alt="Redash"/>
|
||||
</Link>
|
||||
</div>
|
||||
<div>
|
||||
<Dropdown overlayStyle={{ minWidth: 200 }} trigger={["click"]} getPopupContainer={getPopupContainer} // so the overlay menu stays with the fixed header when page scrolls
|
||||
overlay={<Menu mode="vertical" theme="dark" selectable={false} className="mobile-navbar-menu">
|
||||
{currentUser.hasPermission("list_dashboards") && (<Menu.Item key="dashboards">
|
||||
<Link href="dashboards">Dashboards</Link>
|
||||
</Menu.Item>)}
|
||||
{currentUser.hasPermission("view_query") && (<Menu.Item key="queries">
|
||||
<Link href="queries">Queries</Link>
|
||||
</Menu.Item>)}
|
||||
{currentUser.hasPermission("list_alerts") && (<Menu.Item key="alerts">
|
||||
<Link href="alerts">Alerts</Link>
|
||||
</Menu.Item>)}
|
||||
<Menu.Item key="profile">
|
||||
<Link href="users/me">Edit Profile</Link>
|
||||
</Menu.Item>
|
||||
<Menu.Divider />
|
||||
{firstSettingsTab && (<Menu.Item key="settings">
|
||||
<Link href={(firstSettingsTab as any).path}>Settings</Link>
|
||||
</Menu.Item>)}
|
||||
{currentUser.hasPermission("super_admin") && (<Menu.Item key="status">
|
||||
<Link href="admin/status">System Status</Link>
|
||||
</Menu.Item>)}
|
||||
{currentUser.hasPermission("super_admin") && <Menu.Divider />}
|
||||
<Menu.Item key="help">
|
||||
|
||||
<Link href="https://redash.io/help" target="_blank" rel="noopener">
|
||||
Help
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
<Menu.Item key="logout" onClick={() => Auth.logout()}>
|
||||
Log out
|
||||
</Menu.Item>
|
||||
</Menu>}>
|
||||
<Button className="mobile-navbar-toggle-button" ghost>
|
||||
<MenuOutlinedIcon />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>);
|
||||
}
|
||||
MobileNavbar.defaultProps = {
|
||||
getPopupContainer: null,
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from "react";
|
||||
import Link from "@/components/Link";
|
||||
import { clientConfig, currentUser } from "@/services/auth";
|
||||
// @ts-expect-error ts-migrate(7042) FIXME: Module '@/version.json' was resolved to '/Users/el... Remove this comment to see the full error message
|
||||
import frontendVersion from "@/version.json";
|
||||
export default function VersionInfo() {
|
||||
return (<React.Fragment>
|
||||
<div>
|
||||
Version: {(clientConfig as any).version}
|
||||
{frontendVersion !== (clientConfig as any).version && ` (${frontendVersion.substring(0, 8)})`}
|
||||
</div>
|
||||
{(clientConfig as any).newVersionAvailable && currentUser.hasPermission("super_admin") && (<div className="m-t-10">
|
||||
|
||||
<Link href="https://version.redash.io/" className="update-available" target="_blank" rel="noopener">
|
||||
Update Available
|
||||
<i className="fa fa-external-link m-l-5"/>
|
||||
</Link>
|
||||
</div>)}
|
||||
</React.Fragment>);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
@mobileBreakpoint: ~"(max-width: 767px)";
|
||||
|
||||
body #application-root {
|
||||
@topMenuHeight: 49px;
|
||||
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: stretch;
|
||||
padding-bottom: 0 !important;
|
||||
height: 100vh;
|
||||
|
||||
.application-layout-side-menu {
|
||||
height: 100vh;
|
||||
position: relative;
|
||||
|
||||
@media @mobileBreakpoint {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.application-layout-top-menu {
|
||||
height: @topMenuHeight;
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
z-index: 1000;
|
||||
|
||||
@media @mobileBreakpoint {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.application-layout-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
|
||||
flex: 1 1 auto;
|
||||
padding-bottom: 15px;
|
||||
|
||||
@media @mobileBreakpoint {
|
||||
margin-top: @topMenuHeight; // compensate for app header fixed position
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body.fixed-layout #application-root {
|
||||
.application-layout-content {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
body.headless #application-root {
|
||||
.application-layout-side-menu,
|
||||
.application-layout-top-menu {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.application-layout-content {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Fixes for proper snapshots in Percy (move vertical scroll to body level
|
||||
// to capture entire page, otherwise it wll be cut by viewport)
|
||||
@media only percy {
|
||||
body #application-root {
|
||||
height: auto;
|
||||
|
||||
.application-layout-side-menu {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.application-layout-content {
|
||||
overflow: visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import React, { useRef, useCallback } from "react";
|
||||
import DynamicComponent from "@/components/DynamicComponent";
|
||||
import DesktopNavbar from "./DesktopNavbar";
|
||||
import MobileNavbar from "./MobileNavbar";
|
||||
|
||||
import "./index.less";
|
||||
|
||||
type OwnProps = {
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
type Props = OwnProps & typeof ApplicationLayout.defaultProps;
|
||||
|
||||
export default function ApplicationLayout({ children }: Props) {
|
||||
const mobileNavbarContainerRef = useRef();
|
||||
|
||||
const getMobileNavbarPopupContainer = useCallback(() => mobileNavbarContainerRef.current, []);
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
{/* @ts-expect-error ts-migrate(2746) FIXME: This JSX tag's 'children' prop expects a single ch... Remove this comment to see the full error message */}
|
||||
<DynamicComponent name="ApplicationWrapper">
|
||||
<div className="application-layout-side-menu">
|
||||
<DynamicComponent name="ApplicationDesktopNavbar">
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
<DesktopNavbar />
|
||||
</DynamicComponent>
|
||||
</div>
|
||||
<div className="application-layout-content">
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'MutableRefObject<undefined>' is not assignab... Remove this comment to see the full error message */}
|
||||
<nav className="application-layout-top-menu" ref={mobileNavbarContainerRef}>
|
||||
<DynamicComponent name="ApplicationMobileNavbar" getPopupContainer={getMobileNavbarPopupContainer}>
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
<MobileNavbar getPopupContainer={getMobileNavbarPopupContainer} />
|
||||
</DynamicComponent>
|
||||
</nav>
|
||||
{children}
|
||||
</div>
|
||||
</DynamicComponent>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
ApplicationLayout.defaultProps = {
|
||||
children: null,
|
||||
};
|
||||
@@ -1,59 +0,0 @@
|
||||
import { isObject, get } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
function getErrorMessageByStatus(status, defaultMessage) {
|
||||
switch (status) {
|
||||
case 404:
|
||||
return "It seems like the page you're looking for cannot be found.";
|
||||
case 401:
|
||||
case 403:
|
||||
return "It seems like you don’t have permission to see this page.";
|
||||
default:
|
||||
return defaultMessage;
|
||||
}
|
||||
}
|
||||
|
||||
export function getErrorMessage(error) {
|
||||
const message = "It seems like we encountered an error. Try refreshing this page or contact your administrator.";
|
||||
if (isObject(error)) {
|
||||
// HTTP errors
|
||||
if (error.isAxiosError && isObject(error.response)) {
|
||||
return getErrorMessageByStatus(error.response.status, get(error, "response.data.message", message));
|
||||
}
|
||||
// Router errors
|
||||
if (error.status) {
|
||||
return getErrorMessageByStatus(error.status, message);
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
export default function ErrorMessage({ error }) {
|
||||
if (!error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
console.error(error);
|
||||
|
||||
return (
|
||||
<div className="fixed-container" data-test="ErrorMessage">
|
||||
<div className="container">
|
||||
<div className="col-md-8 col-md-push-2">
|
||||
<div className="error-state bg-white tiled">
|
||||
<div className="error-state__icon">
|
||||
<i className="zmdi zmdi-alert-circle-o" />
|
||||
</div>
|
||||
<div className="error-state__details">
|
||||
<h4>{getErrorMessage(error)}</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
ErrorMessage.propTypes = {
|
||||
error: PropTypes.object.isRequired,
|
||||
};
|
||||
17
client/app/components/ApplicationArea/ErrorMessage.less
Normal file
17
client/app/components/ApplicationArea/ErrorMessage.less
Normal file
@@ -0,0 +1,17 @@
|
||||
.error-message-container {
|
||||
width: 100%;
|
||||
padding: 0 15px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
|
||||
.error-state {
|
||||
max-width: 1200px;
|
||||
width: 100%;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
width: 65%;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
client/app/components/ApplicationArea/ErrorMessage.test.tsx
Normal file
40
client/app/components/ApplicationArea/ErrorMessage.test.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from "react";
|
||||
import { mount } from "enzyme";
|
||||
import ErrorMessage from "./ErrorMessage";
|
||||
const ErrorMessages = {
|
||||
UNAUTHORIZED: "It seems like you don’t have permission to see this page.",
|
||||
NOT_FOUND: "It seems like the page you're looking for cannot be found.",
|
||||
GENERIC: "It seems like we encountered an error. Try refreshing this page or contact your administrator.",
|
||||
};
|
||||
function mockAxiosError(status = 500, response = {}) {
|
||||
const error = new Error(`Failed with code ${status}.`);
|
||||
(error as any).isAxiosError = true;
|
||||
(error as any).response = { status, ...response };
|
||||
return error;
|
||||
}
|
||||
describe("Error Message", () => {
|
||||
const spyError = jest.spyOn(console, "error");
|
||||
beforeEach(() => {
|
||||
spyError.mockReset();
|
||||
});
|
||||
function expectErrorMessageToBe(error: any, errorMessage: any) {
|
||||
const component = mount(<ErrorMessage error={error}/>);
|
||||
expect(component.find(".error-state__details h4").text()).toBe(errorMessage);
|
||||
expect(spyError).toHaveBeenCalledWith(error);
|
||||
}
|
||||
test("displays a generic message on adhoc errors", () => {
|
||||
expectErrorMessageToBe(new Error("technical information"), ErrorMessages.GENERIC);
|
||||
});
|
||||
test("displays a not found message on axios errors with 404 code", () => {
|
||||
expectErrorMessageToBe(mockAxiosError(404), ErrorMessages.NOT_FOUND);
|
||||
});
|
||||
test("displays a unauthorized message on axios errors with 401 code", () => {
|
||||
expectErrorMessageToBe(mockAxiosError(401), ErrorMessages.UNAUTHORIZED);
|
||||
});
|
||||
test("displays a unauthorized message on axios errors with 403 code", () => {
|
||||
expectErrorMessageToBe(mockAxiosError(403), ErrorMessages.UNAUTHORIZED);
|
||||
});
|
||||
test("displays a generic message on axios errors with 500 code", () => {
|
||||
expectErrorMessageToBe(mockAxiosError(500), ErrorMessages.GENERIC);
|
||||
});
|
||||
});
|
||||
54
client/app/components/ApplicationArea/ErrorMessage.tsx
Normal file
54
client/app/components/ApplicationArea/ErrorMessage.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import { get, isObject } from "lodash";
|
||||
import React from "react";
|
||||
import "./ErrorMessage.less";
|
||||
import DynamicComponent from "@/components/DynamicComponent";
|
||||
import { ErrorMessageDetails } from "@/components/ApplicationArea/ErrorMessageDetails";
|
||||
function getErrorMessageByStatus(status: any, defaultMessage: any) {
|
||||
switch (status) {
|
||||
case 404:
|
||||
return "It seems like the page you're looking for cannot be found.";
|
||||
case 401:
|
||||
case 403:
|
||||
return "It seems like you don’t have permission to see this page.";
|
||||
default:
|
||||
return defaultMessage;
|
||||
}
|
||||
}
|
||||
function getErrorMessage(error: any) {
|
||||
const message = "It seems like we encountered an error. Try refreshing this page or contact your administrator.";
|
||||
if (isObject(error)) {
|
||||
// HTTP errors
|
||||
if ((error as any).isAxiosError && isObject((error as any).response)) {
|
||||
return getErrorMessageByStatus((error as any).response.status, get(error, "response.data.message", message));
|
||||
}
|
||||
// Router errors
|
||||
if ((error as any).status) {
|
||||
return getErrorMessageByStatus((error as any).status, message);
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
type Props = {
|
||||
error: any;
|
||||
message?: string;
|
||||
};
|
||||
export default function ErrorMessage({ error, message }: Props) {
|
||||
if (!error) {
|
||||
return null;
|
||||
}
|
||||
console.error(error);
|
||||
const errorDetailsProps = {
|
||||
error,
|
||||
message: message || getErrorMessage(error),
|
||||
};
|
||||
return (<div className="error-message-container" data-test="ErrorMessage" role="alert">
|
||||
<div className="error-state bg-white tiled">
|
||||
<div className="error-state__icon">
|
||||
<i className="zmdi zmdi-alert-circle-o"/>
|
||||
</div>
|
||||
<div className="error-state__details">
|
||||
<DynamicComponent name="ErrorMessageDetails" fallback={<ErrorMessageDetails {...errorDetailsProps}/>} {...errorDetailsProps}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
error: any; // TODO: PropTypes.instanceOf(Error)
|
||||
message: string;
|
||||
};
|
||||
|
||||
export function ErrorMessageDetails(props: Props) {
|
||||
return <h4>{props.message}</h4>;
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
import { isFunction, map, fromPairs, extend, startsWith, trimStart, trimEnd } from "lodash";
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import UniversalRouter from "universal-router";
|
||||
import ErrorBoundary from "@/components/ErrorBoundary";
|
||||
import location from "@/services/location";
|
||||
import url from "@/services/url";
|
||||
|
||||
import ErrorMessage from "./ErrorMessage";
|
||||
|
||||
function generateRouteKey() {
|
||||
return Math.random()
|
||||
.toString(32)
|
||||
.substr(2);
|
||||
}
|
||||
|
||||
export function stripBase(href) {
|
||||
// Resolve provided link and '' (root) relative to document's base.
|
||||
// If provided href is not related to current document (does not
|
||||
// start with resolved root) - return false. Otherwise
|
||||
// strip root and return relative url.
|
||||
|
||||
const baseHref = trimEnd(url.normalize(""), "/") + "/";
|
||||
href = url.normalize(href);
|
||||
|
||||
if (startsWith(href, baseHref)) {
|
||||
return "/" + trimStart(href.substr(baseHref.length), "/");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function resolveRouteDependencies(route) {
|
||||
return Promise.all(
|
||||
map(route.resolve, (value, key) => {
|
||||
value = isFunction(value) ? value(route.routeParams, route, location) : value;
|
||||
return Promise.resolve(value).then(result => [key, result]);
|
||||
})
|
||||
).then(results => {
|
||||
route.routeParams = extend(route.routeParams, fromPairs(results));
|
||||
return route;
|
||||
});
|
||||
}
|
||||
|
||||
export default function Router({ routes, onRouteChange }) {
|
||||
const [currentRoute, setCurrentRoute] = useState(null);
|
||||
|
||||
const currentPathRef = useRef(null);
|
||||
const errorHandlerRef = useRef();
|
||||
|
||||
useEffect(() => {
|
||||
let isAbandoned = false;
|
||||
|
||||
const router = new UniversalRouter(routes, {
|
||||
resolveRoute({ route }, routeParams) {
|
||||
if (isFunction(route.render)) {
|
||||
return { ...route, routeParams };
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function resolve(action) {
|
||||
if (!isAbandoned) {
|
||||
if (errorHandlerRef.current) {
|
||||
errorHandlerRef.current.reset();
|
||||
}
|
||||
|
||||
const pathname = stripBase(location.path);
|
||||
|
||||
// This is a optimization for route resolver: if current route was already resolved
|
||||
// from this path - do nothing. It also prevents router from using outdated route in a case
|
||||
// when user navigated to another path while current one was still resolving.
|
||||
// Note: this lock uses only `path` fragment of URL to distinguish routes because currently
|
||||
// all pages depend only on this fragment and handle search/hash on their own. If router
|
||||
// should reload page on search/hash change - this fragment (and few checks below) should be updated
|
||||
if (pathname === currentPathRef.current) {
|
||||
return;
|
||||
}
|
||||
currentPathRef.current = pathname;
|
||||
|
||||
// Don't reload controller if URL was replaced
|
||||
if (action === "REPLACE") {
|
||||
return;
|
||||
}
|
||||
|
||||
router
|
||||
.resolve({ pathname })
|
||||
.then(route => {
|
||||
return isAbandoned || currentPathRef.current !== pathname ? null : resolveRouteDependencies(route);
|
||||
})
|
||||
.then(route => {
|
||||
if (route) {
|
||||
setCurrentRoute({ ...route, key: generateRouteKey() });
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (!isAbandoned && currentPathRef.current === pathname) {
|
||||
setCurrentRoute({
|
||||
render: currentRoute => <ErrorMessage {...currentRoute.routeParams} />,
|
||||
routeParams: { error },
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
resolve("PUSH");
|
||||
|
||||
const unlisten = location.listen((unused, action) => resolve(action));
|
||||
|
||||
return () => {
|
||||
isAbandoned = true;
|
||||
unlisten();
|
||||
};
|
||||
}, [routes]);
|
||||
|
||||
useEffect(() => {
|
||||
onRouteChange(currentRoute);
|
||||
}, [currentRoute, onRouteChange]);
|
||||
|
||||
if (!currentRoute) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ErrorBoundary ref={errorHandlerRef} renderError={error => <ErrorMessage error={error} />}>
|
||||
{currentRoute.render(currentRoute)}
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
Router.propTypes = {
|
||||
routes: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
path: PropTypes.string.isRequired,
|
||||
render: PropTypes.func, // (routeParams: PropTypes.object; currentRoute; location) => PropTypes.node
|
||||
// Additional props to be injected into route component.
|
||||
// Object keys are props names. Object values will become prop values:
|
||||
// - if value is a function - it will be called without arguments, and result will be used; otherwise value will be used;
|
||||
// - after previous step, if value is a promise - router will wait for it to resolve; resolved value then will be used;
|
||||
// otherwise value will be used directly.
|
||||
resolve: PropTypes.objectOf(PropTypes.any),
|
||||
})
|
||||
),
|
||||
onRouteChange: PropTypes.func,
|
||||
};
|
||||
|
||||
Router.defaultProps = {
|
||||
routes: [],
|
||||
onRouteChange: () => {},
|
||||
};
|
||||
118
client/app/components/ApplicationArea/Router.tsx
Normal file
118
client/app/components/ApplicationArea/Router.tsx
Normal file
@@ -0,0 +1,118 @@
|
||||
import { isFunction, startsWith, trimStart, trimEnd } from "lodash";
|
||||
import React, { useState, useEffect, useRef, useContext } from "react";
|
||||
import UniversalRouter from "universal-router";
|
||||
import ErrorBoundary from "@redash/viz/lib/components/ErrorBoundary";
|
||||
import location from "@/services/location";
|
||||
import url from "@/services/url";
|
||||
import ErrorMessage from "./ErrorMessage";
|
||||
function generateRouteKey() {
|
||||
return Math.random()
|
||||
.toString(32)
|
||||
.substr(2);
|
||||
}
|
||||
export const CurrentRouteContext = React.createContext(null);
|
||||
export function useCurrentRoute() {
|
||||
return useContext(CurrentRouteContext);
|
||||
}
|
||||
export function stripBase(href: any) {
|
||||
// Resolve provided link and '' (root) relative to document's base.
|
||||
// If provided href is not related to current document (does not
|
||||
// start with resolved root) - return false. Otherwise
|
||||
// strip root and return relative url.
|
||||
const baseHref = trimEnd(url.normalize(""), "/") + "/";
|
||||
href = url.normalize(href);
|
||||
if (startsWith(href, baseHref)) {
|
||||
return "/" + trimStart(href.substr(baseHref.length), "/");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
type OwnProps = {
|
||||
routes?: {
|
||||
path: string;
|
||||
render?: (...args: any[]) => any;
|
||||
resolve?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}[];
|
||||
onRouteChange?: (...args: any[]) => any;
|
||||
};
|
||||
type Props = OwnProps & typeof Router.defaultProps;
|
||||
export default function Router({ routes, onRouteChange }: Props) {
|
||||
const [currentRoute, setCurrentRoute] = useState(null);
|
||||
const currentPathRef = useRef(null);
|
||||
const errorHandlerRef = useRef();
|
||||
useEffect(() => {
|
||||
let isAbandoned = false;
|
||||
const router = new UniversalRouter(routes, {
|
||||
resolveRoute({ route }, routeParams) {
|
||||
if (isFunction((route as any).render)) {
|
||||
return { ...route, routeParams };
|
||||
}
|
||||
},
|
||||
});
|
||||
function resolve(action: any) {
|
||||
if (!isAbandoned) {
|
||||
if (errorHandlerRef.current) {
|
||||
// @ts-expect-error ts-migrate(2532) FIXME: Object is possibly 'undefined'.
|
||||
errorHandlerRef.current.reset();
|
||||
}
|
||||
const pathname = stripBase(location.path) || "/";
|
||||
// This is a optimization for route resolver: if current route was already resolved
|
||||
// from this path - do nothing. It also prevents router from using outdated route in a case
|
||||
// when user navigated to another path while current one was still resolving.
|
||||
// Note: this lock uses only `path` fragment of URL to distinguish routes because currently
|
||||
// all pages depend only on this fragment and handle search/hash on their own. If router
|
||||
// should reload page on search/hash change - this fragment (and few checks below) should be updated
|
||||
if (pathname === currentPathRef.current) {
|
||||
return;
|
||||
}
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'null'.
|
||||
currentPathRef.current = pathname;
|
||||
// Don't reload controller if URL was replaced
|
||||
if (action === "REPLACE") {
|
||||
return;
|
||||
}
|
||||
router
|
||||
.resolve({ pathname })
|
||||
.then(route => {
|
||||
if (!isAbandoned && currentPathRef.current === pathname) {
|
||||
setCurrentRoute({ ...route, key: generateRouteKey() });
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (!isAbandoned && currentPathRef.current === pathname) {
|
||||
setCurrentRoute({
|
||||
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '{ render: (currentRoute: any) =>... Remove this comment to see the full error message
|
||||
render: (currentRoute: any) => <ErrorMessage {...currentRoute.routeParams}/>,
|
||||
routeParams: { error },
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
resolve("PUSH");
|
||||
const unlisten = location.listen((unused: any, action: any) => resolve(action));
|
||||
return () => {
|
||||
isAbandoned = true;
|
||||
currentPathRef.current = null;
|
||||
unlisten();
|
||||
};
|
||||
}, [routes]);
|
||||
useEffect(() => {
|
||||
onRouteChange(currentRoute);
|
||||
}, [currentRoute, onRouteChange]);
|
||||
if (!currentRoute) {
|
||||
return null;
|
||||
}
|
||||
return (<CurrentRouteContext.Provider value={currentRoute}>
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
<ErrorBoundary ref={errorHandlerRef} renderError={(error: any) => <ErrorMessage error={error}/>}>
|
||||
{/* @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'. */}
|
||||
{currentRoute.render(currentRoute)}
|
||||
</ErrorBoundary>
|
||||
</CurrentRouteContext.Provider>);
|
||||
}
|
||||
Router.defaultProps = {
|
||||
routes: [],
|
||||
onRouteChange: () => { },
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import { isString } from "lodash";
|
||||
import navigateTo from "./navigateTo";
|
||||
|
||||
export default function handleNavigationIntent(event) {
|
||||
export default function handleNavigationIntent(event: any) {
|
||||
let element = event.target;
|
||||
while (element) {
|
||||
if (element.tagName === "A") {
|
||||
@@ -9,7 +9,7 @@ export default function handleNavigationIntent(event) {
|
||||
}
|
||||
element = element.parentNode;
|
||||
}
|
||||
if (!element || !element.hasAttribute("href")) {
|
||||
if (!element || !element.hasAttribute("href") || element.hasAttribute("download") || element.dataset.skipRouter) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import routes from "@/pages";
|
||||
import routes from "@/services/routes";
|
||||
import Router from "./Router";
|
||||
import handleNavigationIntent from "./handleNavigationIntent";
|
||||
import ErrorMessage from "./ErrorMessage";
|
||||
@@ -9,13 +9,15 @@ export default function ApplicationArea() {
|
||||
const [unhandledError, setUnhandledError] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
if (currentRoute && currentRoute.title) {
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
document.title = currentRoute.title;
|
||||
}
|
||||
}, [currentRoute]);
|
||||
|
||||
useEffect(() => {
|
||||
function globalErrorHandler(event) {
|
||||
function globalErrorHandler(event: any) {
|
||||
event.preventDefault();
|
||||
setUnhandledError(event.error);
|
||||
}
|
||||
@@ -33,5 +35,6 @@ export default function ApplicationArea() {
|
||||
return <ErrorMessage error={unhandledError} />;
|
||||
}
|
||||
|
||||
return <Router routes={routes} onRouteChange={setCurrentRoute} />;
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'RouteItem[]' is not assignable to type '{ pa... Remove this comment to see the full error message
|
||||
return <Router routes={routes.items} onRouteChange={setCurrentRoute} />;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { stripBase } from "./Router";
|
||||
|
||||
// When `replace` is set to `true` - it will just replace current URL
|
||||
// without reloading current page (router will skip this location change)
|
||||
export default function navigateTo(href, replace = false) {
|
||||
export default function navigateTo(href: any, replace = false) {
|
||||
// Allow calling chain to roll up, and then navigate
|
||||
setTimeout(() => {
|
||||
const isExternal = stripBase(href) === false;
|
||||
@@ -1,63 +0,0 @@
|
||||
import React, { useEffect, useState, useContext } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { ErrorBoundaryContext } from "@/components/ErrorBoundary";
|
||||
import { Auth } from "@/services/auth";
|
||||
|
||||
// This wrapper modifies `route.render` function and instead of passing `currentRoute` passes an object
|
||||
// that contains:
|
||||
// - `currentRoute.routeParams`
|
||||
// - `pageTitle` field which is equal to `currentRoute.title`
|
||||
// - `onError` field which is a `handleError` method of nearest error boundary
|
||||
// - `apiKey` field
|
||||
|
||||
function ApiKeySessionWrapper({ apiKey, currentRoute, renderChildren }) {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
const { handleError } = useContext(ErrorBoundaryContext);
|
||||
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
Auth.setApiKey(apiKey);
|
||||
Auth.loadConfig()
|
||||
.then(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(true);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(false);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [apiKey]);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment key={currentRoute.key}>
|
||||
{renderChildren({ ...currentRoute.routeParams, pageTitle: currentRoute.title, onError: handleError, apiKey })}
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
ApiKeySessionWrapper.propTypes = {
|
||||
apiKey: PropTypes.string.isRequired,
|
||||
renderChildren: PropTypes.func,
|
||||
};
|
||||
|
||||
ApiKeySessionWrapper.defaultProps = {
|
||||
renderChildren: () => null,
|
||||
};
|
||||
|
||||
export default function routeWithApiKeySession({ render, getApiKey, ...rest }) {
|
||||
return {
|
||||
...rest,
|
||||
render: currentRoute => (
|
||||
<ApiKeySessionWrapper apiKey={getApiKey(currentRoute)} currentRoute={currentRoute} renderChildren={render} />
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import React, { useEffect, useState, useContext } from "react";
|
||||
import { ErrorBoundaryContext } from "@redash/viz/lib/components/ErrorBoundary";
|
||||
import { Auth, clientConfig } from "@/services/auth";
|
||||
type OwnProps = {
|
||||
apiKey: string;
|
||||
renderChildren?: (...args: any[]) => any;
|
||||
};
|
||||
type Props = OwnProps & typeof ApiKeySessionWrapper.defaultProps;
|
||||
// This wrapper modifies `route.render` function and instead of passing `currentRoute` passes an object
|
||||
// that contains:
|
||||
// - `currentRoute.routeParams`
|
||||
// - `pageTitle` field which is equal to `currentRoute.title`
|
||||
// - `onError` field which is a `handleError` method of nearest error boundary
|
||||
// - `apiKey` field
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'currentRoute' does not exist on type 'Pr... Remove this comment to see the full error message
|
||||
function ApiKeySessionWrapper({ apiKey, currentRoute, renderChildren }: Props) {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
const { handleError } = useContext(ErrorBoundaryContext);
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
Auth.setApiKey(apiKey);
|
||||
Auth.loadConfig()
|
||||
.then(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(true);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(false);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, [apiKey]);
|
||||
if (!isAuthenticated || (clientConfig as any).disablePublicUrls) {
|
||||
return null;
|
||||
}
|
||||
return (<React.Fragment key={currentRoute.key}>
|
||||
{renderChildren({ ...currentRoute.routeParams, pageTitle: currentRoute.title, onError: handleError, apiKey })}
|
||||
</React.Fragment>);
|
||||
}
|
||||
ApiKeySessionWrapper.defaultProps = {
|
||||
renderChildren: () => null,
|
||||
};
|
||||
export default function routeWithApiKeySession({ render, getApiKey, ...rest }: any) {
|
||||
return {
|
||||
...rest,
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ apiKey: any; currentRoute: any; renderChil... Remove this comment to see the full error message
|
||||
render: (currentRoute: any) => <ApiKeySessionWrapper apiKey={getApiKey(currentRoute)} currentRoute={currentRoute} renderChildren={render}/>,
|
||||
};
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import ErrorBoundary, { ErrorBoundaryContext } from "@/components/ErrorBoundary";
|
||||
import { Auth } from "@/services/auth";
|
||||
import organizationStatus from "@/services/organizationStatus";
|
||||
import ApplicationHeader from "./ApplicationHeader";
|
||||
import ErrorMessage from "./ErrorMessage";
|
||||
|
||||
// This wrapper modifies `route.render` function and instead of passing `currentRoute` passes an object
|
||||
// that contains:
|
||||
// - `currentRoute.routeParams`
|
||||
// - `pageTitle` field which is equal to `currentRoute.title`
|
||||
// - `onError` field which is a `handleError` method of nearest error boundary
|
||||
|
||||
function UserSessionWrapper({ bodyClass, currentRoute, renderChildren }) {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(!!Auth.isAuthenticated());
|
||||
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
Promise.all([Auth.requireSession(), organizationStatus.refresh()])
|
||||
.then(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(!!Auth.isAuthenticated());
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(false);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (bodyClass) {
|
||||
document.body.classList.toggle(bodyClass, true);
|
||||
return () => {
|
||||
document.body.classList.toggle(bodyClass, false);
|
||||
};
|
||||
}
|
||||
}, [bodyClass]);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<ApplicationHeader />
|
||||
<React.Fragment key={currentRoute.key}>
|
||||
<ErrorBoundary renderError={error => <ErrorMessage error={error} />}>
|
||||
<ErrorBoundaryContext.Consumer>
|
||||
{({ handleError }) =>
|
||||
renderChildren({ ...currentRoute.routeParams, pageTitle: currentRoute.title, onError: handleError })
|
||||
}
|
||||
</ErrorBoundaryContext.Consumer>
|
||||
</ErrorBoundary>
|
||||
</React.Fragment>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
UserSessionWrapper.propTypes = {
|
||||
bodyClass: PropTypes.string,
|
||||
renderChildren: PropTypes.func,
|
||||
};
|
||||
|
||||
UserSessionWrapper.defaultProps = {
|
||||
bodyClass: null,
|
||||
renderChildren: () => null,
|
||||
};
|
||||
|
||||
export default function routeWithUserSession({ render, bodyClass, ...rest }) {
|
||||
return {
|
||||
...rest,
|
||||
render: currentRoute => (
|
||||
<UserSessionWrapper bodyClass={bodyClass} currentRoute={currentRoute} renderChildren={render} />
|
||||
),
|
||||
};
|
||||
}
|
||||
109
client/app/components/ApplicationArea/routeWithUserSession.tsx
Normal file
109
client/app/components/ApplicationArea/routeWithUserSession.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import ErrorBoundary, { ErrorBoundaryContext } from "@redash/viz/lib/components/ErrorBoundary";
|
||||
import { Auth } from "@/services/auth";
|
||||
import { policy } from "@/services/policy";
|
||||
import { CurrentRoute } from "@/services/routes";
|
||||
import organizationStatus from "@/services/organizationStatus";
|
||||
import DynamicComponent from "@/components/DynamicComponent";
|
||||
import ApplicationLayout from "./ApplicationLayout";
|
||||
import ErrorMessage from "./ErrorMessage";
|
||||
|
||||
export type UserSessionWrapperRenderChildrenProps<P> = {
|
||||
pageTitle?: string;
|
||||
onError: (error: Error) => void;
|
||||
} & P;
|
||||
|
||||
export interface UserSessionWrapperProps<P> {
|
||||
render: (props: UserSessionWrapperRenderChildrenProps<P>) => React.ReactNode;
|
||||
currentRoute: CurrentRoute<P>;
|
||||
bodyClass?: string;
|
||||
}
|
||||
|
||||
// This wrapper modifies `route.render` function and instead of passing `currentRoute` passes an object
|
||||
// that contains:
|
||||
// - `currentRoute.routeParams`
|
||||
// - `pageTitle` field which is equal to `currentRoute.title`
|
||||
// - `onError` field which is a `handleError` method of nearest error boundary
|
||||
|
||||
export function UserSessionWrapper<P>({ bodyClass, currentRoute, render }: UserSessionWrapperProps<P>) {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(!!Auth.isAuthenticated());
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
Promise.all([Auth.requireSession(), organizationStatus.refresh(), policy.refresh()])
|
||||
.then(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(!!Auth.isAuthenticated());
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (!isCancelled) {
|
||||
setIsAuthenticated(false);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (bodyClass) {
|
||||
document.body.classList.toggle(bodyClass, true);
|
||||
return () => {
|
||||
document.body.classList.toggle(bodyClass, false);
|
||||
};
|
||||
}
|
||||
}, [bodyClass]);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ApplicationLayout>
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'Element' is not assignable to type 'null | u... Remove this comment to see the full error message */}
|
||||
<React.Fragment key={currentRoute.key}>
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
<ErrorBoundary renderError={(error: Error) => <ErrorMessage error={error} />}>
|
||||
<ErrorBoundaryContext.Consumer>
|
||||
{({ handleError } /* : { handleError: UserSessionWrapperRenderChildrenProps<P>["onError"] } FIXME bring back type */) =>
|
||||
render({ ...currentRoute.routeParams, pageTitle: currentRoute.title, onError: handleError })
|
||||
}
|
||||
</ErrorBoundaryContext.Consumer>
|
||||
</ErrorBoundary>
|
||||
</React.Fragment>
|
||||
</ApplicationLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export type RouteWithUserSessionOptions<P> = {
|
||||
render: (props: UserSessionWrapperRenderChildrenProps<P>) => React.ReactNode;
|
||||
bodyClass?: string;
|
||||
title: string;
|
||||
path: string;
|
||||
};
|
||||
|
||||
export const UserSessionWrapperDynamicComponentName = "UserSessionWrapper";
|
||||
|
||||
export default function routeWithUserSession<P extends {} = {}>({
|
||||
render: originalRender,
|
||||
bodyClass,
|
||||
...rest
|
||||
}: RouteWithUserSessionOptions<P>) {
|
||||
return {
|
||||
...rest,
|
||||
render: (currentRoute: CurrentRoute<P>) => {
|
||||
const props = {
|
||||
render: originalRender,
|
||||
bodyClass,
|
||||
currentRoute,
|
||||
};
|
||||
return (
|
||||
<DynamicComponent
|
||||
{...props}
|
||||
name={UserSessionWrapperDynamicComponentName}
|
||||
fallback={<UserSessionWrapper {...props} />}
|
||||
/>
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -3,50 +3,40 @@ import Card from "antd/lib/card";
|
||||
import Button from "antd/lib/button";
|
||||
import Typography from "antd/lib/typography";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
import Link from "@/components/Link";
|
||||
import HelpTrigger from "@/components/HelpTrigger";
|
||||
import DynamicComponent from "@/components/DynamicComponent";
|
||||
import OrgSettings from "@/services/organizationSettings";
|
||||
|
||||
const Text = Typography.Text;
|
||||
|
||||
function BeaconConsent() {
|
||||
const [hide, setHide] = useState(false);
|
||||
|
||||
if (!clientConfig.showBeaconConsentMessage || hide) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hideConsentCard = () => {
|
||||
clientConfig.showBeaconConsentMessage = false;
|
||||
setHide(true);
|
||||
};
|
||||
|
||||
const confirmConsent = confirm => {
|
||||
let message = "🙏 Thank you.";
|
||||
|
||||
if (!confirm) {
|
||||
message = "Settings Saved.";
|
||||
const [hide, setHide] = useState(false);
|
||||
if (!(clientConfig as any).showBeaconConsentMessage || hide) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OrgSettings.save({ beacon_consent: confirm }, message)
|
||||
// .then(() => {
|
||||
// // const settings = get(response, 'settings');
|
||||
// // this.setState({ settings, formValues: { ...settings } });
|
||||
// })
|
||||
.finally(hideConsentCard);
|
||||
};
|
||||
|
||||
return (
|
||||
<DynamicComponent name="BeaconConsent">
|
||||
const hideConsentCard = () => {
|
||||
(clientConfig as any).showBeaconConsentMessage = false;
|
||||
setHide(true);
|
||||
};
|
||||
const confirmConsent = (confirm: any) => {
|
||||
let message = "🙏 Thank you.";
|
||||
if (!confirm) {
|
||||
message = "Settings Saved.";
|
||||
}
|
||||
OrgSettings.save({ beacon_consent: confirm }, message)
|
||||
// .then(() => {
|
||||
// // const settings = get(response, 'settings');
|
||||
// // this.setState({ settings, formValues: { ...settings } });
|
||||
// })
|
||||
.finally(hideConsentCard);
|
||||
};
|
||||
return (<DynamicComponent name="BeaconConsent">
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
<div className="m-t-10 tiled">
|
||||
<Card
|
||||
title={
|
||||
<>
|
||||
<Card title={<>
|
||||
Would you be ok with sharing anonymous usage data with the Redash team?{" "}
|
||||
<HelpTrigger type="USAGE_DATA_SHARING" />
|
||||
</>
|
||||
}
|
||||
bordered={false}>
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'never'. */}
|
||||
<HelpTrigger type="USAGE_DATA_SHARING"/>
|
||||
</>} bordered={false}>
|
||||
<Text>Help Redash improve by automatically sending anonymous usage data:</Text>
|
||||
<div className="m-t-5">
|
||||
<ul>
|
||||
@@ -65,14 +55,12 @@ function BeaconConsent() {
|
||||
</div>
|
||||
<div className="m-t-15">
|
||||
<Text type="secondary">
|
||||
You can change this setting anytime from the <a href="settings/organization">Organization Settings</a>{" "}
|
||||
page.
|
||||
You can change this setting anytime from the{" "}
|
||||
<Link href="settings/organization">Organization Settings</Link> page.
|
||||
</Text>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</DynamicComponent>
|
||||
);
|
||||
</DynamicComponent>);
|
||||
}
|
||||
|
||||
export default BeaconConsent;
|
||||
@@ -1,7 +1,15 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
function BigMessage({ message, icon, children, className }) {
|
||||
type OwnProps = {
|
||||
message?: string;
|
||||
icon: string;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type Props = OwnProps & typeof BigMessage.defaultProps;
|
||||
|
||||
function BigMessage({ message, icon, children, className }: Props) {
|
||||
return (
|
||||
<div className={"p-15 text-center " + className}>
|
||||
<h3 className="m-t-0 m-b-0">
|
||||
@@ -14,13 +22,6 @@ function BigMessage({ message, icon, children, className }) {
|
||||
);
|
||||
}
|
||||
|
||||
BigMessage.propTypes = {
|
||||
message: PropTypes.string,
|
||||
icon: PropTypes.string.isRequired,
|
||||
children: PropTypes.node,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
BigMessage.defaultProps = {
|
||||
message: "",
|
||||
children: null,
|
||||
@@ -1,23 +1,30 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import Button from "antd/lib/button";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
import CopyOutlinedIcon from "@ant-design/icons/CopyOutlined";
|
||||
import "./CodeBlock.less";
|
||||
|
||||
export default class CodeBlock extends React.Component {
|
||||
static propTypes = {
|
||||
copyable: PropTypes.bool,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
type OwnProps = {
|
||||
copyable?: boolean;
|
||||
};
|
||||
|
||||
type State = any;
|
||||
|
||||
type Props = OwnProps & typeof CodeBlock.defaultProps;
|
||||
|
||||
export default class CodeBlock extends React.Component<Props, State> {
|
||||
static defaultProps = {
|
||||
copyable: false,
|
||||
children: null,
|
||||
};
|
||||
|
||||
copyFeatureEnabled: any;
|
||||
ref: any;
|
||||
resetCopyState: any;
|
||||
|
||||
state = { copied: null };
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.ref = React.createRef();
|
||||
this.copyFeatureEnabled = props.copyable && document.queryCommandSupported("copy");
|
||||
@@ -32,6 +39,7 @@ export default class CodeBlock extends React.Component {
|
||||
|
||||
copy = () => {
|
||||
// select text
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
window.getSelection().selectAllChildren(this.ref.current);
|
||||
|
||||
// copy
|
||||
@@ -48,6 +56,7 @@ export default class CodeBlock extends React.Component {
|
||||
}
|
||||
|
||||
// reset selection
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
window.getSelection().removeAllRanges();
|
||||
|
||||
// reset tooltip
|
||||
@@ -59,7 +68,7 @@ export default class CodeBlock extends React.Component {
|
||||
|
||||
const copyButton = (
|
||||
<Tooltip title={this.state.copied || "Copy"}>
|
||||
<Button icon="copy" type="dashed" size="small" onClick={this.copy} />
|
||||
<Button icon={<CopyOutlinedIcon />} type="dashed" size="small" onClick={this.copy} />
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import cx from "classnames";
|
||||
import AntCollapse from "antd/lib/collapse";
|
||||
|
||||
export default function Collapse({ collapsed, children, className, ...props }) {
|
||||
type OwnProps = {
|
||||
collapsed?: boolean;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type Props = OwnProps & typeof Collapse.defaultProps;
|
||||
|
||||
export default function Collapse({ collapsed, children, className, ...props }: Props) {
|
||||
return (
|
||||
<AntCollapse
|
||||
{...props}
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'string | null' is not assignable to type 'st... Remove this comment to see the full error message
|
||||
activeKey={collapsed ? null : "content"}
|
||||
className={cx(className, "ant-collapse-headerless")}>
|
||||
<AntCollapse.Panel key="content" header="">
|
||||
@@ -16,12 +24,6 @@ export default function Collapse({ collapsed, children, className, ...props }) {
|
||||
);
|
||||
}
|
||||
|
||||
Collapse.propTypes = {
|
||||
collapsed: PropTypes.bool,
|
||||
children: PropTypes.node,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
Collapse.defaultProps = {
|
||||
collapsed: true,
|
||||
children: null,
|
||||
@@ -1,36 +0,0 @@
|
||||
import { isString } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import cx from "classnames";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
|
||||
import "./swatch.less";
|
||||
|
||||
export default function Swatch({ className, color, title, size, ...props }) {
|
||||
const result = (
|
||||
<span className={cx("color-swatch", className)} style={{ backgroundColor: color, width: size }} {...props} />
|
||||
);
|
||||
|
||||
if (isString(title) && title !== "") {
|
||||
return (
|
||||
<Tooltip title={title} mouseEnterDelay={0} mouseLeaveDelay={0}>
|
||||
{result}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Swatch.propTypes = {
|
||||
className: PropTypes.string,
|
||||
title: PropTypes.string,
|
||||
color: PropTypes.string,
|
||||
size: PropTypes.number,
|
||||
};
|
||||
|
||||
Swatch.defaultProps = {
|
||||
className: null,
|
||||
title: null,
|
||||
color: "transparent",
|
||||
size: 12,
|
||||
};
|
||||
@@ -1,184 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { isEmpty, toUpper, includes } from "lodash";
|
||||
import Button from "antd/lib/button";
|
||||
import List from "antd/lib/list";
|
||||
import Modal from "antd/lib/modal";
|
||||
import Input from "antd/lib/input";
|
||||
import Steps from "antd/lib/steps";
|
||||
import { getErrorMessage } from "@/components/ApplicationArea/ErrorMessage";
|
||||
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
|
||||
import { PreviewCard } from "@/components/PreviewCard";
|
||||
import EmptyState from "@/components/items-list/components/EmptyState";
|
||||
import DynamicForm from "@/components/dynamic-form/DynamicForm";
|
||||
import helper from "@/components/dynamic-form/dynamicFormHelper";
|
||||
import HelpTrigger, { TYPES as HELP_TRIGGER_TYPES } from "@/components/HelpTrigger";
|
||||
|
||||
const { Step } = Steps;
|
||||
const { Search } = Input;
|
||||
|
||||
const StepEnum = {
|
||||
SELECT_TYPE: 0,
|
||||
CONFIGURE_IT: 1,
|
||||
DONE: 2,
|
||||
};
|
||||
|
||||
class CreateSourceDialog extends React.Component {
|
||||
static propTypes = {
|
||||
dialog: DialogPropType.isRequired,
|
||||
types: PropTypes.arrayOf(PropTypes.object),
|
||||
sourceType: PropTypes.string.isRequired,
|
||||
imageFolder: PropTypes.string.isRequired,
|
||||
helpTriggerPrefix: PropTypes.string,
|
||||
onCreate: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
types: [],
|
||||
helpTriggerPrefix: null,
|
||||
};
|
||||
|
||||
state = {
|
||||
searchText: "",
|
||||
selectedType: null,
|
||||
savingSource: false,
|
||||
currentStep: StepEnum.SELECT_TYPE,
|
||||
};
|
||||
|
||||
selectType = selectedType => {
|
||||
this.setState({ selectedType, currentStep: StepEnum.CONFIGURE_IT });
|
||||
};
|
||||
|
||||
resetType = () => {
|
||||
if (this.state.currentStep === StepEnum.CONFIGURE_IT) {
|
||||
this.setState({ searchText: "", selectedType: null, currentStep: StepEnum.SELECT_TYPE });
|
||||
}
|
||||
};
|
||||
|
||||
createSource = (values, successCallback, errorCallback) => {
|
||||
const { selectedType, savingSource } = this.state;
|
||||
if (!savingSource) {
|
||||
this.setState({ savingSource: true, currentStep: StepEnum.DONE });
|
||||
this.props
|
||||
.onCreate(selectedType, values)
|
||||
.then(data => {
|
||||
successCallback("Saved.");
|
||||
this.props.dialog.close({ success: true, data });
|
||||
})
|
||||
.catch(error => {
|
||||
this.setState({ savingSource: false, currentStep: StepEnum.CONFIGURE_IT });
|
||||
errorCallback(getErrorMessage(error.message));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
renderTypeSelector() {
|
||||
const { types } = this.props;
|
||||
const { searchText } = this.state;
|
||||
const filteredTypes = types.filter(
|
||||
type => isEmpty(searchText) || includes(type.name.toLowerCase(), searchText.toLowerCase())
|
||||
);
|
||||
return (
|
||||
<div className="m-t-10">
|
||||
<Search
|
||||
placeholder="Search..."
|
||||
onChange={e => this.setState({ searchText: e.target.value })}
|
||||
autoFocus
|
||||
data-test="SearchSource"
|
||||
/>
|
||||
<div className="scrollbox p-5 m-t-10" style={{ minHeight: "30vh", maxHeight: "40vh" }}>
|
||||
{isEmpty(filteredTypes) ? (
|
||||
<EmptyState className="" />
|
||||
) : (
|
||||
<List size="small" dataSource={filteredTypes} renderItem={item => this.renderItem(item)} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderForm() {
|
||||
const { imageFolder, helpTriggerPrefix } = this.props;
|
||||
const { selectedType } = this.state;
|
||||
const fields = helper.getFields(selectedType);
|
||||
const helpTriggerType = `${helpTriggerPrefix}${toUpper(selectedType.type)}`;
|
||||
return (
|
||||
<div>
|
||||
<div className="d-flex justify-content-center align-items-center">
|
||||
<img className="p-5" src={`${imageFolder}/${selectedType.type}.png`} alt={selectedType.name} width="48" />
|
||||
<h4 className="m-0">{selectedType.name}</h4>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
{HELP_TRIGGER_TYPES[helpTriggerType] && (
|
||||
<HelpTrigger className="f-13" type={helpTriggerType}>
|
||||
Setup Instructions <i className="fa fa-question-circle" />
|
||||
</HelpTrigger>
|
||||
)}
|
||||
</div>
|
||||
<DynamicForm id="sourceForm" fields={fields} onSubmit={this.createSource} feedbackIcons hideSubmitButton />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderItem(item) {
|
||||
const { imageFolder } = this.props;
|
||||
return (
|
||||
<List.Item className="p-l-10 p-r-10 clickable" onClick={() => this.selectType(item)}>
|
||||
<PreviewCard title={item.name} imageUrl={`${imageFolder}/${item.type}.png`} roundedImage={false}>
|
||||
<i className="fa fa-angle-double-right" />
|
||||
</PreviewCard>
|
||||
</List.Item>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { currentStep, savingSource } = this.state;
|
||||
const { dialog, sourceType } = this.props;
|
||||
return (
|
||||
<Modal
|
||||
{...dialog.props}
|
||||
title={`Create a New ${sourceType}`}
|
||||
footer={
|
||||
currentStep === StepEnum.SELECT_TYPE
|
||||
? [
|
||||
<Button key="cancel" onClick={() => dialog.dismiss()}>
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button key="submit" type="primary" disabled>
|
||||
Create
|
||||
</Button>,
|
||||
]
|
||||
: [
|
||||
<Button key="previous" onClick={this.resetType}>
|
||||
Previous
|
||||
</Button>,
|
||||
<Button
|
||||
key="submit"
|
||||
htmlType="submit"
|
||||
form="sourceForm"
|
||||
type="primary"
|
||||
loading={savingSource}
|
||||
data-test="CreateSourceButton">
|
||||
Create
|
||||
</Button>,
|
||||
]
|
||||
}>
|
||||
<div data-test="CreateSourceDialog">
|
||||
<Steps className="hidden-xs m-b-10" size="small" current={currentStep} progressDot>
|
||||
{currentStep === StepEnum.CONFIGURE_IT ? (
|
||||
<Step title={<a>Type Selection</a>} className="clickable" onClick={this.resetType} />
|
||||
) : (
|
||||
<Step title="Type Selection" />
|
||||
)}
|
||||
<Step title="Configuration" />
|
||||
<Step title="Done" />
|
||||
</Steps>
|
||||
{currentStep === StepEnum.SELECT_TYPE && this.renderTypeSelector()}
|
||||
{currentStep !== StepEnum.SELECT_TYPE && this.renderForm()}
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default wrapDialog(CreateSourceDialog);
|
||||
152
client/app/components/CreateSourceDialog.tsx
Normal file
152
client/app/components/CreateSourceDialog.tsx
Normal file
@@ -0,0 +1,152 @@
|
||||
import React from "react";
|
||||
import { isEmpty, toUpper, includes, get } from "lodash";
|
||||
import Button from "antd/lib/button";
|
||||
import List from "antd/lib/list";
|
||||
import Modal from "antd/lib/modal";
|
||||
import Input from "antd/lib/input";
|
||||
import Steps from "antd/lib/steps";
|
||||
// @ts-expect-error ts-migrate(6133) FIXME: 'DialogPropType' is declared but its value is neve... Remove this comment to see the full error message
|
||||
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
|
||||
import Link from "@/components/Link";
|
||||
import { PreviewCard } from "@/components/PreviewCard";
|
||||
import EmptyState from "@/components/items-list/components/EmptyState";
|
||||
import DynamicForm from "@/components/dynamic-form/DynamicForm";
|
||||
import helper from "@/components/dynamic-form/dynamicFormHelper";
|
||||
import HelpTrigger, { TYPES as HELP_TRIGGER_TYPES } from "@/components/HelpTrigger";
|
||||
const { Step } = Steps;
|
||||
const { Search } = Input;
|
||||
const StepEnum = {
|
||||
SELECT_TYPE: 0,
|
||||
CONFIGURE_IT: 1,
|
||||
DONE: 2,
|
||||
};
|
||||
type OwnProps = {
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'DialogPropType' refers to a value, but is being u... Remove this comment to see the full error message
|
||||
dialog: DialogPropType;
|
||||
types?: any[];
|
||||
sourceType: string;
|
||||
imageFolder: string;
|
||||
helpTriggerPrefix?: string;
|
||||
onCreate: (...args: any[]) => any;
|
||||
};
|
||||
type State = any;
|
||||
type Props = OwnProps & typeof CreateSourceDialog.defaultProps;
|
||||
class CreateSourceDialog extends React.Component<Props, State> {
|
||||
static defaultProps = {
|
||||
types: [],
|
||||
helpTriggerPrefix: null,
|
||||
};
|
||||
state = {
|
||||
searchText: "",
|
||||
selectedType: null,
|
||||
savingSource: false,
|
||||
currentStep: StepEnum.SELECT_TYPE,
|
||||
};
|
||||
selectType = (selectedType: any) => {
|
||||
this.setState({ selectedType, currentStep: StepEnum.CONFIGURE_IT });
|
||||
};
|
||||
resetType = () => {
|
||||
if (this.state.currentStep === StepEnum.CONFIGURE_IT) {
|
||||
this.setState({ searchText: "", selectedType: null, currentStep: StepEnum.SELECT_TYPE });
|
||||
}
|
||||
};
|
||||
createSource = (values: any, successCallback: any, errorCallback: any) => {
|
||||
const { selectedType, savingSource } = this.state;
|
||||
if (!savingSource) {
|
||||
this.setState({ savingSource: true, currentStep: StepEnum.DONE });
|
||||
(this.props as any).onCreate(selectedType, values)
|
||||
.then((data: any) => {
|
||||
successCallback("Saved.");
|
||||
(this.props as any).dialog.close({ success: true, data });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
this.setState({ savingSource: false, currentStep: StepEnum.CONFIGURE_IT });
|
||||
errorCallback(get(error, "response.data.message", "Failed saving."));
|
||||
});
|
||||
}
|
||||
};
|
||||
renderTypeSelector() {
|
||||
const { types } = this.props;
|
||||
const { searchText } = this.state;
|
||||
const filteredTypes = (types as any).filter((type: any) => isEmpty(searchText) || includes(type.name.toLowerCase(), searchText.toLowerCase()));
|
||||
return (<div className="m-t-10">
|
||||
<Search placeholder="Search..." onChange={e => this.setState({ searchText: e.target.value })} autoFocus data-test="SearchSource"/>
|
||||
<div className="scrollbox p-5 m-t-10" style={{ minHeight: "30vh", maxHeight: "40vh" }}>
|
||||
{isEmpty(filteredTypes) ? (<EmptyState className=""/>) : (<List size="small" dataSource={filteredTypes} renderItem={item => this.renderItem(item)}/>)}
|
||||
</div>
|
||||
</div>);
|
||||
}
|
||||
renderForm() {
|
||||
const { imageFolder, helpTriggerPrefix } = this.props;
|
||||
const { selectedType } = this.state;
|
||||
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'null' is not assignable to param... Remove this comment to see the full error message
|
||||
const fields = helper.getFields(selectedType);
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
const helpTriggerType = `${helpTriggerPrefix}${toUpper(selectedType.type)}`;
|
||||
return (<div>
|
||||
<div className="d-flex justify-content-center align-items-center">
|
||||
{/* @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'. */}
|
||||
<img className="p-5" src={`${imageFolder}/${selectedType.type}.png`} alt={selectedType.name} width="48"/>
|
||||
{/* @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'. */}
|
||||
<h4 className="m-0">{selectedType.name}</h4>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
{/* @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message */}
|
||||
{HELP_TRIGGER_TYPES[helpTriggerType] && (<HelpTrigger className="f-13" type={helpTriggerType}>
|
||||
Setup Instructions <i className="fa fa-question-circle"/>
|
||||
</HelpTrigger>)}
|
||||
</div>
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'never'. */}
|
||||
<DynamicForm id="sourceForm" fields={fields} onSubmit={this.createSource} feedbackIcons hideSubmitButton/>
|
||||
{/* @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'. */}
|
||||
{selectedType.type === "databricks" && (<small>
|
||||
By using the Databricks Data Source you agree to the Databricks JDBC/ODBC{" "}
|
||||
<Link href="https://databricks.com/spark/odbc-driver-download" target="_blank" rel="noopener noreferrer">
|
||||
Driver Download Terms and Conditions
|
||||
</Link>
|
||||
.
|
||||
</small>)}
|
||||
</div>);
|
||||
}
|
||||
renderItem(item: any) {
|
||||
const { imageFolder } = this.props;
|
||||
return (<List.Item className="p-l-10 p-r-10 clickable" onClick={() => this.selectType(item)}>
|
||||
<PreviewCard title={item.name} imageUrl={`${imageFolder}/${item.type}.png`} roundedImage={false} data-test="PreviewItem" data-test-type={item.type}>
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'Element' is not assignable to type 'null | u... Remove this comment to see the full error message */}
|
||||
<i className="fa fa-angle-double-right"/>
|
||||
</PreviewCard>
|
||||
</List.Item>);
|
||||
}
|
||||
render() {
|
||||
const { currentStep, savingSource } = this.state;
|
||||
const { dialog, sourceType } = this.props;
|
||||
return (<Modal {...(dialog as any).props} title={`Create a New ${sourceType}`} footer={currentStep === StepEnum.SELECT_TYPE
|
||||
? [
|
||||
<Button key="cancel" onClick={() => (dialog as any).dismiss()} data-test="CreateSourceCancelButton">
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button key="submit" type="primary" disabled>
|
||||
Create
|
||||
</Button>,
|
||||
]
|
||||
: [
|
||||
<Button key="previous" onClick={this.resetType}>
|
||||
Previous
|
||||
</Button>,
|
||||
<Button key="submit" htmlType="submit" form="sourceForm" type="primary" loading={savingSource} data-test="CreateSourceSaveButton">
|
||||
Create
|
||||
</Button>,
|
||||
]}>
|
||||
<div data-test="CreateSourceDialog">
|
||||
<Steps className="hidden-xs m-b-10" size="small" current={currentStep} progressDot>
|
||||
{currentStep === StepEnum.CONFIGURE_IT ? (<Step title={<a>Type Selection</a>} className="clickable" onClick={this.resetType}/>) : (<Step title="Type Selection"/>)}
|
||||
<Step title="Configuration"/>
|
||||
<Step title="Done"/>
|
||||
</Steps>
|
||||
{currentStep === StepEnum.SELECT_TYPE && this.renderTypeSelector()}
|
||||
{currentStep !== StepEnum.SELECT_TYPE && this.renderForm()}
|
||||
</div>
|
||||
</Modal>);
|
||||
}
|
||||
}
|
||||
export default wrapDialog(CreateSourceDialog);
|
||||
@@ -1,43 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
import { Moment } from "@/components/proptypes";
|
||||
|
||||
const DateInput = React.forwardRef(({ defaultValue, value, onSelect, className, ...props }, ref) => {
|
||||
const format = clientConfig.dateFormat || "YYYY-MM-DD";
|
||||
const additionalAttributes = {};
|
||||
if (defaultValue && defaultValue.isValid()) {
|
||||
additionalAttributes.defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (value && value.isValid())) {
|
||||
additionalAttributes.value = value;
|
||||
}
|
||||
return (
|
||||
<DatePicker
|
||||
ref={ref}
|
||||
className={className}
|
||||
{...additionalAttributes}
|
||||
format={format}
|
||||
placeholder="Select Date"
|
||||
onChange={onSelect}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
DateInput.propTypes = {
|
||||
defaultValue: Moment,
|
||||
value: Moment,
|
||||
onSelect: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
DateInput.defaultProps = {
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
onSelect: () => {},
|
||||
className: "",
|
||||
};
|
||||
|
||||
export default DateInput;
|
||||
31
client/app/components/DateInput.tsx
Normal file
31
client/app/components/DateInput.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from "react";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
// @ts-expect-error ts-migrate(6133) FIXME: 'Moment' is declared but its value is never read.
|
||||
import { Moment } from "@/components/proptypes";
|
||||
type Props = {
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
defaultValue?: Moment;
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
value?: Moment;
|
||||
onSelect?: (...args: any[]) => any;
|
||||
className?: string;
|
||||
};
|
||||
const DateInput = React.forwardRef<any, Props>(({ defaultValue, value, onSelect, className, ...props }, ref) => {
|
||||
const format = (clientConfig as any).dateFormat || "YYYY-MM-DD";
|
||||
const additionalAttributes = {};
|
||||
if (defaultValue && defaultValue.isValid()) {
|
||||
(additionalAttributes as any).defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (value && value.isValid())) {
|
||||
(additionalAttributes as any).value = value;
|
||||
}
|
||||
return (<DatePicker ref={ref} className={className} {...additionalAttributes} format={format} placeholder="Select Date" onChange={onSelect} {...props}/>);
|
||||
});
|
||||
DateInput.defaultProps = {
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
onSelect: () => { },
|
||||
className: "",
|
||||
};
|
||||
export default DateInput;
|
||||
@@ -1,45 +0,0 @@
|
||||
import { isArray } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
import { Moment } from "@/components/proptypes";
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
const DateRangeInput = React.forwardRef(({ defaultValue, value, onSelect, className, ...props }, ref) => {
|
||||
const format = clientConfig.dateFormat || "YYYY-MM-DD";
|
||||
const additionalAttributes = {};
|
||||
if (isArray(defaultValue) && defaultValue[0].isValid() && defaultValue[1].isValid()) {
|
||||
additionalAttributes.defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (isArray(value) && value[0].isValid() && value[1].isValid())) {
|
||||
additionalAttributes.value = value;
|
||||
}
|
||||
return (
|
||||
<RangePicker
|
||||
ref={ref}
|
||||
className={className}
|
||||
{...additionalAttributes}
|
||||
format={format}
|
||||
onChange={onSelect}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
DateRangeInput.propTypes = {
|
||||
defaultValue: PropTypes.arrayOf(Moment),
|
||||
value: PropTypes.arrayOf(Moment),
|
||||
onSelect: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
DateRangeInput.defaultProps = {
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
onSelect: () => {},
|
||||
className: "",
|
||||
};
|
||||
|
||||
export default DateRangeInput;
|
||||
34
client/app/components/DateRangeInput.tsx
Normal file
34
client/app/components/DateRangeInput.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { isArray } from "lodash";
|
||||
import React from "react";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
// @ts-expect-error ts-migrate(6133) FIXME: 'Moment' is declared but its value is never read.
|
||||
import { Moment } from "@/components/proptypes";
|
||||
const { RangePicker } = DatePicker;
|
||||
type Props = {
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
defaultValue?: Moment[];
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
value?: Moment[];
|
||||
onSelect?: (...args: any[]) => any;
|
||||
className?: string;
|
||||
};
|
||||
const DateRangeInput = React.forwardRef<any, Props>(({ defaultValue, value, onSelect, className, ...props }, ref) => {
|
||||
const format = (clientConfig as any).dateFormat || "YYYY-MM-DD";
|
||||
const additionalAttributes = {};
|
||||
if (isArray(defaultValue) && defaultValue[0].isValid() && defaultValue[1].isValid()) {
|
||||
(additionalAttributes as any).defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (isArray(value) && value[0].isValid() && value[1].isValid())) {
|
||||
(additionalAttributes as any).value = value;
|
||||
}
|
||||
return (<RangePicker ref={ref} className={className} {...additionalAttributes} format={format} onChange={onSelect} {...props}/>);
|
||||
});
|
||||
DateRangeInput.defaultProps = {
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'null' is not assignable to type 'any[] | und... Remove this comment to see the full error message
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
onSelect: () => { },
|
||||
className: "",
|
||||
};
|
||||
export default DateRangeInput;
|
||||
@@ -1,46 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
import { Moment } from "@/components/proptypes";
|
||||
|
||||
const DateTimeInput = React.forwardRef(({ defaultValue, value, withSeconds, onSelect, className, ...props }, ref) => {
|
||||
const format = (clientConfig.dateFormat || "YYYY-MM-DD") + (withSeconds ? " HH:mm:ss" : " HH:mm");
|
||||
const additionalAttributes = {};
|
||||
if (defaultValue && defaultValue.isValid()) {
|
||||
additionalAttributes.defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (value && value.isValid())) {
|
||||
additionalAttributes.value = value;
|
||||
}
|
||||
return (
|
||||
<DatePicker
|
||||
ref={ref}
|
||||
className={className}
|
||||
showTime
|
||||
{...additionalAttributes}
|
||||
format={format}
|
||||
placeholder="Select Date and Time"
|
||||
onChange={onSelect}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
DateTimeInput.propTypes = {
|
||||
defaultValue: Moment,
|
||||
value: Moment,
|
||||
withSeconds: PropTypes.bool,
|
||||
onSelect: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
DateTimeInput.defaultProps = {
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
withSeconds: false,
|
||||
onSelect: () => {},
|
||||
className: "",
|
||||
};
|
||||
|
||||
export default DateTimeInput;
|
||||
33
client/app/components/DateTimeInput.tsx
Normal file
33
client/app/components/DateTimeInput.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from "react";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
// @ts-expect-error ts-migrate(6133) FIXME: 'Moment' is declared but its value is never read.
|
||||
import { Moment } from "@/components/proptypes";
|
||||
type Props = {
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
defaultValue?: Moment;
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
value?: Moment;
|
||||
withSeconds?: boolean;
|
||||
onSelect?: (...args: any[]) => any;
|
||||
className?: string;
|
||||
};
|
||||
const DateTimeInput = React.forwardRef<any, Props>(({ defaultValue, value, withSeconds, onSelect, className, ...props }, ref) => {
|
||||
const format = ((clientConfig as any).dateFormat || "YYYY-MM-DD") + (withSeconds ? " HH:mm:ss" : " HH:mm");
|
||||
const additionalAttributes = {};
|
||||
if (defaultValue && defaultValue.isValid()) {
|
||||
(additionalAttributes as any).defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (value && value.isValid())) {
|
||||
(additionalAttributes as any).value = value;
|
||||
}
|
||||
return (<DatePicker ref={ref} className={className} showTime {...additionalAttributes} format={format} placeholder="Select Date and Time" onChange={onSelect} {...props}/>);
|
||||
});
|
||||
DateTimeInput.defaultProps = {
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
withSeconds: false,
|
||||
onSelect: () => { },
|
||||
className: "",
|
||||
};
|
||||
export default DateTimeInput;
|
||||
@@ -1,50 +0,0 @@
|
||||
import { isArray } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
import { Moment } from "@/components/proptypes";
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
const DateTimeRangeInput = React.forwardRef(
|
||||
({ defaultValue, value, withSeconds, onSelect, className, ...props }, ref) => {
|
||||
const format = (clientConfig.dateFormat || "YYYY-MM-DD") + (withSeconds ? " HH:mm:ss" : " HH:mm");
|
||||
const additionalAttributes = {};
|
||||
if (isArray(defaultValue) && defaultValue[0].isValid() && defaultValue[1].isValid()) {
|
||||
additionalAttributes.defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (isArray(value) && value[0].isValid() && value[1].isValid())) {
|
||||
additionalAttributes.value = value;
|
||||
}
|
||||
return (
|
||||
<RangePicker
|
||||
ref={ref}
|
||||
className={className}
|
||||
showTime
|
||||
{...additionalAttributes}
|
||||
format={format}
|
||||
onChange={onSelect}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
DateTimeRangeInput.propTypes = {
|
||||
defaultValue: PropTypes.arrayOf(Moment),
|
||||
value: PropTypes.arrayOf(Moment),
|
||||
withSeconds: PropTypes.bool,
|
||||
onSelect: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
DateTimeRangeInput.defaultProps = {
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
withSeconds: false,
|
||||
onSelect: () => {},
|
||||
className: "",
|
||||
};
|
||||
|
||||
export default DateTimeRangeInput;
|
||||
36
client/app/components/DateTimeRangeInput.tsx
Normal file
36
client/app/components/DateTimeRangeInput.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { isArray } from "lodash";
|
||||
import React from "react";
|
||||
import DatePicker from "antd/lib/date-picker";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
// @ts-expect-error ts-migrate(6133) FIXME: 'Moment' is declared but its value is never read.
|
||||
import { Moment } from "@/components/proptypes";
|
||||
const { RangePicker } = DatePicker;
|
||||
type Props = {
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
defaultValue?: Moment[];
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'Moment' refers to a value, but is being used as a... Remove this comment to see the full error message
|
||||
value?: Moment[];
|
||||
withSeconds?: boolean;
|
||||
onSelect?: (...args: any[]) => any;
|
||||
className?: string;
|
||||
};
|
||||
const DateTimeRangeInput = React.forwardRef<any, Props>(({ defaultValue, value, withSeconds, onSelect, className, ...props }, ref) => {
|
||||
const format = ((clientConfig as any).dateFormat || "YYYY-MM-DD") + (withSeconds ? " HH:mm:ss" : " HH:mm");
|
||||
const additionalAttributes = {};
|
||||
if (isArray(defaultValue) && defaultValue[0].isValid() && defaultValue[1].isValid()) {
|
||||
(additionalAttributes as any).defaultValue = defaultValue;
|
||||
}
|
||||
if (value === null || (isArray(value) && value[0].isValid() && value[1].isValid())) {
|
||||
(additionalAttributes as any).value = value;
|
||||
}
|
||||
return (<RangePicker ref={ref} className={className} showTime {...additionalAttributes} format={format} onChange={onSelect} {...props}/>);
|
||||
});
|
||||
DateTimeRangeInput.defaultProps = {
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'null' is not assignable to type 'any[] | und... Remove this comment to see the full error message
|
||||
defaultValue: null,
|
||||
value: undefined,
|
||||
withSeconds: false,
|
||||
onSelect: () => { },
|
||||
className: "",
|
||||
};
|
||||
export default DateTimeRangeInput;
|
||||
30
client/app/components/DialogWrapper.d.ts
vendored
Normal file
30
client/app/components/DialogWrapper.d.ts
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ModalProps } from "antd/lib/modal/Modal";
|
||||
|
||||
export interface DialogProps<ROk, RCancel> {
|
||||
props: ModalProps;
|
||||
close: (result: ROk) => void;
|
||||
dismiss: (result: RCancel) => void;
|
||||
}
|
||||
|
||||
export type DialogWrapperChildProps<ROk, RCancel> = {
|
||||
dialog: DialogProps<ROk, RCancel>;
|
||||
};
|
||||
|
||||
export type DialogComponentType<ROk = void, P = {}, RCancel = void> = React.ComponentType<
|
||||
DialogWrapperChildProps<ROk, RCancel> & P
|
||||
>;
|
||||
|
||||
export function wrap<ROk = void, P = {}, RCancel = void>(
|
||||
DialogComponent: DialogComponentType<ROk, P, RCancel>
|
||||
): {
|
||||
Component: DialogComponentType<ROk, P, RCancel>;
|
||||
showModal: (
|
||||
props?: P
|
||||
) => {
|
||||
update: (props: P) => void;
|
||||
onClose: (handler: (result: ROk) => Promise<void> | void) => void;
|
||||
onDismiss: (handler: (result: RCancel) => Promise<void> | void) => void;
|
||||
close: (result: ROk) => void;
|
||||
dismiss: (result: RCancel) => void;
|
||||
};
|
||||
};
|
||||
@@ -1,209 +0,0 @@
|
||||
import { isFunction } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import ReactDOM from "react-dom";
|
||||
|
||||
/**
|
||||
Wrapper for dialogs based on Ant's <Modal> component.
|
||||
|
||||
|
||||
Using wrapped dialogs
|
||||
=====================
|
||||
|
||||
Wrapped component is an object with two fields:
|
||||
|
||||
{
|
||||
showModal: (dialogProps) => object({
|
||||
result: Promise,
|
||||
close: (result) => void,
|
||||
dismiss: (reason) => void,
|
||||
}),
|
||||
Component: React.Component, // wrapped dialog component
|
||||
}
|
||||
|
||||
To open dialog, use `showModal` method; optionally you can pass additional properties that
|
||||
will be expanded on wrapped component:
|
||||
|
||||
const dialog = SomeWrappedDialog.showModal()
|
||||
|
||||
const dialog = SomeWrappedDialog.showModal({ greeting: 'Hello' })
|
||||
|
||||
To get result of modal, use `result` property:
|
||||
|
||||
dialog.result
|
||||
.then(...) // pressed OK button or used `close` method; resolved value is a result of dialog
|
||||
.catch(...) // pressed Cancel button or used `dismiss` method; optional argument is a rejection reason.
|
||||
|
||||
Also, dialog has `close` and `dismiss` methods that allows to close dialog by caller. Passed arguments
|
||||
will be used to resolve/reject `dialog.result` promise. `update` methods allows to pass new properties
|
||||
to dialog.
|
||||
|
||||
|
||||
Creating a dialog
|
||||
================
|
||||
|
||||
1. Add imports:
|
||||
|
||||
import { wrap as wrapDialog, DialogPropType } from 'path/to/DialogWrapper';
|
||||
|
||||
2. define a `dialog` property on your component:
|
||||
|
||||
propTypes = {
|
||||
dialog: DialogPropType.isRequired,
|
||||
};
|
||||
|
||||
`dialog` property is an object:
|
||||
|
||||
{
|
||||
props: object, // properties for <Modal> component;
|
||||
close: (result) => void, // method to confirm dialog; `result` will be returned to caller
|
||||
dismiss: (reason) => void, // method to reject dialog; `reason` will be returned to caller
|
||||
}
|
||||
|
||||
3. expand additional properties on <Modal> component:
|
||||
|
||||
render() {
|
||||
const { dialog } = this.props;
|
||||
return (
|
||||
<Modal {...dialog.props}>
|
||||
);
|
||||
}
|
||||
|
||||
4. wrap your component and export it:
|
||||
|
||||
export default wrapDialog(YourComponent).
|
||||
|
||||
Your component is ready to use. Wrapper will manage <Modal>'s visibility and events.
|
||||
If you want to override behavior of `onOk`/`onCancel` - don't forget to close dialog:
|
||||
|
||||
customOkHandler() {
|
||||
this.saveData().then(() => {
|
||||
this.props.dialog.close({ success: true }); // or dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { dialog } = this.props;
|
||||
return (
|
||||
<Modal {...dialog.props} onOk={() => this.customOkHandler()}>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Settings
|
||||
========
|
||||
|
||||
You can setup this wrapper to use custom `Promise` library (for example, Bluebird):
|
||||
|
||||
import DialogWrapper from 'path/to/DialogWrapper';
|
||||
import Promise from 'bluebird';
|
||||
|
||||
DialogWrapper.Promise = Promise;
|
||||
|
||||
It could be useful to avoid `unhandledrejection` exception that would fire with native Promises,
|
||||
or when some custom Promise library is used in application.
|
||||
|
||||
*/
|
||||
|
||||
export const DialogPropType = PropTypes.shape({
|
||||
props: PropTypes.shape({
|
||||
visible: PropTypes.bool,
|
||||
onOk: PropTypes.func,
|
||||
onCancel: PropTypes.func,
|
||||
afterClose: PropTypes.func,
|
||||
}).isRequired,
|
||||
close: PropTypes.func.isRequired,
|
||||
dismiss: PropTypes.func.isRequired,
|
||||
});
|
||||
|
||||
// default export of module
|
||||
const DialogWrapper = {
|
||||
Promise,
|
||||
DialogPropType,
|
||||
wrap() {},
|
||||
};
|
||||
|
||||
function openDialog(DialogComponent, props) {
|
||||
const dialog = {
|
||||
props: {
|
||||
visible: true,
|
||||
onOk: () => {},
|
||||
onCancel: () => {},
|
||||
afterClose: () => {},
|
||||
},
|
||||
close: () => {},
|
||||
dismiss: () => {},
|
||||
};
|
||||
|
||||
const dialogResult = {
|
||||
resolve: () => {},
|
||||
reject: () => {},
|
||||
};
|
||||
|
||||
const container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
|
||||
function render() {
|
||||
ReactDOM.render(<DialogComponent {...props} dialog={dialog} />, container);
|
||||
}
|
||||
|
||||
function destroyDialog() {
|
||||
// Allow calling chain to roll up, and then destroy component
|
||||
setTimeout(() => {
|
||||
ReactDOM.unmountComponentAtNode(container);
|
||||
document.body.removeChild(container);
|
||||
}, 10);
|
||||
}
|
||||
|
||||
function closeDialog(result) {
|
||||
dialogResult.resolve(result);
|
||||
dialog.props.visible = false;
|
||||
render();
|
||||
}
|
||||
|
||||
function dismissDialog(reason) {
|
||||
dialogResult.reject(reason);
|
||||
dialog.props.visible = false;
|
||||
render();
|
||||
}
|
||||
|
||||
dialog.props.onOk = closeDialog;
|
||||
dialog.props.onCancel = dismissDialog;
|
||||
dialog.props.afterClose = destroyDialog;
|
||||
dialog.close = closeDialog;
|
||||
dialog.dismiss = dismissDialog;
|
||||
|
||||
const result = {
|
||||
close: closeDialog,
|
||||
dismiss: dismissDialog,
|
||||
update: newProps => {
|
||||
props = { ...props, ...newProps };
|
||||
render();
|
||||
},
|
||||
result: new DialogWrapper.Promise((resolve, reject) => {
|
||||
dialogResult.resolve = resolve;
|
||||
dialogResult.reject = reject;
|
||||
}),
|
||||
};
|
||||
|
||||
render(); // show it only when all structures initialized to avoid unnecessary re-rendering
|
||||
|
||||
// Some known libraries support
|
||||
// Bluebird: http://bluebirdjs.com/docs/api/suppressunhandledrejections.html
|
||||
if (isFunction(result.result.suppressUnhandledRejections)) {
|
||||
result.result.suppressUnhandledRejections();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function wrap(DialogComponent) {
|
||||
return {
|
||||
Component: DialogComponent,
|
||||
showModal: props => openDialog(DialogComponent, props),
|
||||
};
|
||||
}
|
||||
|
||||
DialogWrapper.wrap = wrap;
|
||||
|
||||
export default DialogWrapper;
|
||||
223
client/app/components/DialogWrapper.tsx
Normal file
223
client/app/components/DialogWrapper.tsx
Normal file
@@ -0,0 +1,223 @@
|
||||
import { isFunction } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import ReactDOM from "react-dom";
|
||||
type DialogPropType = {
|
||||
props: {
|
||||
visible?: boolean;
|
||||
onOk?: (...args: any[]) => any;
|
||||
onCancel?: (...args: any[]) => any;
|
||||
afterClose?: (...args: any[]) => any;
|
||||
};
|
||||
close: (...args: any[]) => any;
|
||||
dismiss: (...args: any[]) => any;
|
||||
};
|
||||
/**
|
||||
Wrapper for dialogs based on Ant's <Modal> component.
|
||||
|
||||
|
||||
Using wrapped dialogs
|
||||
=====================
|
||||
|
||||
Wrapped component is an object with two fields:
|
||||
|
||||
{
|
||||
showModal: (dialogProps) => object({
|
||||
close: (result) => void,
|
||||
dismiss: (reason) => void,
|
||||
onClose: (handler) => this,
|
||||
onDismiss: (handler) => this,
|
||||
}),
|
||||
Component: React.Component, // wrapped dialog component
|
||||
}
|
||||
|
||||
To open dialog, use `showModal` method; optionally you can pass additional properties that
|
||||
will be expanded on wrapped component:
|
||||
|
||||
const dialog = SomeWrappedDialog.showModal()
|
||||
|
||||
const dialog = SomeWrappedDialog.showModal({ greeting: 'Hello' })
|
||||
|
||||
To get result of modal, use `onClose`/`onDismiss` setters:
|
||||
|
||||
dialog
|
||||
.onClose(result => { ... }) // pressed OK button or used `close` method
|
||||
.onDismiss(result => { ... }) // pressed Cancel button or used `dismiss` method
|
||||
|
||||
If `onClose`/`onDismiss` returns a promise - dialog wrapper will stop handling further close/dismiss
|
||||
requests and will show loader on a corresponding button until that promise is fulfilled (either resolved or
|
||||
rejected). If that promise will be rejected - dialog close/dismiss will be abandoned. Use promise returned
|
||||
from `close`/`dismiss` methods to handle errors (if needed).
|
||||
|
||||
Also, dialog has `close` and `dismiss` methods that allows to close dialog by caller. Passed arguments
|
||||
will be passed to a corresponding handler. Both methods will return the promise returned from `onClose` and
|
||||
`onDismiss` callbacks. `update` method allows to pass new properties to dialog.
|
||||
|
||||
|
||||
Creating a dialog
|
||||
================
|
||||
|
||||
1. Add imports:
|
||||
|
||||
import { wrap as wrapDialog, DialogPropType } from 'path/to/DialogWrapper';
|
||||
|
||||
2. define a `dialog` property on your component:
|
||||
|
||||
propTypes = {
|
||||
dialog: DialogPropType.isRequired,
|
||||
};
|
||||
|
||||
`dialog` property is an object:
|
||||
|
||||
{
|
||||
props: object, // properties for <Modal> component;
|
||||
close: (result) => void, // method to confirm dialog; `result` will be returned to caller
|
||||
dismiss: (reason) => void, // method to reject dialog; `reason` will be returned to caller
|
||||
}
|
||||
|
||||
3. expand additional properties on <Modal> component:
|
||||
|
||||
render() {
|
||||
const { dialog } = this.props;
|
||||
return (
|
||||
<Modal {...dialog.props}>
|
||||
);
|
||||
}
|
||||
|
||||
4. wrap your component and it:
|
||||
|
||||
export default wrapDialog(YourComponent).
|
||||
|
||||
Your component is ready to use. Wrapper will manage <Modal>'s visibility and events.
|
||||
If you want to override behavior of `onOk`/`onCancel` - don't forget to close dialog:
|
||||
|
||||
customOkHandler() {
|
||||
this.saveData().then(() => {
|
||||
this.props.dialog.close({ success: true }); // or dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { dialog } = this.props;
|
||||
return (
|
||||
<Modal {...dialog.props} onOk={() => this.customOkHandler()}>
|
||||
);
|
||||
}
|
||||
*/
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Requireable<InferProps<{ props: Validator<In... Remove this comment to see the full error message
|
||||
export const DialogPropType: PropTypes.Requireable<DialogPropType> = PropTypes.shape({
|
||||
props: PropTypes.shape({
|
||||
visible: PropTypes.bool,
|
||||
onOk: PropTypes.func,
|
||||
onCancel: PropTypes.func,
|
||||
afterClose: PropTypes.func,
|
||||
}).isRequired,
|
||||
close: PropTypes.func.isRequired,
|
||||
dismiss: PropTypes.func.isRequired,
|
||||
});
|
||||
|
||||
function openDialog(DialogComponent: any, props: any) {
|
||||
const dialog = {
|
||||
props: {
|
||||
visible: true,
|
||||
okButtonProps: {},
|
||||
cancelButtonProps: {},
|
||||
onOk: () => { },
|
||||
onCancel: () => { },
|
||||
afterClose: () => { },
|
||||
},
|
||||
close: () => { },
|
||||
dismiss: () => { },
|
||||
};
|
||||
let pendingCloseTask: any = null;
|
||||
const handlers = {
|
||||
onClose: () => { },
|
||||
onDismiss: () => { },
|
||||
};
|
||||
const container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
function render() {
|
||||
ReactDOM.render(<DialogComponent {...props} dialog={dialog}/>, container);
|
||||
}
|
||||
function destroyDialog() {
|
||||
// Allow calling chain to roll up, and then destroy component
|
||||
setTimeout(() => {
|
||||
ReactDOM.unmountComponentAtNode(container);
|
||||
document.body.removeChild(container);
|
||||
}, 10);
|
||||
}
|
||||
function processDialogClose(result: any, setAdditionalDialogProps: any) {
|
||||
dialog.props.okButtonProps = { disabled: true };
|
||||
dialog.props.cancelButtonProps = { disabled: true };
|
||||
setAdditionalDialogProps();
|
||||
render();
|
||||
return Promise.resolve(result)
|
||||
.then(() => {
|
||||
dialog.props.visible = false;
|
||||
})
|
||||
.finally(() => {
|
||||
dialog.props.okButtonProps = {};
|
||||
dialog.props.cancelButtonProps = {};
|
||||
render();
|
||||
});
|
||||
}
|
||||
function closeDialog(result: any) {
|
||||
if (!pendingCloseTask) {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
|
||||
pendingCloseTask = processDialogClose(handlers.onClose(result), () => {
|
||||
(dialog.props.okButtonProps as any).loading = true;
|
||||
}).finally(() => {
|
||||
pendingCloseTask = null;
|
||||
});
|
||||
}
|
||||
return pendingCloseTask;
|
||||
}
|
||||
function dismissDialog(result: any) {
|
||||
if (!pendingCloseTask) {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
|
||||
pendingCloseTask = processDialogClose(handlers.onDismiss(result), () => {
|
||||
(dialog.props.cancelButtonProps as any).loading = true;
|
||||
}).finally(() => {
|
||||
pendingCloseTask = null;
|
||||
});
|
||||
}
|
||||
return pendingCloseTask;
|
||||
}
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type '(result: any) => any' is not assignable to t... Remove this comment to see the full error message
|
||||
dialog.props.onOk = closeDialog;
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type '(result: any) => any' is not assignable to t... Remove this comment to see the full error message
|
||||
dialog.props.onCancel = dismissDialog;
|
||||
dialog.props.afterClose = destroyDialog;
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type '(result: any) => any' is not assignable to t... Remove this comment to see the full error message
|
||||
dialog.close = closeDialog;
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type '(result: any) => any' is not assignable to t... Remove this comment to see the full error message
|
||||
dialog.dismiss = dismissDialog;
|
||||
const result = {
|
||||
close: closeDialog,
|
||||
dismiss: dismissDialog,
|
||||
update: (newProps: any) => {
|
||||
props = { ...props, ...newProps };
|
||||
render();
|
||||
},
|
||||
onClose: (handler: any) => {
|
||||
if (isFunction(handler)) {
|
||||
handlers.onClose = handler;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
onDismiss: (handler: any) => {
|
||||
if (isFunction(handler)) {
|
||||
handlers.onDismiss = handler;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
render(); // show it only when all structures initialized to avoid unnecessary re-rendering
|
||||
return result;
|
||||
}
|
||||
export function wrap(DialogComponent: any) {
|
||||
return {
|
||||
Component: DialogComponent,
|
||||
showModal: (props: any) => openDialog(DialogComponent, props),
|
||||
};
|
||||
}
|
||||
@@ -1,31 +1,35 @@
|
||||
import { isFunction, isString } from "lodash";
|
||||
import { isFunction, isString, isUndefined } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
const componentsRegistry = new Map();
|
||||
const activeInstances = new Set();
|
||||
|
||||
export function registerComponent(name, component) {
|
||||
export function registerComponent(name: any, component: any) {
|
||||
if (isString(name) && name !== "") {
|
||||
componentsRegistry.set(name, isFunction(component) ? component : null);
|
||||
// Refresh active DynamicComponent instances which use this component
|
||||
activeInstances.forEach(dynamicComponent => {
|
||||
// @ts-expect-error ts-migrate(2571) FIXME: Object is of type 'unknown'.
|
||||
if (dynamicComponent.props.name === name) {
|
||||
// @ts-expect-error ts-migrate(2571) FIXME: Object is of type 'unknown'.
|
||||
dynamicComponent.forceUpdate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function unregisterComponent(name) {
|
||||
export function unregisterComponent(name: any) {
|
||||
registerComponent(name, null);
|
||||
}
|
||||
|
||||
export default class DynamicComponent extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
type OwnProps = {
|
||||
name: string;
|
||||
fallback?: React.ReactNode;
|
||||
};
|
||||
|
||||
type Props = OwnProps & typeof DynamicComponent.defaultProps;
|
||||
|
||||
export default class DynamicComponent extends React.Component<Props> {
|
||||
|
||||
static defaultProps = {
|
||||
children: null,
|
||||
@@ -40,10 +44,11 @@ export default class DynamicComponent extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { name, children, ...props } = this.props;
|
||||
const { name, children, fallback, ...props } = this.props;
|
||||
const RealComponent = componentsRegistry.get(name);
|
||||
if (!RealComponent) {
|
||||
return children;
|
||||
// return fallback if any, otherwise return children
|
||||
return isUndefined(fallback) ? children : fallback;
|
||||
}
|
||||
return <RealComponent {...props}>{children}</RealComponent>;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
import { trim } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import cx from "classnames";
|
||||
import Input from "antd/lib/input";
|
||||
|
||||
export default class EditInPlace extends React.Component {
|
||||
static propTypes = {
|
||||
ignoreBlanks: PropTypes.bool,
|
||||
isEditable: PropTypes.bool,
|
||||
placeholder: PropTypes.string,
|
||||
value: PropTypes.string,
|
||||
onDone: PropTypes.func.isRequired,
|
||||
multiline: PropTypes.bool,
|
||||
editorProps: PropTypes.object,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
ignoreBlanks: false,
|
||||
isEditable: true,
|
||||
placeholder: "",
|
||||
value: "",
|
||||
multiline: false,
|
||||
editorProps: {},
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
editing: false,
|
||||
};
|
||||
this.inputRef = React.createRef();
|
||||
}
|
||||
|
||||
componentDidUpdate(_, prevState) {
|
||||
if (this.state.editing && !prevState.editing) {
|
||||
this.inputRef.current.focus();
|
||||
}
|
||||
}
|
||||
|
||||
startEditing = () => {
|
||||
if (this.props.isEditable) {
|
||||
this.setState({ editing: true });
|
||||
}
|
||||
};
|
||||
|
||||
stopEditing = currentValue => {
|
||||
const newValue = trim(currentValue);
|
||||
const ignorableBlank = this.props.ignoreBlanks && newValue === "";
|
||||
if (!ignorableBlank && newValue !== this.props.value) {
|
||||
this.props.onDone(newValue);
|
||||
}
|
||||
this.setState({ editing: false });
|
||||
};
|
||||
|
||||
handleKeyDown = event => {
|
||||
if (event.keyCode === 13 && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
this.stopEditing(event.target.value);
|
||||
} else if (event.keyCode === 27) {
|
||||
this.setState({ editing: false });
|
||||
}
|
||||
};
|
||||
|
||||
renderNormal = () => (
|
||||
<span
|
||||
role="presentation"
|
||||
onFocus={this.startEditing}
|
||||
onClick={this.startEditing}
|
||||
className={this.props.isEditable ? "editable" : ""}>
|
||||
{this.props.value || this.props.placeholder}
|
||||
</span>
|
||||
);
|
||||
|
||||
renderEdit = () => {
|
||||
const { multiline, value, editorProps } = this.props;
|
||||
const InputComponent = multiline ? Input.TextArea : Input;
|
||||
return (
|
||||
<InputComponent
|
||||
ref={this.inputRef}
|
||||
defaultValue={value}
|
||||
onBlur={e => this.stopEditing(e.target.value)}
|
||||
onKeyDown={this.handleKeyDown}
|
||||
{...editorProps}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<span className={cx("edit-in-place", { active: this.state.editing }, this.props.className)}>
|
||||
{this.state.editing ? this.renderEdit() : this.renderNormal()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
}
|
||||
77
client/app/components/EditInPlace.tsx
Normal file
77
client/app/components/EditInPlace.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import { trim } from "lodash";
|
||||
import React from "react";
|
||||
import cx from "classnames";
|
||||
import Input from "antd/lib/input";
|
||||
type OwnProps = {
|
||||
ignoreBlanks?: boolean;
|
||||
isEditable?: boolean;
|
||||
placeholder?: string;
|
||||
value?: string;
|
||||
onDone: (...args: any[]) => any;
|
||||
onStopEditing?: (...args: any[]) => any;
|
||||
multiline?: boolean;
|
||||
editorProps?: any;
|
||||
defaultEditing?: boolean;
|
||||
};
|
||||
type State = any;
|
||||
type Props = OwnProps & typeof EditInPlace.defaultProps;
|
||||
export default class EditInPlace extends React.Component<Props, State> {
|
||||
static defaultProps = {
|
||||
ignoreBlanks: false,
|
||||
isEditable: true,
|
||||
placeholder: "",
|
||||
value: "",
|
||||
onStopEditing: () => { },
|
||||
multiline: false,
|
||||
editorProps: {},
|
||||
defaultEditing: false,
|
||||
};
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
editing: props.defaultEditing,
|
||||
};
|
||||
}
|
||||
componentDidUpdate(_: Props, prevState: State) {
|
||||
if (!this.state.editing && prevState.editing) {
|
||||
this.props.onStopEditing();
|
||||
}
|
||||
}
|
||||
startEditing = () => {
|
||||
if (this.props.isEditable) {
|
||||
this.setState({ editing: true });
|
||||
}
|
||||
};
|
||||
stopEditing = (currentValue: any) => {
|
||||
const newValue = trim(currentValue);
|
||||
const ignorableBlank = this.props.ignoreBlanks && newValue === "";
|
||||
if (!ignorableBlank && newValue !== this.props.value) {
|
||||
this.props.onDone(newValue);
|
||||
}
|
||||
this.setState({ editing: false });
|
||||
};
|
||||
handleKeyDown = (event: any) => {
|
||||
if (event.keyCode === 13 && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
this.stopEditing(event.target.value);
|
||||
}
|
||||
else if (event.keyCode === 27) {
|
||||
this.setState({ editing: false });
|
||||
}
|
||||
};
|
||||
renderNormal = () => this.props.value ? (<span role="presentation" onFocus={this.startEditing} onClick={this.startEditing} className={this.props.isEditable ? "editable" : ""}>
|
||||
{this.props.value}
|
||||
</span>) : (<a className="clickable" onClick={this.startEditing}>
|
||||
{this.props.placeholder}
|
||||
</a>);
|
||||
renderEdit = () => {
|
||||
const { multiline, value, editorProps } = this.props;
|
||||
const InputComponent = multiline ? Input.TextArea : Input;
|
||||
return (<InputComponent defaultValue={value} onBlur={(e: any) => this.stopEditing(e.target.value)} onKeyDown={this.handleKeyDown} autoFocus {...editorProps}/>);
|
||||
};
|
||||
render() {
|
||||
return (<span className={cx("edit-in-place", { active: this.state.editing }, (this.props as any).className)}>
|
||||
{this.state.editing ? this.renderEdit() : this.renderNormal()}
|
||||
</span>);
|
||||
}
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
import { includes, words, capitalize, clone, isNull } from "lodash";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import Checkbox from "antd/lib/checkbox";
|
||||
import Modal from "antd/lib/modal";
|
||||
import Form from "antd/lib/form";
|
||||
import Button from "antd/lib/button";
|
||||
import Select from "antd/lib/select";
|
||||
import Input from "antd/lib/input";
|
||||
import Divider from "antd/lib/divider";
|
||||
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
|
||||
import QuerySelector from "@/components/QuerySelector";
|
||||
import { Query } from "@/services/query";
|
||||
|
||||
const { Option } = Select;
|
||||
const formItemProps = { labelCol: { span: 6 }, wrapperCol: { span: 16 } };
|
||||
|
||||
function getDefaultTitle(text) {
|
||||
return capitalize(words(text).join(" ")); // humanize
|
||||
}
|
||||
|
||||
function isTypeDateRange(type) {
|
||||
return /-range/.test(type);
|
||||
}
|
||||
|
||||
function joinExampleList(multiValuesOptions) {
|
||||
const { prefix, suffix } = multiValuesOptions;
|
||||
return ["value1", "value2", "value3"].map(value => `${prefix}${value}${suffix}`).join(",");
|
||||
}
|
||||
|
||||
function NameInput({ name, type, onChange, existingNames, setValidation }) {
|
||||
let helpText = "";
|
||||
let validateStatus = "";
|
||||
|
||||
if (!name) {
|
||||
helpText = "Choose a keyword for this parameter";
|
||||
setValidation(false);
|
||||
} else if (includes(existingNames, name)) {
|
||||
helpText = "Parameter with this name already exists";
|
||||
setValidation(false);
|
||||
validateStatus = "error";
|
||||
} else {
|
||||
if (isTypeDateRange(type)) {
|
||||
helpText = (
|
||||
<React.Fragment>
|
||||
Appears in query as{" "}
|
||||
<code style={{ display: "inline-block", color: "inherit" }}>{`{{${name}.start}} {{${name}.end}}`}</code>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
setValidation(true);
|
||||
}
|
||||
|
||||
return (
|
||||
<Form.Item required label="Keyword" help={helpText} validateStatus={validateStatus} {...formItemProps}>
|
||||
<Input onChange={e => onChange(e.target.value)} autoFocus />
|
||||
</Form.Item>
|
||||
);
|
||||
}
|
||||
|
||||
NameInput.propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
existingNames: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||
setValidation: PropTypes.func.isRequired,
|
||||
type: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
function EditParameterSettingsDialog(props) {
|
||||
const [param, setParam] = useState(clone(props.parameter));
|
||||
const [isNameValid, setIsNameValid] = useState(true);
|
||||
const [initialQuery, setInitialQuery] = useState();
|
||||
|
||||
const isNew = !props.parameter.name;
|
||||
|
||||
// fetch query by id
|
||||
useEffect(() => {
|
||||
const queryId = props.parameter.queryId;
|
||||
if (queryId) {
|
||||
Query.get({ id: queryId }).then(setInitialQuery);
|
||||
}
|
||||
}, [props.parameter.queryId]);
|
||||
|
||||
function isFulfilled() {
|
||||
// name
|
||||
if (!isNameValid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// title
|
||||
if (param.title === "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// query
|
||||
if (param.type === "query" && !param.queryId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function onConfirm(e) {
|
||||
// update title to default
|
||||
if (!param.title) {
|
||||
// forced to do this cause param won't update in time for save
|
||||
param.title = getDefaultTitle(param.name);
|
||||
setParam(param);
|
||||
}
|
||||
|
||||
props.dialog.close(param);
|
||||
|
||||
e.preventDefault(); // stops form redirect
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
{...props.dialog.props}
|
||||
title={isNew ? "Add Parameter" : param.name}
|
||||
width={600}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={props.dialog.dismiss}>
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button
|
||||
key="submit"
|
||||
htmlType="submit"
|
||||
disabled={!isFulfilled()}
|
||||
type="primary"
|
||||
form="paramForm"
|
||||
data-test="SaveParameterSettings">
|
||||
{isNew ? "Add Parameter" : "OK"}
|
||||
</Button>,
|
||||
]}>
|
||||
<Form layout="horizontal" onSubmit={onConfirm} id="paramForm">
|
||||
{isNew && (
|
||||
<NameInput
|
||||
name={param.name}
|
||||
onChange={name => setParam({ ...param, name })}
|
||||
setValidation={setIsNameValid}
|
||||
existingNames={props.existingParams}
|
||||
type={param.type}
|
||||
/>
|
||||
)}
|
||||
<Form.Item label="Title" {...formItemProps}>
|
||||
<Input
|
||||
value={isNull(param.title) ? getDefaultTitle(param.name) : param.title}
|
||||
onChange={e => setParam({ ...param, title: e.target.value })}
|
||||
data-test="ParameterTitleInput"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="Type" {...formItemProps}>
|
||||
<Select value={param.type} onChange={type => setParam({ ...param, type })} data-test="ParameterTypeSelect">
|
||||
<Option value="text" data-test="TextParameterTypeOption">
|
||||
Text
|
||||
</Option>
|
||||
<Option value="number" data-test="NumberParameterTypeOption">
|
||||
Number
|
||||
</Option>
|
||||
<Option value="enum">Dropdown List</Option>
|
||||
<Option value="query">Query Based Dropdown List</Option>
|
||||
<Option disabled key="dv1">
|
||||
<Divider className="select-option-divider" />
|
||||
</Option>
|
||||
<Option value="date" data-test="DateParameterTypeOption">
|
||||
Date
|
||||
</Option>
|
||||
<Option value="datetime-local" data-test="DateTimeParameterTypeOption">
|
||||
Date and Time
|
||||
</Option>
|
||||
<Option value="datetime-with-seconds">Date and Time (with seconds)</Option>
|
||||
<Option disabled key="dv2">
|
||||
<Divider className="select-option-divider" />
|
||||
</Option>
|
||||
<Option value="date-range" data-test="DateRangeParameterTypeOption">
|
||||
Date Range
|
||||
</Option>
|
||||
<Option value="datetime-range">Date and Time Range</Option>
|
||||
<Option value="datetime-range-with-seconds">Date and Time Range (with seconds)</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
{param.type === "enum" && (
|
||||
<Form.Item label="Values" help="Dropdown list values (newline delimited)" {...formItemProps}>
|
||||
<Input.TextArea
|
||||
rows={3}
|
||||
value={param.enumOptions}
|
||||
onChange={e => setParam({ ...param, enumOptions: e.target.value })}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
{param.type === "query" && (
|
||||
<Form.Item label="Query" help="Select query to load dropdown values from" {...formItemProps}>
|
||||
<QuerySelector
|
||||
selectedQuery={initialQuery}
|
||||
onChange={q => setParam({ ...param, queryId: q && q.id })}
|
||||
type="select"
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
{(param.type === "enum" || param.type === "query") && (
|
||||
<Form.Item className="m-b-0" label=" " colon={false} {...formItemProps}>
|
||||
<Checkbox
|
||||
defaultChecked={!!param.multiValuesOptions}
|
||||
onChange={e =>
|
||||
setParam({
|
||||
...param,
|
||||
multiValuesOptions: e.target.checked
|
||||
? {
|
||||
prefix: "",
|
||||
suffix: "",
|
||||
separator: ",",
|
||||
}
|
||||
: null,
|
||||
})
|
||||
}
|
||||
data-test="AllowMultipleValuesCheckbox">
|
||||
Allow multiple values
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
)}
|
||||
{(param.type === "enum" || param.type === "query") && param.multiValuesOptions && (
|
||||
<Form.Item
|
||||
label="Quotation"
|
||||
help={
|
||||
<React.Fragment>
|
||||
Placed in query as: <code>{joinExampleList(param.multiValuesOptions)}</code>
|
||||
</React.Fragment>
|
||||
}
|
||||
{...formItemProps}>
|
||||
<Select
|
||||
value={param.multiValuesOptions.prefix}
|
||||
onChange={quoteOption =>
|
||||
setParam({
|
||||
...param,
|
||||
multiValuesOptions: {
|
||||
...param.multiValuesOptions,
|
||||
prefix: quoteOption,
|
||||
suffix: quoteOption,
|
||||
},
|
||||
})
|
||||
}
|
||||
data-test="QuotationSelect">
|
||||
<Option value="">None (default)</Option>
|
||||
<Option value="'">Single Quotation Mark</Option>
|
||||
<Option value={'"'} data-test="DoubleQuotationMarkOption">
|
||||
Double Quotation Mark
|
||||
</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
EditParameterSettingsDialog.propTypes = {
|
||||
parameter: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
|
||||
dialog: DialogPropType.isRequired,
|
||||
existingParams: PropTypes.arrayOf(PropTypes.string),
|
||||
};
|
||||
|
||||
EditParameterSettingsDialog.defaultProps = {
|
||||
existingParams: [],
|
||||
};
|
||||
|
||||
export default wrapDialog(EditParameterSettingsDialog);
|
||||
193
client/app/components/EditParameterSettingsDialog.tsx
Normal file
193
client/app/components/EditParameterSettingsDialog.tsx
Normal file
@@ -0,0 +1,193 @@
|
||||
import { includes, words, capitalize, clone, isNull } from "lodash";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import Checkbox from "antd/lib/checkbox";
|
||||
import Modal from "antd/lib/modal";
|
||||
import Form from "antd/lib/form";
|
||||
import Button from "antd/lib/button";
|
||||
import Select from "antd/lib/select";
|
||||
import Input from "antd/lib/input";
|
||||
import Divider from "antd/lib/divider";
|
||||
// @ts-expect-error ts-migrate(6133) FIXME: 'DialogPropType' is declared but its value is neve... Remove this comment to see the full error message
|
||||
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper";
|
||||
import QuerySelector from "@/components/QuerySelector";
|
||||
import { Query } from "@/services/query";
|
||||
const { Option } = Select;
|
||||
const formItemProps = { labelCol: { span: 6 }, wrapperCol: { span: 16 } };
|
||||
function getDefaultTitle(text: any) {
|
||||
return capitalize(words(text).join(" ")); // humanize
|
||||
}
|
||||
function isTypeDateRange(type: any) {
|
||||
return /-range/.test(type);
|
||||
}
|
||||
function joinExampleList(multiValuesOptions: any) {
|
||||
const { prefix, suffix } = multiValuesOptions;
|
||||
return ["value1", "value2", "value3"].map(value => `${prefix}${value}${suffix}`).join(",");
|
||||
}
|
||||
type NameInputProps = {
|
||||
name: string;
|
||||
onChange: (...args: any[]) => any;
|
||||
existingNames: string[];
|
||||
setValidation: (...args: any[]) => any;
|
||||
type: string;
|
||||
};
|
||||
function NameInput({ name, type, onChange, existingNames, setValidation }: NameInputProps) {
|
||||
let helpText = "";
|
||||
let validateStatus = "";
|
||||
if (!name) {
|
||||
helpText = "Choose a keyword for this parameter";
|
||||
setValidation(false);
|
||||
}
|
||||
else if (includes(existingNames, name)) {
|
||||
helpText = "Parameter with this name already exists";
|
||||
setValidation(false);
|
||||
validateStatus = "error";
|
||||
}
|
||||
else {
|
||||
if (isTypeDateRange(type)) {
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Element' is not assignable to type 'string'.
|
||||
helpText = (<React.Fragment>
|
||||
Appears in query as{" "}
|
||||
<code style={{ display: "inline-block", color: "inherit" }}>{`{{${name}.start}} {{${name}.end}}`}</code>
|
||||
</React.Fragment>);
|
||||
}
|
||||
setValidation(true);
|
||||
}
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type '"" | "err... Remove this comment to see the full error message
|
||||
return (<Form.Item required label="Keyword" help={helpText} validateStatus={validateStatus} {...formItemProps}>
|
||||
<Input onChange={e => onChange(e.target.value)} autoFocus/>
|
||||
</Form.Item>);
|
||||
}
|
||||
type OwnEditParameterSettingsDialogProps = {
|
||||
parameter: any;
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'DialogPropType' refers to a value, but is being u... Remove this comment to see the full error message
|
||||
dialog: DialogPropType;
|
||||
existingParams?: string[];
|
||||
};
|
||||
type EditParameterSettingsDialogProps = OwnEditParameterSettingsDialogProps & typeof EditParameterSettingsDialog.defaultProps;
|
||||
function EditParameterSettingsDialog(props: EditParameterSettingsDialogProps) {
|
||||
const [param, setParam] = useState(clone(props.parameter));
|
||||
const [isNameValid, setIsNameValid] = useState(true);
|
||||
const [initialQuery, setInitialQuery] = useState();
|
||||
const isNew = !props.parameter.name;
|
||||
// fetch query by id
|
||||
useEffect(() => {
|
||||
const queryId = props.parameter.queryId;
|
||||
if (queryId) {
|
||||
(Query as any).get({ id: queryId }).then(setInitialQuery);
|
||||
}
|
||||
}, [props.parameter.queryId]);
|
||||
function isFulfilled() {
|
||||
// name
|
||||
if (!isNameValid) {
|
||||
return false;
|
||||
}
|
||||
// title
|
||||
if (param.title === "") {
|
||||
return false;
|
||||
}
|
||||
// query
|
||||
if (param.type === "query" && !param.queryId) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function onConfirm() {
|
||||
// update title to default
|
||||
if (!param.title) {
|
||||
// forced to do this cause param won't update in time for save
|
||||
param.title = getDefaultTitle(param.name);
|
||||
setParam(param);
|
||||
}
|
||||
props.dialog.close(param);
|
||||
}
|
||||
return (<Modal {...props.dialog.props} title={isNew ? "Add Parameter" : param.name} width={600} footer={[
|
||||
<Button key="cancel" onClick={props.dialog.dismiss}>
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button key="submit" htmlType="submit" disabled={!isFulfilled()} type="primary" form="paramForm" data-test="SaveParameterSettings">
|
||||
{isNew ? "Add Parameter" : "OK"}
|
||||
</Button>,
|
||||
]}>
|
||||
<Form layout="horizontal" onFinish={onConfirm} id="paramForm">
|
||||
{isNew && (<NameInput name={param.name} onChange={name => setParam({ ...param, name })} setValidation={setIsNameValid} existingNames={props.existingParams} type={param.type}/>)}
|
||||
<Form.Item required label="Title" {...formItemProps}>
|
||||
<Input value={isNull(param.title) ? getDefaultTitle(param.name) : param.title} onChange={e => setParam({ ...param, title: e.target.value })} data-test="ParameterTitleInput"/>
|
||||
</Form.Item>
|
||||
<Form.Item label="Type" {...formItemProps}>
|
||||
<Select value={param.type} onChange={type => setParam({ ...param, type })} data-test="ParameterTypeSelect">
|
||||
<Option value="text" data-test="TextParameterTypeOption">
|
||||
Text
|
||||
</Option>
|
||||
<Option value="number" data-test="NumberParameterTypeOption">
|
||||
Number
|
||||
</Option>
|
||||
<Option value="enum">Dropdown List</Option>
|
||||
<Option value="query">Query Based Dropdown List</Option>
|
||||
{/* @ts-expect-error ts-migrate(2741) FIXME: Property 'value' is missing in type '{ children: E... Remove this comment to see the full error message */}
|
||||
<Option disabled key="dv1">
|
||||
<Divider className="select-option-divider"/>
|
||||
</Option>
|
||||
<Option value="date" data-test="DateParameterTypeOption">
|
||||
Date
|
||||
</Option>
|
||||
<Option value="datetime-local" data-test="DateTimeParameterTypeOption">
|
||||
Date and Time
|
||||
</Option>
|
||||
<Option value="datetime-with-seconds">Date and Time (with seconds)</Option>
|
||||
{/* @ts-expect-error ts-migrate(2741) FIXME: Property 'value' is missing in type '{ children: E... Remove this comment to see the full error message */}
|
||||
<Option disabled key="dv2">
|
||||
<Divider className="select-option-divider"/>
|
||||
</Option>
|
||||
<Option value="date-range" data-test="DateRangeParameterTypeOption">
|
||||
Date Range
|
||||
</Option>
|
||||
<Option value="datetime-range">Date and Time Range</Option>
|
||||
<Option value="datetime-range-with-seconds">Date and Time Range (with seconds)</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
{param.type === "enum" && (<Form.Item label="Values" help="Dropdown list values (newline delimited)" {...formItemProps}>
|
||||
<Input.TextArea rows={3} value={param.enumOptions} onChange={e => setParam({ ...param, enumOptions: e.target.value })}/>
|
||||
</Form.Item>)}
|
||||
{param.type === "query" && (<Form.Item label="Query" help="Select query to load dropdown values from" {...formItemProps}>
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'undefined' is not assignable to type 'never'... Remove this comment to see the full error message */}
|
||||
<QuerySelector selectedQuery={initialQuery} onChange={(q: any) => setParam({ ...param, queryId: q && q.id })} type="select"/>
|
||||
</Form.Item>)}
|
||||
{(param.type === "enum" || param.type === "query") && (<Form.Item className="m-b-0" label=" " colon={false} {...formItemProps}>
|
||||
<Checkbox defaultChecked={!!param.multiValuesOptions} onChange={e => setParam({
|
||||
...param,
|
||||
multiValuesOptions: e.target.checked
|
||||
? {
|
||||
prefix: "",
|
||||
suffix: "",
|
||||
separator: ",",
|
||||
}
|
||||
: null,
|
||||
})} data-test="AllowMultipleValuesCheckbox">
|
||||
Allow multiple values
|
||||
</Checkbox>
|
||||
</Form.Item>)}
|
||||
{(param.type === "enum" || param.type === "query") && param.multiValuesOptions && (<Form.Item label="Quotation" help={<React.Fragment>
|
||||
Placed in query as: <code>{joinExampleList(param.multiValuesOptions)}</code>
|
||||
</React.Fragment>} {...formItemProps}>
|
||||
<Select value={param.multiValuesOptions.prefix} onChange={quoteOption => setParam({
|
||||
...param,
|
||||
multiValuesOptions: {
|
||||
...param.multiValuesOptions,
|
||||
prefix: quoteOption,
|
||||
suffix: quoteOption,
|
||||
},
|
||||
})} data-test="QuotationSelect">
|
||||
<Option value="">None (default)</Option>
|
||||
<Option value="'">Single Quotation Mark</Option>
|
||||
<Option value={'"'} data-test="DoubleQuotationMarkOption">
|
||||
Double Quotation Mark
|
||||
</Option>
|
||||
</Select>
|
||||
</Form.Item>)}
|
||||
</Form>
|
||||
</Modal>);
|
||||
}
|
||||
EditParameterSettingsDialog.defaultProps = {
|
||||
existingParams: [],
|
||||
};
|
||||
export default wrapDialog(EditParameterSettingsDialog);
|
||||
@@ -1,88 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import Dropdown from "antd/lib/dropdown";
|
||||
import Menu from "antd/lib/menu";
|
||||
import Button from "antd/lib/button";
|
||||
import Icon from "antd/lib/icon";
|
||||
|
||||
import QueryResultsLink from "./QueryResultsLink";
|
||||
|
||||
export default function QueryControlDropdown(props) {
|
||||
const menu = (
|
||||
<Menu>
|
||||
{!props.query.isNew() && (!props.query.is_draft || !props.query.is_archived) && (
|
||||
<Menu.Item>
|
||||
<a target="_self" onClick={() => props.openAddToDashboardForm(props.selectedTab)}>
|
||||
<Icon type="plus-circle" theme="filled" /> Add to Dashboard
|
||||
</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{!props.query.isNew() && (
|
||||
<Menu.Item>
|
||||
<a onClick={() => props.showEmbedDialog(props.query, props.selectedTab)} data-test="ShowEmbedDialogButton">
|
||||
<Icon type="share-alt" /> Embed Elsewhere
|
||||
</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
<Menu.Item>
|
||||
<QueryResultsLink
|
||||
fileType="csv"
|
||||
disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()}
|
||||
query={props.query}
|
||||
queryResult={props.queryResult}
|
||||
embed={props.embed}
|
||||
apiKey={props.apiKey}>
|
||||
<Icon type="file" /> Download as CSV File
|
||||
</QueryResultsLink>
|
||||
</Menu.Item>
|
||||
<Menu.Item>
|
||||
<QueryResultsLink
|
||||
fileType="tsv"
|
||||
disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()}
|
||||
query={props.query}
|
||||
queryResult={props.queryResult}
|
||||
embed={props.embed}
|
||||
apiKey={props.apiKey}>
|
||||
<Icon type="file" /> Download as TSV File
|
||||
</QueryResultsLink>
|
||||
</Menu.Item>
|
||||
<Menu.Item>
|
||||
<QueryResultsLink
|
||||
fileType="xlsx"
|
||||
disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()}
|
||||
query={props.query}
|
||||
queryResult={props.queryResult}
|
||||
embed={props.embed}
|
||||
apiKey={props.apiKey}>
|
||||
<Icon type="file-excel" /> Download as Excel File
|
||||
</QueryResultsLink>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
);
|
||||
|
||||
return (
|
||||
<Dropdown trigger={["click"]} overlay={menu} overlayClassName="query-control-dropdown-overlay">
|
||||
<Button data-test="QueryControlDropdownButton">
|
||||
<Icon type="ellipsis" rotate={90} />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
QueryControlDropdown.propTypes = {
|
||||
query: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
|
||||
queryResult: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
||||
queryExecuting: PropTypes.bool.isRequired,
|
||||
showEmbedDialog: PropTypes.func.isRequired,
|
||||
embed: PropTypes.bool,
|
||||
apiKey: PropTypes.string,
|
||||
selectedTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
openAddToDashboardForm: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
QueryControlDropdown.defaultProps = {
|
||||
queryResult: {},
|
||||
embed: false,
|
||||
apiKey: "",
|
||||
selectedTab: "",
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
import React from "react";
|
||||
import Dropdown from "antd/lib/dropdown";
|
||||
import Menu from "antd/lib/menu";
|
||||
import Button from "antd/lib/button";
|
||||
import { clientConfig } from "@/services/auth";
|
||||
import PlusCircleFilledIcon from "@ant-design/icons/PlusCircleFilled";
|
||||
import ShareAltOutlinedIcon from "@ant-design/icons/ShareAltOutlined";
|
||||
import FileOutlinedIcon from "@ant-design/icons/FileOutlined";
|
||||
import FileExcelOutlinedIcon from "@ant-design/icons/FileExcelOutlined";
|
||||
import EllipsisOutlinedIcon from "@ant-design/icons/EllipsisOutlined";
|
||||
import QueryResultsLink from "./QueryResultsLink";
|
||||
type OwnProps = {
|
||||
query: any;
|
||||
queryResult?: any;
|
||||
queryExecuting: boolean;
|
||||
showEmbedDialog: (...args: any[]) => any;
|
||||
embed?: boolean;
|
||||
apiKey?: string;
|
||||
selectedTab?: string | number;
|
||||
openAddToDashboardForm: (...args: any[]) => any;
|
||||
};
|
||||
type Props = OwnProps & typeof QueryControlDropdown.defaultProps;
|
||||
export default function QueryControlDropdown(props: Props) {
|
||||
const menu = (<Menu>
|
||||
{!props.query.isNew() && (!props.query.is_draft || !props.query.is_archived) && (<Menu.Item>
|
||||
<a target="_self" onClick={() => props.openAddToDashboardForm(props.selectedTab)}>
|
||||
<PlusCircleFilledIcon /> Add to Dashboard
|
||||
</a>
|
||||
</Menu.Item>)}
|
||||
{!(clientConfig as any).disablePublicUrls && !props.query.isNew() && (<Menu.Item>
|
||||
<a onClick={() => props.showEmbedDialog(props.query, props.selectedTab)} data-test="ShowEmbedDialogButton">
|
||||
<ShareAltOutlinedIcon /> Embed Elsewhere
|
||||
</a>
|
||||
</Menu.Item>)}
|
||||
<Menu.Item>
|
||||
<QueryResultsLink fileType="csv" disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()} query={props.query} queryResult={props.queryResult} embed={props.embed} apiKey={props.apiKey}>
|
||||
<FileOutlinedIcon /> Download as CSV File
|
||||
</QueryResultsLink>
|
||||
</Menu.Item>
|
||||
<Menu.Item>
|
||||
<QueryResultsLink fileType="tsv" disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()} query={props.query} queryResult={props.queryResult} embed={props.embed} apiKey={props.apiKey}>
|
||||
<FileOutlinedIcon /> Download as TSV File
|
||||
</QueryResultsLink>
|
||||
</Menu.Item>
|
||||
<Menu.Item>
|
||||
<QueryResultsLink fileType="xlsx" disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()} query={props.query} queryResult={props.queryResult} embed={props.embed} apiKey={props.apiKey}>
|
||||
<FileExcelOutlinedIcon /> Download as Excel File
|
||||
</QueryResultsLink>
|
||||
</Menu.Item>
|
||||
</Menu>);
|
||||
return (<Dropdown trigger={["click"]} overlay={menu} overlayClassName="query-control-dropdown-overlay">
|
||||
<Button data-test="QueryControlDropdownButton">
|
||||
<EllipsisOutlinedIcon rotate={90}/>
|
||||
</Button>
|
||||
</Dropdown>);
|
||||
}
|
||||
QueryControlDropdown.defaultProps = {
|
||||
queryResult: {},
|
||||
embed: false,
|
||||
apiKey: "",
|
||||
selectedTab: "",
|
||||
};
|
||||
@@ -1,7 +1,19 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import Link from "@/components/Link";
|
||||
|
||||
export default function QueryResultsLink(props) {
|
||||
type OwnProps = {
|
||||
query: any;
|
||||
queryResult?: any;
|
||||
fileType?: string;
|
||||
disabled: boolean;
|
||||
embed?: boolean;
|
||||
apiKey?: string;
|
||||
children: React.ReactNode[] | React.ReactNode;
|
||||
};
|
||||
|
||||
type Props = OwnProps & typeof QueryResultsLink.defaultProps;
|
||||
|
||||
export default function QueryResultsLink(props: Props) {
|
||||
let href = "";
|
||||
|
||||
const { query, queryResult, fileType } = props;
|
||||
@@ -17,22 +29,12 @@ export default function QueryResultsLink(props) {
|
||||
}
|
||||
|
||||
return (
|
||||
<a target="_blank" rel="noopener noreferrer" disabled={props.disabled} href={href} download>
|
||||
<Link target="_blank" rel="noopener noreferrer" disabled={props.disabled} href={href} download>
|
||||
{props.children}
|
||||
</a>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
QueryResultsLink.propTypes = {
|
||||
query: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
|
||||
queryResult: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
||||
fileType: PropTypes.string,
|
||||
disabled: PropTypes.bool.isRequired,
|
||||
embed: PropTypes.bool,
|
||||
apiKey: PropTypes.string,
|
||||
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
||||
};
|
||||
|
||||
QueryResultsLink.defaultProps = {
|
||||
queryResult: {},
|
||||
fileType: "csv",
|
||||
@@ -1,25 +1,26 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import Button from "antd/lib/button";
|
||||
import Icon from "antd/lib/icon";
|
||||
import FormOutlinedIcon from "@ant-design/icons/FormOutlined";
|
||||
|
||||
export default function EditVisualizationButton(props) {
|
||||
type OwnProps = {
|
||||
openVisualizationEditor: (...args: any[]) => any;
|
||||
selectedTab?: string | number;
|
||||
};
|
||||
|
||||
type Props = OwnProps & typeof EditVisualizationButton.defaultProps;
|
||||
|
||||
export default function EditVisualizationButton(props: Props) {
|
||||
return (
|
||||
<Button
|
||||
data-test="EditVisualization"
|
||||
className="edit-visualization"
|
||||
onClick={() => props.openVisualizationEditor(props.selectedTab)}>
|
||||
<Icon type="form" />
|
||||
<FormOutlinedIcon />
|
||||
<span className="hidden-xs hidden-s hidden-m">Edit Visualization</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
EditVisualizationButton.propTypes = {
|
||||
openVisualizationEditor: PropTypes.func.isRequired,
|
||||
selectedTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
};
|
||||
|
||||
EditVisualizationButton.defaultProps = {
|
||||
selectedTab: "",
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import cx from "classnames";
|
||||
import { clientConfig, currentUser } from "@/services/auth";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
import Alert from "antd/lib/alert";
|
||||
import HelpTrigger from "@/components/HelpTrigger";
|
||||
|
||||
export default function EmailSettingsWarning({ featureName, className, mode, adminOnly }) {
|
||||
if (!clientConfig.mailSettingsMissing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (adminOnly && !currentUser.isAdmin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const message = (
|
||||
<span>
|
||||
Your mail server isn't configured correctly, and is needed for {featureName} to work.{" "}
|
||||
<HelpTrigger type="MAIL_CONFIG" className="f-inherit" />
|
||||
</span>
|
||||
);
|
||||
|
||||
if (mode === "icon") {
|
||||
return (
|
||||
<Tooltip title={message}>
|
||||
<i className={cx("fa fa-exclamation-triangle", className)} />
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
return <Alert message={message} type="error" className={className} />;
|
||||
}
|
||||
|
||||
EmailSettingsWarning.propTypes = {
|
||||
featureName: PropTypes.string.isRequired,
|
||||
className: PropTypes.string,
|
||||
mode: PropTypes.oneOf(["alert", "icon"]),
|
||||
adminOnly: PropTypes.bool,
|
||||
};
|
||||
|
||||
EmailSettingsWarning.defaultProps = {
|
||||
className: null,
|
||||
mode: "alert",
|
||||
adminOnly: false,
|
||||
};
|
||||
37
client/app/components/EmailSettingsWarning.tsx
Normal file
37
client/app/components/EmailSettingsWarning.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import React from "react";
|
||||
import cx from "classnames";
|
||||
import { clientConfig, currentUser } from "@/services/auth";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
import Alert from "antd/lib/alert";
|
||||
import HelpTrigger from "@/components/HelpTrigger";
|
||||
type OwnProps = {
|
||||
featureName: string;
|
||||
className?: string;
|
||||
mode?: "alert" | "icon";
|
||||
adminOnly?: boolean;
|
||||
};
|
||||
type Props = OwnProps & typeof EmailSettingsWarning.defaultProps;
|
||||
export default function EmailSettingsWarning({ featureName, className, mode, adminOnly }: Props) {
|
||||
if (!(clientConfig as any).mailSettingsMissing) {
|
||||
return null;
|
||||
}
|
||||
if (adminOnly && !currentUser.isAdmin) {
|
||||
return null;
|
||||
}
|
||||
const message = (<span>
|
||||
Your mail server isn't configured correctly, and is needed for {featureName} to work.{" "}
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'never'. */}
|
||||
<HelpTrigger type="MAIL_CONFIG" className="f-inherit"/>
|
||||
</span>);
|
||||
if (mode === "icon") {
|
||||
return (<Tooltip title={message}>
|
||||
<i className={cx("fa fa-exclamation-triangle", className)}/>
|
||||
</Tooltip>);
|
||||
}
|
||||
return <Alert message={message} type="error" className={className}/>;
|
||||
}
|
||||
EmailSettingsWarning.defaultProps = {
|
||||
className: null,
|
||||
mode: "alert",
|
||||
adminOnly: false,
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
import { isFunction } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import debug from "debug";
|
||||
import Alert from "antd/lib/alert";
|
||||
|
||||
const logger = debug("redash:errors");
|
||||
|
||||
export const ErrorBoundaryContext = React.createContext({
|
||||
handleError: error => {
|
||||
// Allow calling chain to roll up, and then throw the error in global context
|
||||
setTimeout(() => {
|
||||
throw error;
|
||||
});
|
||||
},
|
||||
reset: () => {},
|
||||
});
|
||||
|
||||
export function ErrorMessage({ children }) {
|
||||
return <Alert message={children} type="error" showIcon />;
|
||||
}
|
||||
|
||||
ErrorMessage.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
ErrorMessage.defaultProps = {
|
||||
children: "Something went wrong.",
|
||||
};
|
||||
|
||||
export default class ErrorBoundary extends React.Component {
|
||||
static propTypes = {
|
||||
children: PropTypes.node,
|
||||
renderError: PropTypes.func, // error => ReactNode
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
children: null,
|
||||
renderError: null,
|
||||
};
|
||||
|
||||
state = { error: null };
|
||||
|
||||
handleError = error => {
|
||||
this.setState(this.constructor.getDerivedStateFromError(error));
|
||||
this.componentDidCatch(error, null);
|
||||
};
|
||||
|
||||
reset = () => {
|
||||
this.setState({ error: null });
|
||||
};
|
||||
|
||||
static getDerivedStateFromError(error) {
|
||||
return { error };
|
||||
}
|
||||
|
||||
componentDidCatch(error, errorInfo) {
|
||||
logger(error, errorInfo);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { renderError, children } = this.props;
|
||||
const { error } = this.state;
|
||||
|
||||
if (error) {
|
||||
if (isFunction(renderError)) {
|
||||
return renderError(error);
|
||||
}
|
||||
return <ErrorMessage />;
|
||||
}
|
||||
|
||||
return <ErrorBoundaryContext.Provider value={this}>{children}</ErrorBoundaryContext.Provider>;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
export default class FavoritesControl extends React.Component {
|
||||
static propTypes = {
|
||||
item: PropTypes.shape({
|
||||
is_favorite: PropTypes.bool.isRequired,
|
||||
}).isRequired,
|
||||
onChange: PropTypes.func,
|
||||
};
|
||||
type OwnProps = {
|
||||
item: {
|
||||
is_favorite: boolean;
|
||||
};
|
||||
onChange?: (...args: any[]) => any;
|
||||
};
|
||||
|
||||
type Props = OwnProps & typeof FavoritesControl.defaultProps;
|
||||
|
||||
export default class FavoritesControl extends React.Component<Props> {
|
||||
|
||||
static defaultProps = {
|
||||
onChange: () => {},
|
||||
};
|
||||
|
||||
toggleItem(event, item, callback) {
|
||||
toggleItem(event: any, item: any, callback: any) {
|
||||
const action = item.is_favorite ? item.unfavorite.bind(item) : item.favorite.bind(item);
|
||||
const savedIsFavorite = item.is_favorite;
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
import { isArray, indexOf, get, map, includes, every, some, toNumber } from "lodash";
|
||||
import moment from "moment";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import Select from "antd/lib/select";
|
||||
import { formatColumnValue } from "@/lib/utils";
|
||||
|
||||
const ALL_VALUES = "###Redash::Filters::SelectAll###";
|
||||
const NONE_VALUES = "###Redash::Filters::Clear###";
|
||||
|
||||
export const FilterType = PropTypes.shape({
|
||||
name: PropTypes.string.isRequired,
|
||||
friendlyName: PropTypes.string.isRequired,
|
||||
multiple: PropTypes.bool,
|
||||
current: PropTypes.oneOfType([PropTypes.any, PropTypes.arrayOf(PropTypes.any)]),
|
||||
values: PropTypes.arrayOf(PropTypes.any).isRequired,
|
||||
});
|
||||
|
||||
export const FiltersType = PropTypes.arrayOf(FilterType);
|
||||
|
||||
function createFilterChangeHandler(filters, onChange) {
|
||||
return (filter, values) => {
|
||||
if (isArray(values)) {
|
||||
values = map(values, value => filter.values[toNumber(value.key)] || value.key);
|
||||
} else {
|
||||
const _values = filter.values[toNumber(values.key)];
|
||||
values = _values !== undefined ? _values : values.key;
|
||||
}
|
||||
|
||||
if (filter.multiple && includes(values, ALL_VALUES)) {
|
||||
values = [...filter.values];
|
||||
}
|
||||
if (filter.multiple && includes(values, NONE_VALUES)) {
|
||||
values = [];
|
||||
}
|
||||
filters = map(filters, f => (f.name === filter.name ? { ...filter, current: values } : f));
|
||||
onChange(filters);
|
||||
};
|
||||
}
|
||||
|
||||
export function filterData(rows, filters = []) {
|
||||
if (!isArray(rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let result = rows;
|
||||
|
||||
if (isArray(filters) && filters.length > 0) {
|
||||
// "every" field's value should match "some" of corresponding filter's values
|
||||
result = result.filter(row =>
|
||||
every(filters, filter => {
|
||||
const rowValue = row[filter.name];
|
||||
const filterValues = isArray(filter.current) ? filter.current : [filter.current];
|
||||
return some(filterValues, filterValue => {
|
||||
if (moment.isMoment(rowValue)) {
|
||||
return rowValue.isSame(filterValue);
|
||||
}
|
||||
// We compare with either the value or the String representation of the value,
|
||||
// because Select2 casts true/false to "true"/"false".
|
||||
return filterValue === rowValue || String(rowValue) === filterValue;
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function Filters({ filters, onChange }) {
|
||||
if (filters.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
onChange = createFilterChangeHandler(filters, onChange);
|
||||
|
||||
return (
|
||||
<div className="filters-wrapper">
|
||||
<div className="container bg-white">
|
||||
<div className="row">
|
||||
{map(filters, filter => {
|
||||
const options = map(filter.values, (value, index) => (
|
||||
<Select.Option key={index}>{formatColumnValue(value, get(filter, "column.type"))}</Select.Option>
|
||||
));
|
||||
|
||||
return (
|
||||
<div key={filter.name} className="col-sm-6 p-l-0 filter-container">
|
||||
<label>{filter.friendlyName}</label>
|
||||
{options.length === 0 && <Select className="w-100" disabled value="No values" />}
|
||||
{options.length > 0 && (
|
||||
<Select
|
||||
labelInValue
|
||||
className="w-100"
|
||||
mode={filter.multiple ? "multiple" : "default"}
|
||||
value={
|
||||
isArray(filter.current)
|
||||
? map(filter.current, value => ({
|
||||
key: `${indexOf(filter.values, value)}`,
|
||||
label: formatColumnValue(value),
|
||||
}))
|
||||
: { key: `${indexOf(filter.values, filter.current)}`, label: formatColumnValue(filter.current) }
|
||||
}
|
||||
allowClear={filter.multiple}
|
||||
optionFilterProp="children"
|
||||
showSearch
|
||||
onChange={values => onChange(filter, values)}>
|
||||
{!filter.multiple && options}
|
||||
{filter.multiple && [
|
||||
<Select.Option key={NONE_VALUES}>
|
||||
<i className="fa fa-square-o m-r-5" />
|
||||
Clear
|
||||
</Select.Option>,
|
||||
<Select.Option key={ALL_VALUES}>
|
||||
<i className="fa fa-check-square-o m-r-5" />
|
||||
Select All
|
||||
</Select.Option>,
|
||||
<Select.OptGroup key="Values" title="Values">
|
||||
{options}
|
||||
</Select.OptGroup>,
|
||||
]}
|
||||
</Select>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Filters.propTypes = {
|
||||
filters: FiltersType.isRequired,
|
||||
onChange: PropTypes.func, // (name, value) => void
|
||||
};
|
||||
|
||||
Filters.defaultProps = {
|
||||
onChange: () => {},
|
||||
};
|
||||
|
||||
export default Filters;
|
||||
121
client/app/components/Filters.tsx
Normal file
121
client/app/components/Filters.tsx
Normal file
@@ -0,0 +1,121 @@
|
||||
import { isArray, indexOf, get, map, includes, every, some, toNumber } from "lodash";
|
||||
import moment from "moment";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import Select from "antd/lib/select";
|
||||
import { formatColumnValue } from "@/lib/utils";
|
||||
const ALL_VALUES = "###Redash::Filters::SelectAll###";
|
||||
const NONE_VALUES = "###Redash::Filters::Clear###";
|
||||
type FilterType = {
|
||||
name: string;
|
||||
friendlyName: string;
|
||||
multiple?: boolean;
|
||||
current?: any | any[];
|
||||
values: any[];
|
||||
};
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Requireable<InferProps<{ name: Validator<str... Remove this comment to see the full error message
|
||||
const FilterType: PropTypes.Requireable<FilterType> = PropTypes.shape({
|
||||
name: PropTypes.string.isRequired,
|
||||
friendlyName: PropTypes.string.isRequired,
|
||||
multiple: PropTypes.bool,
|
||||
current: PropTypes.oneOfType([PropTypes.any, PropTypes.arrayOf(PropTypes.any)]),
|
||||
values: PropTypes.arrayOf(PropTypes.any).isRequired,
|
||||
});
|
||||
export { FilterType };
|
||||
export const FiltersType = PropTypes.arrayOf(FilterType);
|
||||
function createFilterChangeHandler(filters: any, onChange: any) {
|
||||
return (filter: any, values: any) => {
|
||||
if (isArray(values)) {
|
||||
values = map(values, value => filter.values[toNumber(value.key)] || value.key);
|
||||
}
|
||||
else {
|
||||
const _values = filter.values[toNumber(values.key)];
|
||||
values = _values !== undefined ? _values : values.key;
|
||||
}
|
||||
if (filter.multiple && includes(values, ALL_VALUES)) {
|
||||
values = [...filter.values];
|
||||
}
|
||||
if (filter.multiple && includes(values, NONE_VALUES)) {
|
||||
values = [];
|
||||
}
|
||||
filters = map(filters, f => (f.name === filter.name ? { ...filter, current: values } : f));
|
||||
onChange(filters);
|
||||
};
|
||||
}
|
||||
export function filterData(rows: any, filters = []) {
|
||||
if (!isArray(rows)) {
|
||||
return [];
|
||||
}
|
||||
let result = rows;
|
||||
if (isArray(filters) && filters.length > 0) {
|
||||
// "every" field's value should match "some" of corresponding filter's values
|
||||
result = result.filter(row => every(filters, filter => {
|
||||
const rowValue = row[(filter as any).name];
|
||||
const filterValues = isArray((filter as any).current) ? (filter as any).current : [(filter as any).current];
|
||||
return some(filterValues, filterValue => {
|
||||
if (moment.isMoment(rowValue)) {
|
||||
return rowValue.isSame(filterValue);
|
||||
}
|
||||
// We compare with either the value or the String representation of the value,
|
||||
// because Select2 casts true/false to "true"/"false".
|
||||
return filterValue === rowValue || String(rowValue) === filterValue;
|
||||
});
|
||||
}));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
type OwnProps = {
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'FiltersType' refers to a value, but is being used... Remove this comment to see the full error message
|
||||
filters: FiltersType;
|
||||
onChange?: (...args: any[]) => any;
|
||||
};
|
||||
type Props = OwnProps & typeof Filters.defaultProps;
|
||||
function Filters({ filters, onChange }: Props) {
|
||||
if (filters.length === 0) {
|
||||
return null;
|
||||
}
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type '(filter: any, values: any) => void' is not a... Remove this comment to see the full error message
|
||||
onChange = createFilterChangeHandler(filters, onChange);
|
||||
return (<div className="filters-wrapper" data-test="Filters">
|
||||
<div className="container bg-white">
|
||||
<div className="row">
|
||||
{map(filters, filter => {
|
||||
// @ts-expect-error ts-migrate(2741) FIXME: Property 'value' is missing in type '{ children: a... Remove this comment to see the full error message
|
||||
const options = map(filter.values, (value, index) => (<Select.Option key={index}>{formatColumnValue(value, get(filter, "column.type"))}</Select.Option>));
|
||||
return (<div key={filter.name} className="col-sm-6 p-l-0 filter-container" data-test={`FilterName-${filter.name}`}>
|
||||
<label>{filter.friendlyName}</label>
|
||||
{options.length === 0 && <Select className="w-100" disabled value="No values"/>}
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
{options.length > 0 && (<Select labelInValue className="w-100" mode={filter.multiple ? "multiple" : "default"} value={isArray(filter.current)
|
||||
? map(filter.current, value => ({
|
||||
key: `${indexOf(filter.values, value)}`,
|
||||
label: formatColumnValue(value),
|
||||
}))
|
||||
: { key: `${indexOf(filter.values, filter.current)}`, label: formatColumnValue(filter.current) }} allowClear={filter.multiple} optionFilterProp="children" showSearch maxTagCount={3} maxTagTextLength={10} maxTagPlaceholder={num => `+${num.length} more`} onChange={values => onChange(filter, values)}>
|
||||
{!filter.multiple && options}
|
||||
{filter.multiple && [
|
||||
// @ts-expect-error ts-migrate(2741) FIXME: Property 'value' is missing in type '{ children: (... Remove this comment to see the full error message
|
||||
<Select.Option key={NONE_VALUES} data-test="ClearOption">
|
||||
<i className="fa fa-square-o m-r-5"/>
|
||||
Clear
|
||||
</Select.Option>,
|
||||
// @ts-expect-error ts-migrate(2741) FIXME: Property 'value' is missing in type '{ children: (... Remove this comment to see the full error message
|
||||
<Select.Option key={ALL_VALUES} data-test="SelectAllOption">
|
||||
<i className="fa fa-check-square-o m-r-5"/>
|
||||
Select All
|
||||
</Select.Option>,
|
||||
<Select.OptGroup key="Values" title="Values">
|
||||
{options}
|
||||
</Select.OptGroup>,
|
||||
]}
|
||||
</Select>)}
|
||||
</div>);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>);
|
||||
}
|
||||
Filters.defaultProps = {
|
||||
onChange: () => { },
|
||||
};
|
||||
export default Filters;
|
||||
@@ -1,195 +0,0 @@
|
||||
import { startsWith } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import cx from "classnames";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
import Drawer from "antd/lib/drawer";
|
||||
import Icon from "antd/lib/icon";
|
||||
import BigMessage from "@/components/BigMessage";
|
||||
import DynamicComponent from "@/components/DynamicComponent";
|
||||
|
||||
import "./HelpTrigger.less";
|
||||
|
||||
const DOMAIN = "https://redash.io";
|
||||
const HELP_PATH = "/help";
|
||||
const IFRAME_TIMEOUT = 20000;
|
||||
const IFRAME_URL_UPDATE_MESSAGE = "iframe_url";
|
||||
|
||||
export const TYPES = {
|
||||
HOME: ["", "Help"],
|
||||
VALUE_SOURCE_OPTIONS: ["/user-guide/querying/query-parameters#Value-Source-Options", "Guide: Value Source Options"],
|
||||
SHARE_DASHBOARD: ["/user-guide/dashboards/sharing-dashboards", "Guide: Sharing and Embedding Dashboards"],
|
||||
AUTHENTICATION_OPTIONS: ["/user-guide/users/authentication-options", "Guide: Authentication Options"],
|
||||
USAGE_DATA_SHARING: ["/open-source/admin-guide/usage-data", "Help: Anonymous Usage Data Sharing"],
|
||||
DS_ATHENA: ["/data-sources/amazon-athena-setup", "Guide: Help Setting up Amazon Athena"],
|
||||
DS_BIGQUERY: ["/data-sources/bigquery-setup", "Guide: Help Setting up BigQuery"],
|
||||
DS_URL: ["/data-sources/querying-urls", "Guide: Help Setting up URL"],
|
||||
DS_MONGODB: ["/data-sources/mongodb-setup", "Guide: Help Setting up MongoDB"],
|
||||
DS_GOOGLE_SPREADSHEETS: ["/data-sources/querying-a-google-spreadsheet", "Guide: Help Setting up Google Spreadsheets"],
|
||||
DS_GOOGLE_ANALYTICS: ["/data-sources/google-analytics-setup", "Guide: Help Setting up Google Analytics"],
|
||||
DS_AXIBASETSD: ["/data-sources/axibase-time-series-database", "Guide: Help Setting up Axibase Time Series"],
|
||||
DS_RESULTS: ["/user-guide/querying/query-results-data-source", "Guide: Help Setting up Query Results"],
|
||||
ALERT_SETUP: ["/user-guide/alerts/setting-up-an-alert", "Guide: Setting Up a New Alert"],
|
||||
MAIL_CONFIG: ["/open-source/setup/#Mail-Configuration", "Guide: Mail Configuration"],
|
||||
ALERT_NOTIF_TEMPLATE_GUIDE: ["/user-guide/alerts/custom-alert-notifications", "Guide: Custom Alerts Notifications"],
|
||||
FAVORITES: ["/user-guide/querying/favorites-tagging/#Favorites", "Guide: Favorites"],
|
||||
MANAGE_PERMISSIONS: [
|
||||
"/user-guide/querying/writing-queries#Managing-Query-Permissions",
|
||||
"Guide: Managing Query Permissions",
|
||||
],
|
||||
NUMBER_FORMAT_SPECS: ["/user-guide/visualizations/formatting-numbers", "Formatting Numbers"],
|
||||
};
|
||||
|
||||
export default class HelpTrigger extends React.Component {
|
||||
static propTypes = {
|
||||
type: PropTypes.oneOf(Object.keys(TYPES)).isRequired,
|
||||
className: PropTypes.string,
|
||||
showTooltip: PropTypes.bool,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
className: null,
|
||||
showTooltip: true,
|
||||
children: <i className="fa fa-question-circle" />,
|
||||
};
|
||||
|
||||
iframeRef = React.createRef();
|
||||
|
||||
iframeLoadingTimeout = null;
|
||||
|
||||
state = {
|
||||
visible: false,
|
||||
loading: false,
|
||||
error: false,
|
||||
currentUrl: null,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
window.addEventListener("message", this.onPostMessageReceived, false);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener("message", this.onPostMessageReceived);
|
||||
clearTimeout(this.iframeLoadingTimeout);
|
||||
}
|
||||
|
||||
loadIframe = url => {
|
||||
clearTimeout(this.iframeLoadingTimeout);
|
||||
this.setState({ loading: true, error: false });
|
||||
|
||||
this.iframeRef.current.src = url;
|
||||
this.iframeLoadingTimeout = setTimeout(() => {
|
||||
this.setState({ error: url, loading: false });
|
||||
}, IFRAME_TIMEOUT); // safety
|
||||
};
|
||||
|
||||
onIframeLoaded = () => {
|
||||
this.setState({ loading: false });
|
||||
clearTimeout(this.iframeLoadingTimeout);
|
||||
};
|
||||
|
||||
onPostMessageReceived = event => {
|
||||
if (!startsWith(event.origin, DOMAIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { type, message: currentUrl } = event.data || {};
|
||||
if (type !== IFRAME_URL_UPDATE_MESSAGE) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ currentUrl });
|
||||
};
|
||||
|
||||
openDrawer = () => {
|
||||
this.setState({ visible: true });
|
||||
const [pagePath] = TYPES[this.props.type];
|
||||
const url = DOMAIN + HELP_PATH + pagePath;
|
||||
|
||||
// wait for drawer animation to complete so there's no animation jank
|
||||
setTimeout(() => this.loadIframe(url), 300);
|
||||
};
|
||||
|
||||
closeDrawer = event => {
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
this.setState({ visible: false });
|
||||
this.setState({ visible: false, currentUrl: null });
|
||||
};
|
||||
|
||||
render() {
|
||||
const [, tooltip] = TYPES[this.props.type];
|
||||
const className = cx("help-trigger", this.props.className);
|
||||
const url = this.state.currentUrl;
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Tooltip title={this.props.showTooltip ? tooltip : null}>
|
||||
<a onClick={this.openDrawer} className={className}>
|
||||
{this.props.children}
|
||||
</a>
|
||||
</Tooltip>
|
||||
<Drawer
|
||||
placement="right"
|
||||
closable={false}
|
||||
onClose={this.closeDrawer}
|
||||
visible={this.state.visible}
|
||||
className="help-drawer"
|
||||
destroyOnClose
|
||||
width={400}>
|
||||
<div className="drawer-wrapper">
|
||||
<div className="drawer-menu">
|
||||
{url && (
|
||||
<Tooltip title="Open page in a new window" placement="left">
|
||||
{/* eslint-disable-next-line react/jsx-no-target-blank */}
|
||||
<a href={url} target="_blank">
|
||||
<i className="fa fa-external-link" />
|
||||
</a>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Tooltip title="Close" placement="bottom">
|
||||
<a href="#" onClick={this.closeDrawer}>
|
||||
<Icon type="close" />
|
||||
</a>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{/* iframe */}
|
||||
{!this.state.error && (
|
||||
<iframe
|
||||
ref={this.iframeRef}
|
||||
title="Redash Help"
|
||||
src="about:blank"
|
||||
className={cx({ ready: !this.state.loading })}
|
||||
onLoad={this.onIframeLoaded}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* loading indicator */}
|
||||
{this.state.loading && (
|
||||
<BigMessage icon="fa-spinner fa-2x fa-pulse" message="Loading..." className="help-message" />
|
||||
)}
|
||||
|
||||
{/* error message */}
|
||||
{this.state.error && (
|
||||
<BigMessage icon="fa-exclamation-circle" className="help-message">
|
||||
Something went wrong.
|
||||
<br />
|
||||
{/* eslint-disable-next-line react/jsx-no-target-blank */}
|
||||
<a href={this.state.error} target="_blank" rel="noopener">
|
||||
Click here
|
||||
</a>{" "}
|
||||
to open the page in a new window.
|
||||
</BigMessage>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* extra content */}
|
||||
<DynamicComponent name="HelpDrawerExtraContent" onLeave={this.closeDrawer} openPageUrl={this.loadIframe} />
|
||||
</Drawer>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@import '~antd/lib/drawer/style/drawer';
|
||||
@import "~antd/lib/drawer/style/drawer";
|
||||
|
||||
@help-doc-bg: #f7f7f7; // according to https://github.com/getredash/website/blob/13daff2d8b570956565f482236f6245042e8477f/src/scss/_components/_variables.scss#L15
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
top: 13px;
|
||||
right: 13px;
|
||||
border-radius: 3px;
|
||||
background: rgba(@help-doc-bg, .75); // makes it dissolve over help doc bg
|
||||
background: rgba(@help-doc-bg, 0.75); // makes it dissolve over help doc bg
|
||||
border: 2px solid @help-doc-bg;
|
||||
display: flex;
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
color: @text-color-secondary;
|
||||
transition: color @animation-duration-slow;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: @icon-color-hover;
|
||||
@@ -65,13 +66,13 @@
|
||||
|
||||
// divider
|
||||
&:not(:first-child):before {
|
||||
content: '';
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 9px;
|
||||
left: 0;
|
||||
top: 9px;
|
||||
border-left: 1px dotted rgba(0,0,0,.12);
|
||||
border-left: 1px dotted rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,4 +88,4 @@
|
||||
height: 100%;
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
213
client/app/components/HelpTrigger.tsx
Normal file
213
client/app/components/HelpTrigger.tsx
Normal file
@@ -0,0 +1,213 @@
|
||||
import { startsWith, get, some, mapValues } from "lodash";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import cx from "classnames";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
import Drawer from "antd/lib/drawer";
|
||||
import Link from "@/components/Link";
|
||||
import CloseOutlinedIcon from "@ant-design/icons/CloseOutlined";
|
||||
import BigMessage from "@/components/BigMessage";
|
||||
import DynamicComponent, { registerComponent } from "@/components/DynamicComponent";
|
||||
import "./HelpTrigger.less";
|
||||
const DOMAIN = "https://redash.io";
|
||||
const HELP_PATH = "/help";
|
||||
const IFRAME_TIMEOUT = 20000;
|
||||
const IFRAME_URL_UPDATE_MESSAGE = "iframe_url";
|
||||
export const TYPES = mapValues({
|
||||
HOME: ["", "Help"],
|
||||
VALUE_SOURCE_OPTIONS: ["/user-guide/querying/query-parameters#Value-Source-Options", "Guide: Value Source Options"],
|
||||
SHARE_DASHBOARD: ["/user-guide/dashboards/sharing-dashboards", "Guide: Sharing and Embedding Dashboards"],
|
||||
AUTHENTICATION_OPTIONS: ["/user-guide/users/authentication-options", "Guide: Authentication Options"],
|
||||
USAGE_DATA_SHARING: ["/open-source/admin-guide/usage-data", "Help: Anonymous Usage Data Sharing"],
|
||||
DS_ATHENA: ["/data-sources/amazon-athena-setup", "Guide: Help Setting up Amazon Athena"],
|
||||
DS_BIGQUERY: ["/data-sources/bigquery-setup", "Guide: Help Setting up BigQuery"],
|
||||
DS_URL: ["/data-sources/querying-urls", "Guide: Help Setting up URL"],
|
||||
DS_MONGODB: ["/data-sources/mongodb-setup", "Guide: Help Setting up MongoDB"],
|
||||
DS_GOOGLE_SPREADSHEETS: [
|
||||
"/data-sources/querying-a-google-spreadsheet",
|
||||
"Guide: Help Setting up Google Spreadsheets",
|
||||
],
|
||||
DS_GOOGLE_ANALYTICS: ["/data-sources/google-analytics-setup", "Guide: Help Setting up Google Analytics"],
|
||||
DS_AXIBASETSD: ["/data-sources/axibase-time-series-database", "Guide: Help Setting up Axibase Time Series"],
|
||||
DS_RESULTS: ["/user-guide/querying/query-results-data-source", "Guide: Help Setting up Query Results"],
|
||||
ALERT_SETUP: ["/user-guide/alerts/setting-up-an-alert", "Guide: Setting Up a New Alert"],
|
||||
MAIL_CONFIG: ["/open-source/setup/#Mail-Configuration", "Guide: Mail Configuration"],
|
||||
ALERT_NOTIF_TEMPLATE_GUIDE: ["/user-guide/alerts/custom-alert-notifications", "Guide: Custom Alerts Notifications"],
|
||||
FAVORITES: ["/user-guide/querying/favorites-tagging/#Favorites", "Guide: Favorites"],
|
||||
MANAGE_PERMISSIONS: [
|
||||
"/user-guide/querying/writing-queries#Managing-Query-Permissions",
|
||||
"Guide: Managing Query Permissions",
|
||||
],
|
||||
NUMBER_FORMAT_SPECS: ["/user-guide/visualizations/formatting-numbers", "Formatting Numbers"],
|
||||
GETTING_STARTED: ["/user-guide/getting-started", "Guide: Getting Started"],
|
||||
DASHBOARDS: ["/user-guide/dashboards", "Guide: Dashboards"],
|
||||
QUERIES: ["/help/user-guide/querying", "Guide: Queries"],
|
||||
ALERTS: ["/user-guide/alerts", "Guide: Alerts"],
|
||||
}, ([url, title]) => [DOMAIN + HELP_PATH + url, title]);
|
||||
type OwnProps = {
|
||||
type?: string;
|
||||
href?: string;
|
||||
title?: React.ReactNode;
|
||||
className?: string;
|
||||
showTooltip?: boolean;
|
||||
renderAsLink?: boolean;
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
const HelpTriggerPropTypes = {
|
||||
type: PropTypes.string,
|
||||
href: PropTypes.string,
|
||||
title: PropTypes.node,
|
||||
className: PropTypes.string,
|
||||
showTooltip: PropTypes.bool,
|
||||
renderAsLink: PropTypes.bool,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
const HelpTriggerDefaultProps = {
|
||||
type: null,
|
||||
href: null,
|
||||
title: null,
|
||||
className: null,
|
||||
showTooltip: true,
|
||||
renderAsLink: false,
|
||||
children: <i className="fa fa-question-circle"/>,
|
||||
};
|
||||
export function helpTriggerWithTypes(types: any, allowedDomains = [], drawerClassName = null) {
|
||||
return class HelpTrigger extends React.Component {
|
||||
static propTypes = {
|
||||
...HelpTriggerPropTypes,
|
||||
type: PropTypes.oneOf(Object.keys(types)),
|
||||
};
|
||||
static defaultProps = HelpTriggerDefaultProps;
|
||||
iframeRef = React.createRef();
|
||||
iframeLoadingTimeout = null;
|
||||
state = {
|
||||
visible: false,
|
||||
loading: false,
|
||||
error: false,
|
||||
currentUrl: null,
|
||||
};
|
||||
componentDidMount() {
|
||||
window.addEventListener("message", this.onPostMessageReceived, false);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener("message", this.onPostMessageReceived);
|
||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||
clearTimeout(this.iframeLoadingTimeout);
|
||||
}
|
||||
loadIframe = (url: any) => {
|
||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||
clearTimeout(this.iframeLoadingTimeout);
|
||||
this.setState({ loading: true, error: false });
|
||||
// @ts-expect-error ts-migrate(2571) FIXME: Object is of type 'unknown'.
|
||||
this.iframeRef.current.src = url;
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'number' is not assignable to type 'null'.
|
||||
this.iframeLoadingTimeout = setTimeout(() => {
|
||||
this.setState({ error: url, loading: false });
|
||||
}, IFRAME_TIMEOUT); // safety
|
||||
};
|
||||
onIframeLoaded = () => {
|
||||
this.setState({ loading: false });
|
||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||
clearTimeout(this.iframeLoadingTimeout);
|
||||
};
|
||||
onPostMessageReceived = (event: any) => {
|
||||
if (!some(allowedDomains, domain => startsWith(event.origin, domain))) {
|
||||
return;
|
||||
}
|
||||
const { type, message: currentUrl } = event.data || {};
|
||||
if (type !== IFRAME_URL_UPDATE_MESSAGE) {
|
||||
return;
|
||||
}
|
||||
this.setState({ currentUrl });
|
||||
};
|
||||
getUrl = () => {
|
||||
const helpTriggerType = get(types, (this.props as any).type);
|
||||
return helpTriggerType ? helpTriggerType[0] : (this.props as any).href;
|
||||
};
|
||||
openDrawer = (e: any) => {
|
||||
// keep "open in new tab" behavior
|
||||
if (!e.shiftKey && !e.ctrlKey && !e.metaKey) {
|
||||
e.preventDefault();
|
||||
this.setState({ visible: true });
|
||||
// wait for drawer animation to complete so there's no animation jank
|
||||
setTimeout(() => this.loadIframe(this.getUrl()), 300);
|
||||
}
|
||||
};
|
||||
closeDrawer = (event: any) => {
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
this.setState({ visible: false });
|
||||
this.setState({ visible: false, currentUrl: null });
|
||||
};
|
||||
render() {
|
||||
const targetUrl = this.getUrl();
|
||||
if (!targetUrl) {
|
||||
return null;
|
||||
}
|
||||
const tooltip = get(types, `${(this.props as any).type}[1]`, (this.props as any).title);
|
||||
const className = cx("help-trigger", (this.props as any).className);
|
||||
const url = this.state.currentUrl;
|
||||
const isAllowedDomain = some(allowedDomains, domain => startsWith(url || targetUrl, domain));
|
||||
const shouldRenderAsLink = (this.props as any).renderAsLink || !isAllowedDomain;
|
||||
return (<React.Fragment>
|
||||
<Tooltip title={(this.props as any).showTooltip ? (<>
|
||||
{tooltip}
|
||||
{shouldRenderAsLink && <i className="fa fa-external-link" style={{ marginLeft: 5 }}/>}
|
||||
</>) : null}>
|
||||
<Link href={url || this.getUrl()} className={className} rel="noopener noreferrer" target="_blank" onClick={shouldRenderAsLink ? () => { } : this.openDrawer}>
|
||||
{this.props.children}
|
||||
</Link>
|
||||
</Tooltip>
|
||||
<Drawer placement="right" closable={false} onClose={this.closeDrawer} visible={this.state.visible} className={cx("help-drawer", drawerClassName)} destroyOnClose width={400}>
|
||||
<div className="drawer-wrapper">
|
||||
<div className="drawer-menu">
|
||||
{url && (<Tooltip title="Open page in a new window" placement="left">
|
||||
|
||||
<Link href={url} target="_blank">
|
||||
<i className="fa fa-external-link"/>
|
||||
</Link>
|
||||
</Tooltip>)}
|
||||
<Tooltip title="Close" placement="bottom">
|
||||
<a onClick={this.closeDrawer}>
|
||||
<CloseOutlinedIcon />
|
||||
</a>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
|
||||
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'RefObject<unknown>' is not assignable to typ... Remove this comment to see the full error message */}
|
||||
{!this.state.error && (<iframe ref={this.iframeRef} title="Usage Help" src="about:blank" className={cx({ ready: !this.state.loading })} onLoad={this.onIframeLoaded}/>)}
|
||||
|
||||
|
||||
{this.state.loading && (<BigMessage icon="fa-spinner fa-2x fa-pulse" message="Loading..." className="help-message"/>)}
|
||||
|
||||
|
||||
{/* @ts-expect-error ts-migrate(2746) FIXME: This JSX tag's 'children' prop expects a single ch... Remove this comment to see the full error message */}
|
||||
{this.state.error && (<BigMessage icon="fa-exclamation-circle" className="help-message">
|
||||
Something went wrong.
|
||||
<br />
|
||||
|
||||
<Link href={this.state.error} target="_blank" rel="noopener">
|
||||
Click here
|
||||
</Link>{" "}
|
||||
to open the page in a new window.
|
||||
</BigMessage>)}
|
||||
</div>
|
||||
|
||||
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
<DynamicComponent name="HelpDrawerExtraContent" onLeave={this.closeDrawer} openPageUrl={this.loadIframe}/>
|
||||
</Drawer>
|
||||
</React.Fragment>);
|
||||
}
|
||||
};
|
||||
}
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'never'.
|
||||
registerComponent("HelpTrigger", helpTriggerWithTypes(TYPES, [DOMAIN]));
|
||||
type Props = OwnProps & typeof HelpTriggerDefaultProps;
|
||||
export default function HelpTrigger(props: Props) {
|
||||
return <DynamicComponent {...props} name="HelpTrigger"/>;
|
||||
}
|
||||
HelpTrigger.defaultProps = HelpTriggerDefaultProps;
|
||||
@@ -1,20 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { sanitize } from "dompurify";
|
||||
|
||||
export default function HtmlContent({ children, ...props }) {
|
||||
return (
|
||||
<div
|
||||
{...props}
|
||||
dangerouslySetInnerHTML={{ __html: sanitize(children) }} // eslint-disable-line react/no-danger
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
HtmlContent.propTypes = {
|
||||
children: PropTypes.string,
|
||||
};
|
||||
|
||||
HtmlContent.defaultProps = {
|
||||
children: "",
|
||||
};
|
||||
@@ -1,10 +1,15 @@
|
||||
import React from "react";
|
||||
import Input from "antd/lib/input";
|
||||
import Icon from "antd/lib/icon";
|
||||
import CopyOutlinedIcon from "@ant-design/icons/CopyOutlined";
|
||||
import Tooltip from "antd/lib/tooltip";
|
||||
|
||||
export default class InputWithCopy extends React.Component {
|
||||
constructor(props) {
|
||||
type State = any;
|
||||
|
||||
export default class InputWithCopy extends React.Component<{}, State> {
|
||||
copyFeatureSupported: any;
|
||||
ref: any;
|
||||
resetCopyState: any;
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
this.state = { copied: null };
|
||||
this.ref = React.createRef();
|
||||
@@ -42,7 +47,7 @@ export default class InputWithCopy extends React.Component {
|
||||
render() {
|
||||
const copyButton = (
|
||||
<Tooltip title={this.state.copied || "Copy"}>
|
||||
<Icon type="copy" style={{ cursor: "pointer" }} onClick={this.copy} />
|
||||
<CopyOutlinedIcon style={{ cursor: "pointer" }} onClick={this.copy} />
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
26
client/app/components/Link.tsx
Normal file
26
client/app/components/Link.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from "react";
|
||||
import Button from "antd/lib/button";
|
||||
|
||||
function DefaultLinkComponent(props: any) {
|
||||
return <a {...props} />; // eslint-disable-line jsx-a11y/anchor-has-content
|
||||
}
|
||||
|
||||
function Link(props: any) {
|
||||
return <Link.Component {...props} />;
|
||||
}
|
||||
|
||||
Link.Component = DefaultLinkComponent;
|
||||
|
||||
function DefaultButtonLinkComponent(props: any) {
|
||||
return <Button role="button" {...props} />;
|
||||
}
|
||||
|
||||
function ButtonLink(props: any) {
|
||||
return <ButtonLink.Component {...props} />;
|
||||
}
|
||||
|
||||
ButtonLink.Component = DefaultButtonLinkComponent;
|
||||
|
||||
Link.Button = ButtonLink;
|
||||
|
||||
export default Link;
|
||||
@@ -1,18 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import BigMessage from "@/components/BigMessage";
|
||||
import { TagsControl } from "@/components/tags-control/TagsControl";
|
||||
|
||||
export default function NoTaggedObjectsFound({ objectType, tags }) {
|
||||
return (
|
||||
<BigMessage icon="fa-tags">
|
||||
No {objectType} found tagged with
|
||||
<TagsControl className="inline-tags-control" tags={Array.from(tags)} />.
|
||||
</BigMessage>
|
||||
);
|
||||
}
|
||||
|
||||
NoTaggedObjectsFound.propTypes = {
|
||||
objectType: PropTypes.string.isRequired,
|
||||
tags: PropTypes.oneOfType([PropTypes.array, PropTypes.objectOf(Set)]).isRequired,
|
||||
};
|
||||
22
client/app/components/NoTaggedObjectsFound.tsx
Normal file
22
client/app/components/NoTaggedObjectsFound.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from "react";
|
||||
import BigMessage from "@/components/BigMessage";
|
||||
import { TagsControl } from "@/components/tags-control/TagsControl";
|
||||
|
||||
type Props = {
|
||||
objectType: string;
|
||||
tags: any[] | {
|
||||
// @ts-expect-error ts-migrate(2314) FIXME: Generic type 'Set<T>' requires 1 type argument(s).
|
||||
[key: string]: Set;
|
||||
};
|
||||
};
|
||||
|
||||
export default function NoTaggedObjectsFound({ objectType, tags }: Props) {
|
||||
return (
|
||||
// @ts-expect-error ts-migrate(2746) FIXME: This JSX tag's 'children' prop expects a single ch... Remove this comment to see the full error message
|
||||
<BigMessage icon="fa-tags">
|
||||
No {objectType} found tagged with
|
||||
{/* @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. */}
|
||||
<TagsControl className="inline-tags-control" tags={Array.from(tags)} tagSeparator={"+"} />.
|
||||
</BigMessage>
|
||||
);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
export default function PageHeader({ title }) {
|
||||
return (
|
||||
<div className="page-header-wrapper row p-l-15 p-r-15 m-b-10 m-l-0 m-r-0">
|
||||
<div className="col-sm-9 p-l-0 p-r-0">
|
||||
<h3>{title}</h3>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
PageHeader.propTypes = {
|
||||
title: PropTypes.string.isRequired,
|
||||
};
|
||||
20
client/app/components/PageHeader/index.less
Executable file
20
client/app/components/PageHeader/index.less
Executable file
@@ -0,0 +1,20 @@
|
||||
.page-header-wrapper {
|
||||
margin: 15px 0 10px 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
justify-content: stretch;
|
||||
|
||||
h3 {
|
||||
margin: 0;
|
||||
line-height: 1.3;
|
||||
font-weight: 500;
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.page-header-actions {
|
||||
flex: 0 0 auto;
|
||||
padding: 0 0 0 15px;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user