Compare commits

..

51 Commits

Author SHA1 Message Date
github-actions[bot]
9743820efe Snapshot: 25.12.0-dev 2025-12-01 00:46:06 +00:00
Eric Radman
9d49e0457f PostgreSQL: allow connection parameters to be specified (#7579)
As documented in
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS

Multiple parameters are separated by a space.
2025-11-26 09:32:11 -05:00
Eric Radman
b5781a8ebe Add lineShape option for Line and Area charts (#7582)
Linear
Spline
Horizontal-Vertical
Vertical-Horizontal
2025-11-25 11:43:15 -05:00
Tsuneo Yoshioka
b6f4159be9 Add "Last 10 years" option for dynamic date range (#7422) 2025-11-21 10:23:58 +09:00
Sarvesh Vazarkar
d5fbf547cf pg: fix has_privileges function to quote schema and table names (#7574) 2025-11-20 10:14:03 -05:00
github-actions[bot]
772b160a79 Snapshot: 25.11.0-dev 2025-11-01 00:39:20 +00:00
Tsuneo Yoshioka
bac2160e2a Advanced query search syntax for multi byte search (#7546)
* Advanced query search syntax for multi byte search

* Advanced search for my queries

* Add advanced query seearch tooltip

* Revert "Add advanced query seearch tooltip"

This reverts commit 43148ba6ac.
2025-10-15 16:12:00 +00:00
Tsuneo Yoshioka
c5aa5da6a2 Update queries.latest_query_data on save (#7560)
* Update queries.latest_query_data on save

* Add wait on test as loading query and query results may re-render DOM and that makes test fraky

* Fix styling report by prettier
2025-10-14 22:59:36 +09:00
Eric Radman
9503cc9fb8 Correct custom chart help text: use newPlot() (#7557) 2025-10-08 07:44:29 -04:00
Tsuneo Yoshioka
b353057f9a Update ace-builds/react-ace to the latest versions (#7532) 2025-10-06 11:14:37 -04:00
Eric Radman
8747d02bbe Use standard PostgreSQL image and drop clean-all target (#7555) 2025-10-06 09:48:49 -04:00
Kamil Frydel
5b463b0d83 Make details visualization configurable (#7535)
- Added possibility to select visible columns and reordering
- Added formatting options as in Table visualization
- Set default alignment to left
2025-10-06 08:10:33 -04:00
Tsuneo Yoshioka
ea589ad477 Query Serach: avoid concurrent search API request (#7551) 2025-10-02 14:52:57 +00:00
Tsuneo Yoshioka
617124850b SchemaBrowser: on column comment tooltip, show newlines correctly (#7552) 2025-10-02 23:22:01 +09:00
Zafer Balkan
1cc200843c Add duckdb support (#7548) 2025-10-01 23:27:13 +09:00
github-actions[bot]
e0410e2ffe Snapshot: 25.10.0-dev 2025-10-01 00:39:34 +00:00
Tsuneo Yoshioka
7e39b3668d MySQL: add column type, comment, and table comment (#7544) 2025-09-30 19:20:34 +00:00
Tsuneo Yoshioka
92f15a3ccb BigQuery: Add table description on Schema Browser (#7543) 2025-10-01 03:52:36 +09:00
Tsuneo Yoshioka
9a1d33381c BigQuery: support multiple locations (#7540) 2025-09-25 22:01:17 +09:00
Tsuneo Yoshioka
56c06adc24 BigQuery: Remove "Job ID" metadata on annotaton to avoid cache misses (#7541) 2025-09-24 23:44:40 +09:00
Tsuneo Yoshioka
5e8915afe5 BigQuery: show column description(comment) on Schema Browser (#7538)
* BigQuery: add column description to Schema Browser

* fix restyled prettier error

* Remove column-description
2025-09-23 23:54:01 +09:00
Tsuneo Yoshioka
b8ebf49436 Make favorite queries/dashboard order by starred at(favorited at) (#7351)
* Make favorite queries/dashboard order by starred at(favorited at)

* fix styling for restyled error
2025-09-16 16:24:03 +09:00
Tsuneo Yoshioka
59951eda3d Fix/too many history replace state (#7530)
* Fix too many history.replaceState() error on Safari

* fix restyled error by running prettier for client/app/services/location.js
2025-09-12 03:41:04 +09:00
Artem Safiiulin
777153e7a0 Update jql.py (jira datasource) to use jira api v3 updated. (#7527)
* Update jql.py (jira datasource) to use jira api v3 updated.

* fix spaces in blank lines

* Add condition for empty "fields"

---------

Co-authored-by: Artem Safiiulin <asafiiulin@cloudlinux.com>
Co-authored-by: Tsuneo Yoshioka <yoshiokatsuneo@gmail.com>
2025-09-10 23:43:05 +09:00
Tsuneo Yoshioka
47b1309f13 Add range slider to the chart (#7525) 2025-09-09 19:22:53 +00:00
Tsuneo Yoshioka
120250152f Add "Missing and NULL values" option to scatter chart (#7523) 2025-09-08 23:54:11 +00:00
Tsuneo Yoshioka
ac81f0b223 keep ordering on search (#7520) 2025-09-08 17:22:35 +00:00
Tsuneo Yoshioka
7838058953 fix: webpack missing source-map warning for @plotly/msgbox-gl (#7522) 2025-09-08 14:18:10 +00:00
Eric Radman
f95156e924 Rely on information_schema.columns for views and foreign tables (#7521)
This prevents duplicate entries in the schema list.  Materialized views are the
only table-like object not found information_schema. Also ensure that the schema
and table found in information_schema is accessible by the current user.
2025-09-08 09:41:28 -04:00
Tsuneo Yoshioka
74de676bdf Allow HTTP request line more than 4096 bytes (#7506) 2025-09-04 18:05:05 +00:00
Tsuneo Yoshioka
2762f1fc85 Fix: null is not shown for text with "Allow HTML content" (#7519) 2025-09-03 10:55:26 -04:00
github-actions[bot]
438efd0826 Snapshot: 25.09.0-dev 2025-09-01 00:43:37 +00:00
Tsuneo Yoshioka
e586ab708b Fix stacking bar chart (#7516) 2025-08-30 03:31:47 +09:00
Tsuneo Yoshioka
24ca5135aa Update plotly.js to 3.1.0 (#7514) 2025-08-28 17:06:54 +09:00
Eric Radman
fae354fcce Update Poetry to 2.1.4 (#7509)
* Relocate [tool.poetry] to [project] section
* Add dependencies section to [project]
* Format authors and maintainers as objects
2025-08-26 08:08:19 -04:00
Tsuneo Yoshioka
4ae372f022 Update from webpack4 to webpack5 (#7507) 2025-08-25 20:50:18 +00:00
Tsuneo Yoshioka
0b5907f12b Fix css height for mobile safari not to overlap URL bar (#7334) 2025-08-22 18:42:36 +00:00
Adrian Oesch
00a97d9266 Add private_key auth method to snowflake query runner (#7371)
* add private_key auth method

* fix casing

* fix private_key parsing

* use params and add optional pwd

* use private_key_b64

* add file option

* remove __contains__

* fix pem pwd

* fix lint issues

* fix black

---------

Co-authored-by: Tsuneo Yoshioka <yoshiokatsuneo@gmail.com>
2025-08-08 17:38:22 +00:00
github-actions[bot]
35afe880a1 Snapshot: 25.08.0-dev 2025-08-01 00:45:49 +00:00
Tsuneo Yoshioka
a6298f2753 MongoDB: fix for empty username/password (#7487) 2025-07-31 23:39:39 +09:00
Zach Liu
e69283f488 clickhouse: display data types (#7490) 2025-07-31 13:08:40 +00:00
Eric Radman
09ed3c4b81 Clickhouse: do not display INFORMATION_SCHEMA tables (#7489)
As with other query runners, do not show system tables in the schema list.
2025-07-31 08:07:40 -04:00
Eric Radman
f5e2a4c0fc Sort Dashboard and Query tags by name (#7484) 2025-07-23 11:34:26 -04:00
Lee2532
4e200b4a08 bigquery load schema diff locations ignore (#7289)
* diff locations ignore

* add logging message

* Processing Location is not specified
2025-07-22 15:45:37 +00:00
Костятнин Дементьєв
5ae1f70d9e Add support for Google OAuth Scheme Override (#7178)
* Added support for Google Oauth Scheme Override (through environment variable)

* Refactoring

* Refactoring

* Applied formatting

* Refactoring

* Refactoring

* Updated comment for `GOOGLE_OAUTH_SCHEME_OVERRIDE` variable

* Updated comment for `GOOGLE_OAUTH_SCHEME_OVERRIDE` variable

* Removed duplication of url_for function

---------

Co-authored-by: kostiantyn-dementiev-op <kostiantyn.dementiev@observepoint.com>
2025-07-21 00:05:43 +09:00
Eric Radman
3f781d262b Push by tag name for Docker repository "redash" (#7321) 2025-07-17 14:50:13 -04:00
Tsuneo Yoshioka
a34c1591e3 Upgrade prettier version to the same version that CI is using (#7367) 2025-07-18 00:04:55 +09:00
Eric Radman
9f76fda18c Use 12-column layout for dashboard grid (#7396)
* Use 12-column layout for dashboard grid

Set minSizeX, minSizeY for widgets to 2 since a value of 1 breaks all
assumptions of the UI layout.

Migration provide transition from 6 to 12 columns for all widgets.

* Restyled by prettier
2025-07-16 01:24:21 +00:00
Tsuneo Yoshioka
d8ae679937 Make NULL values visible (#7439)
* Make NULL value visible
* Make the representation of NULL value configurable
* use display-as-null css class for null-value styling
2025-07-16 00:48:36 +00:00
Elliot Maincourt
f3b0b60abd feat(flask): make refresh cookie name configurable (#7473) 2025-07-09 12:09:24 -04:00
Kamil Frydel
df8be91a07 Add migration to set default alert selector (#7475)
In commits fc1e1f7 and e44fcdb a new Selector option was added to
alerts, which may be "first", "min" or "max".  This migration sets the
default to "first" for existing alerts.
2025-07-09 13:20:12 +00:00
135 changed files with 4131 additions and 2253 deletions

View File

@@ -18,7 +18,7 @@ services:
image: redis:7-alpine
restart: unless-stopped
postgres:
image: pgautoupgrade/pgautoupgrade:latest
image: postgres:18-alpine
command: "postgres -c fsync=off -c full_page_writes=off -c synchronous_commit=OFF"
restart: unless-stopped
environment:

View File

@@ -66,7 +66,7 @@ services:
image: redis:7-alpine
restart: unless-stopped
postgres:
image: pgautoupgrade/pgautoupgrade:latest
image: postgres:18-alpine
command: "postgres -c fsync=off -c full_page_writes=off -c synchronous_commit=OFF"
restart: unless-stopped
environment:

View File

@@ -121,7 +121,7 @@ jobs:
context: .
build-args: |
test_all_deps=true
outputs: type=image,push-by-digest=true,push=true
outputs: type=image,push-by-digest=false,push=true
cache-from: type=gha,scope=${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.arch }}
env:

View File

@@ -95,7 +95,7 @@ EOF
WORKDIR /app
ENV POETRY_VERSION=1.8.3
ENV POETRY_VERSION=2.1.4
ENV POETRY_HOME=/etc/poetry
ENV POETRY_VIRTUALENVS_CREATE=false
RUN curl -sSL https://install.python-poetry.org | python3 -

View File

@@ -1,4 +1,4 @@
.PHONY: compose_build up test_db create_database clean clean-all down tests lint backend-unit-tests frontend-unit-tests test build watch start redis-cli bash
.PHONY: compose_build up test_db create_database clean down tests lint backend-unit-tests frontend-unit-tests test build watch start redis-cli bash
compose_build: .env
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose build
@@ -32,11 +32,6 @@ clean:
docker image prune --force
docker volume prune --force
clean-all: clean
docker image rm --force \
redash/redash:latest redis:7-alpine maildev/maildev:latest \
pgautoupgrade/pgautoupgrade:15-alpine3.8 pgautoupgrade/pgautoupgrade:latest
down:
docker compose down

View File

@@ -46,7 +46,7 @@ server() {
MAX_REQUESTS=${MAX_REQUESTS:-1000}
MAX_REQUESTS_JITTER=${MAX_REQUESTS_JITTER:-100}
TIMEOUT=${REDASH_GUNICORN_TIMEOUT:-60}
exec /usr/local/bin/gunicorn -b 0.0.0.0:5000 --name redash -w${REDASH_WEB_WORKERS:-4} redash.wsgi:app --max-requests $MAX_REQUESTS --max-requests-jitter $MAX_REQUESTS_JITTER --timeout $TIMEOUT
exec /usr/local/bin/gunicorn -b 0.0.0.0:5000 --name redash -w${REDASH_WEB_WORKERS:-4} redash.wsgi:app --max-requests $MAX_REQUESTS --max-requests-jitter $MAX_REQUESTS_JITTER --timeout $TIMEOUT --limit-request-line ${REDASH_GUNICORN_LIMIT_REQUEST_LINE:-0}
}
create_db() {

View File

@@ -15,7 +15,7 @@ body {
display: table;
width: 100%;
padding: 10px;
height: calc(100vh - 116px);
height: calc(100% - 116px);
}
@media (min-width: 992px) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -20,7 +20,7 @@ html {
html,
body {
min-height: 100vh;
height: 100%;
}
body {
@@ -35,7 +35,7 @@ body {
}
#application-root {
min-height: 100vh;
height: 100%;
}
#application-root,

View File

@@ -10,7 +10,7 @@
vertical-align: middle;
display: inline-block;
width: 1px;
height: 100vh;
height: 100%;
}
}
@@ -135,4 +135,4 @@
}
}

View File

@@ -8,7 +8,7 @@ body.fixed-layout {
padding-bottom: 0;
width: 100vw;
height: 100vh;
height: 100%;
.application-layout-content > div {
display: flex;
@@ -90,7 +90,7 @@ body.fixed-layout {
.embed__vis {
display: flex;
flex-flow: column;
height: calc(~'100vh - 25px');
height: calc(~'100% - 25px');
> .embed-heading {
flex: 0 0 auto;

View File

@@ -7,10 +7,10 @@ body #application-root {
flex-direction: row;
justify-content: stretch;
padding-bottom: 0 !important;
height: 100vh;
height: 100%;
.application-layout-side-menu {
height: 100vh;
height: 100%;
position: relative;
@media @mobileBreakpoint {
@@ -47,6 +47,10 @@ body #application-root {
}
}
body > section {
height: 100%;
}
body.fixed-layout #application-root {
.application-layout-content {
padding-bottom: 0;

View File

@@ -51,7 +51,7 @@
right: 0;
background: linear-gradient(to bottom, transparent, transparent 2px, #f6f8f9 2px, #f6f8f9 5px),
linear-gradient(to left, #b3babf, #b3babf 1px, transparent 1px, transparent);
background-size: calc((100% + 15px) / 6) 5px;
background-size: calc((100% + 15px) / 12) 5px;
background-position: -7px 1px;
}
}

View File

@@ -9,121 +9,85 @@ const DYNAMIC_DATE_OPTIONS = [
name: "This week",
value: getDynamicDateRangeFromString("d_this_week"),
label: () =>
getDynamicDateRangeFromString("d_this_week")
.value()[0]
.format("MMM D") +
getDynamicDateRangeFromString("d_this_week").value()[0].format("MMM D") +
" - " +
getDynamicDateRangeFromString("d_this_week")
.value()[1]
.format("MMM D"),
getDynamicDateRangeFromString("d_this_week").value()[1].format("MMM D"),
},
{
name: "This month",
value: getDynamicDateRangeFromString("d_this_month"),
label: () =>
getDynamicDateRangeFromString("d_this_month")
.value()[0]
.format("MMMM"),
label: () => getDynamicDateRangeFromString("d_this_month").value()[0].format("MMMM"),
},
{
name: "This year",
value: getDynamicDateRangeFromString("d_this_year"),
label: () =>
getDynamicDateRangeFromString("d_this_year")
.value()[0]
.format("YYYY"),
label: () => getDynamicDateRangeFromString("d_this_year").value()[0].format("YYYY"),
},
{
name: "Last week",
value: getDynamicDateRangeFromString("d_last_week"),
label: () =>
getDynamicDateRangeFromString("d_last_week")
.value()[0]
.format("MMM D") +
getDynamicDateRangeFromString("d_last_week").value()[0].format("MMM D") +
" - " +
getDynamicDateRangeFromString("d_last_week")
.value()[1]
.format("MMM D"),
getDynamicDateRangeFromString("d_last_week").value()[1].format("MMM D"),
},
{
name: "Last month",
value: getDynamicDateRangeFromString("d_last_month"),
label: () =>
getDynamicDateRangeFromString("d_last_month")
.value()[0]
.format("MMMM"),
label: () => getDynamicDateRangeFromString("d_last_month").value()[0].format("MMMM"),
},
{
name: "Last year",
value: getDynamicDateRangeFromString("d_last_year"),
label: () =>
getDynamicDateRangeFromString("d_last_year")
.value()[0]
.format("YYYY"),
label: () => getDynamicDateRangeFromString("d_last_year").value()[0].format("YYYY"),
},
{
name: "Last 7 days",
value: getDynamicDateRangeFromString("d_last_7_days"),
label: () =>
getDynamicDateRangeFromString("d_last_7_days")
.value()[0]
.format("MMM D") + " - Today",
label: () => getDynamicDateRangeFromString("d_last_7_days").value()[0].format("MMM D") + " - Today",
},
{
name: "Last 14 days",
value: getDynamicDateRangeFromString("d_last_14_days"),
label: () =>
getDynamicDateRangeFromString("d_last_14_days")
.value()[0]
.format("MMM D") + " - Today",
label: () => getDynamicDateRangeFromString("d_last_14_days").value()[0].format("MMM D") + " - Today",
},
{
name: "Last 30 days",
value: getDynamicDateRangeFromString("d_last_30_days"),
label: () =>
getDynamicDateRangeFromString("d_last_30_days")
.value()[0]
.format("MMM D") + " - Today",
label: () => getDynamicDateRangeFromString("d_last_30_days").value()[0].format("MMM D") + " - Today",
},
{
name: "Last 60 days",
value: getDynamicDateRangeFromString("d_last_60_days"),
label: () =>
getDynamicDateRangeFromString("d_last_60_days")
.value()[0]
.format("MMM D") + " - Today",
label: () => getDynamicDateRangeFromString("d_last_60_days").value()[0].format("MMM D") + " - Today",
},
{
name: "Last 90 days",
value: getDynamicDateRangeFromString("d_last_90_days"),
label: () =>
getDynamicDateRangeFromString("d_last_90_days")
.value()[0]
.format("MMM D") + " - Today",
label: () => getDynamicDateRangeFromString("d_last_90_days").value()[0].format("MMM D") + " - Today",
},
{
name: "Last 12 months",
value: getDynamicDateRangeFromString("d_last_12_months"),
label: null,
},
{
name: "Last 10 years",
value: getDynamicDateRangeFromString("d_last_10_years"),
label: null,
},
];
const DYNAMIC_DATETIME_OPTIONS = [
{
name: "Today",
value: getDynamicDateRangeFromString("d_today"),
label: () =>
getDynamicDateRangeFromString("d_today")
.value()[0]
.format("MMM D"),
label: () => getDynamicDateRangeFromString("d_today").value()[0].format("MMM D"),
},
{
name: "Yesterday",
value: getDynamicDateRangeFromString("d_yesterday"),
label: () =>
getDynamicDateRangeFromString("d_yesterday")
.value()[0]
.format("MMM D"),
label: () => getDynamicDateRangeFromString("d_yesterday").value()[0].format("MMM D"),
},
...DYNAMIC_DATE_OPTIONS,
];

View File

@@ -10,6 +10,10 @@ export interface PaginationOptions {
itemsPerPage?: number;
}
export interface SearchOptions {
isServerSideFTS?: boolean;
}
export interface Controller<I, P = any> {
params: P; // TODO: Find out what params is (except merging with props)
@@ -18,7 +22,7 @@ export interface Controller<I, P = any> {
// search
searchTerm?: string;
updateSearch: (searchTerm: string) => void;
updateSearch: (searchTerm: string, searchOptions?: SearchOptions) => void;
// tags
selectedTags: string[];
@@ -94,7 +98,7 @@ export interface ItemsListWrappedComponentProps<I, P = any> {
export function wrap<I, P = any>(
WrappedComponent: React.ComponentType<ItemsListWrappedComponentProps<I>>,
createItemsSource: () => ItemsSource,
createStateStorage: () => StateStorage
createStateStorage: ( { ...props }) => StateStorage
) {
class ItemsListWrapper extends React.Component<ItemsListWrapperProps, ItemsListWrapperState<I, P>> {
private _itemsSource: ItemsSource;
@@ -117,7 +121,7 @@ export function wrap<I, P = any>(
constructor(props: ItemsListWrapperProps) {
super(props);
const stateStorage = createStateStorage();
const stateStorage = createStateStorage({ ...props });
const itemsSource = createItemsSource();
this._itemsSource = itemsSource;
@@ -141,11 +145,32 @@ export function wrap<I, P = any>(
const initialState = this.getState({ ...itemsSource.getState(), isLoaded: false });
const { updatePagination, toggleSorting, setSorting, updateSearch, updateSelectedTags, update, handleError } = itemsSource;
let isRunningUpdateSearch = false;
let pendingUpdateSearchParams: any[] | null = null;
const debouncedUpdateSearch = debounce(async (...params) => {
// Avoid running multiple updateSerch concurrently.
// If an updateSearch is already running, we save the params for the latest call.
// When the current updateSearch is finished, we call debouncedUpdateSearch again with the saved params.
if (isRunningUpdateSearch) {
pendingUpdateSearchParams = params;
return;
}
isRunningUpdateSearch = true;
await updateSearch(...params);
isRunningUpdateSearch = false;
if (pendingUpdateSearchParams) {
const pendingParams = pendingUpdateSearchParams;
pendingUpdateSearchParams = null;
debouncedUpdateSearch(...pendingParams);
}
}, 200);
this.state = {
...initialState,
toggleSorting, // eslint-disable-line react/no-unused-state
setSorting, // eslint-disable-line react/no-unused-state
updateSearch: debounce(updateSearch, 200), // eslint-disable-line react/no-unused-state
updateSearch: debouncedUpdateSearch, // eslint-disable-line react/no-unused-state
updateSelectedTags, // eslint-disable-line react/no-unused-state
updatePagination, // eslint-disable-line react/no-unused-state
update, // eslint-disable-line react/no-unused-state

View File

@@ -135,19 +135,19 @@ export class ItemsSource {
this._changed({ sorting: true });
};
updateSearch = (searchTerm) => {
updateSearch = (searchTerm, options) => {
// here we update state directly, but later `fetchData` will update it properly
this._searchTerm = searchTerm;
// in search mode ignore the ordering and use the ranking order
// provided by the server-side FTS backend instead, unless it was
// requested by the user by actively ordering in search mode
if (searchTerm === "") {
if (searchTerm === "" || !options?.isServerSideFTS) {
this._sorter.setField(this._savedOrderByField); // restore ordering
} else {
this._sorter.setField(null);
}
this._paginator.setPage(1);
this._changed({ search: true, pagination: { page: true } });
return this._changed({ search: true, pagination: { page: true } });
};
updateSelectedTags = (selectedTags) => {

View File

@@ -47,20 +47,30 @@ function SchemaItem({ item, expanded, onToggle, onSelect, ...props }) {
return (
<div {...props}>
<div className="schema-list-item">
<PlainButton className="table-name" onClick={onToggle}>
<i className="fa fa-table m-r-5" aria-hidden="true" />
<strong>
<span title={item.name}>{tableDisplayName}</span>
{!isNil(item.size) && <span> ({item.size})</span>}
</strong>
</PlainButton>
<Tooltip
title={item.description}
mouseEnterDelay={0}
mouseLeaveDelay={0}
placement="rightTop"
trigger={item.description ? "hover" : ""}
overlayStyle={{ whiteSpace: "pre-line" }}
>
<PlainButton className="table-name" onClick={onToggle}>
<i className="fa fa-table m-r-5" aria-hidden="true" />
<strong>
<span title={item.name}>{tableDisplayName}</span>
{!isNil(item.size) && <span> ({item.size})</span>}
</strong>
</PlainButton>
</Tooltip>
<Tooltip
title="Insert table name into query text"
mouseEnterDelay={0}
mouseLeaveDelay={0}
placement="topRight"
arrowPointAtCenter>
<PlainButton className="copy-to-editor" onClick={e => handleSelect(e, item.name)}>
arrowPointAtCenter
>
<PlainButton className="copy-to-editor" onClick={(e) => handleSelect(e, item.name)}>
<i className="fa fa-angle-double-right" aria-hidden="true" />
</PlainButton>
</Tooltip>
@@ -70,16 +80,23 @@ function SchemaItem({ item, expanded, onToggle, onSelect, ...props }) {
{item.loading ? (
<div className="table-open">Loading...</div>
) : (
map(item.columns, column => {
map(item.columns, (column) => {
const columnName = get(column, "name");
const columnType = get(column, "type");
const columnDescription = get(column, "description");
return (
<Tooltip
title="Insert column name into query text"
title={"Insert column name into query text" + (columnDescription ? "\n" + columnDescription : "")}
mouseEnterDelay={0}
mouseLeaveDelay={0}
placement="rightTop">
<PlainButton key={columnName} className="table-open-item" onClick={e => handleSelect(e, columnName)}>
placement="rightTop"
overlayStyle={{ whiteSpace: "pre-line" }}
>
<PlainButton
key={columnName}
className="table-open-item"
onClick={(e) => handleSelect(e, columnName)}
>
<div>
{columnName} {columnType && <span className="column-type">{columnType}</span>}
</div>
@@ -168,7 +185,7 @@ export function SchemaList({ loading, schema, expandedFlags, onTableExpand, onIt
}
export function applyFilterOnSchema(schema, filterString) {
const filters = filter(filterString.toLowerCase().split(/\s+/), s => s.length > 0);
const filters = filter(filterString.toLowerCase().split(/\s+/), (s) => s.length > 0);
// Empty string: return original schema
if (filters.length === 0) {
@@ -181,9 +198,9 @@ export function applyFilterOnSchema(schema, filterString) {
const columnFilter = filters[0];
return filter(
schema,
item =>
(item) =>
includes(item.name.toLowerCase(), nameFilter) ||
some(item.columns, column => includes(get(column, "name").toLowerCase(), columnFilter))
some(item.columns, (column) => includes(get(column, "name").toLowerCase(), columnFilter))
);
}
@@ -191,11 +208,11 @@ export function applyFilterOnSchema(schema, filterString) {
const nameFilter = filters[0];
const columnFilter = filters[1];
return filter(
map(schema, item => {
map(schema, (item) => {
if (includes(item.name.toLowerCase(), nameFilter)) {
item = {
...item,
columns: filter(item.columns, column => includes(get(column, "name").toLowerCase(), columnFilter)),
columns: filter(item.columns, (column) => includes(get(column, "name").toLowerCase(), columnFilter)),
};
return item.columns.length > 0 ? item : null;
}
@@ -243,7 +260,7 @@ export default function SchemaBrowser({
placeholder="Search schema..."
aria-label="Search schema"
disabled={schema.length === 0}
onChange={event => handleFilterChange(event.target.value)}
onChange={(event) => handleFilterChange(event.target.value)}
/>
<Tooltip title="Refresh Schema">

View File

@@ -59,6 +59,7 @@ function wrapComponentWithSettings(WrappedComponent) {
"dateTimeFormat",
"integerFormat",
"floatFormat",
"nullValue",
"booleanValues",
"tableCellMaxJSONSize",
"allowCustomJSVisualizations",

View File

@@ -1,13 +1,13 @@
export default {
columns: 6, // grid columns count
columns: 12, // grid columns count
rowHeight: 50, // grid row height (incl. bottom padding)
margins: 15, // widget margins
mobileBreakPoint: 800,
// defaults for widgets
defaultSizeX: 3,
defaultSizeX: 6,
defaultSizeY: 3,
minSizeX: 1,
maxSizeX: 6,
minSizeY: 1,
minSizeX: 2,
maxSizeX: 12,
minSizeY: 2,
maxSizeY: 1000,
};

View File

@@ -81,12 +81,19 @@ function DashboardListExtraActions(props) {
}
function DashboardList({ controller }) {
let usedListColumns = listColumns;
if (controller.params.currentPage === "favorites") {
usedListColumns = [
...usedListColumns,
Columns.dateTime.sortable({ title: "Starred At", field: "starred_at", width: "1%" }),
];
}
const {
areExtraActionsAvailable,
listColumns: tableColumns,
Component: ExtraActionsComponent,
selectedItems,
} = useItemsListExtraActions(controller, listColumns, DashboardListExtraActions);
} = useItemsListExtraActions(controller, usedListColumns, DashboardListExtraActions);
return (
<div className="page-dashboard-list">
@@ -139,9 +146,9 @@ function DashboardList({ controller }) {
showPageSizeSelect
totalCount={controller.totalItemsCount}
pageSize={controller.itemsPerPage}
onPageSizeChange={itemsPerPage => controller.updatePagination({ itemsPerPage })}
onPageSizeChange={(itemsPerPage) => controller.updatePagination({ itemsPerPage })}
page={controller.page}
onChange={page => controller.updatePagination({ page })}
onChange={(page) => controller.updatePagination({ page })}
/>
</div>
</React.Fragment>
@@ -170,10 +177,10 @@ const DashboardListPage = itemsList(
}[currentPage];
},
getItemProcessor() {
return item => new Dashboard(item);
return (item) => new Dashboard(item);
},
}),
() => new UrlStateStorage({ orderByField: "created_at", orderByReverse: true })
({ ...props }) => new UrlStateStorage({ orderByField: props.orderByField ?? "created_at", orderByReverse: true })
);
routes.register(
@@ -181,7 +188,7 @@ routes.register(
routeWithUserSession({
path: "/dashboards",
title: "Dashboards",
render: pageProps => <DashboardListPage {...pageProps} currentPage="all" />,
render: (pageProps) => <DashboardListPage {...pageProps} currentPage="all" />,
})
);
routes.register(
@@ -189,7 +196,7 @@ routes.register(
routeWithUserSession({
path: "/dashboards/favorites",
title: "Favorite Dashboards",
render: pageProps => <DashboardListPage {...pageProps} currentPage="favorites" />,
render: (pageProps) => <DashboardListPage {...pageProps} currentPage="favorites" orderByField="starred_at" />,
})
);
routes.register(
@@ -197,6 +204,6 @@ routes.register(
routeWithUserSession({
path: "/dashboards/my",
title: "My Dashboards",
render: pageProps => <DashboardListPage {...pageProps} currentPage="my" />,
render: (pageProps) => <DashboardListPage {...pageProps} currentPage="my" />,
})
);

View File

@@ -8,7 +8,7 @@
}
> .container {
min-height: calc(100vh - 95px);
min-height: calc(100% - 95px);
}
.loading-message {

View File

@@ -15,7 +15,7 @@ export function FavoriteList({ title, resource, itemUrl, emptyState }) {
useEffect(() => {
setLoading(true);
resource
.favorites()
.favorites({ order: "-starred_at" })
.then(({ results }) => setItems(results))
.finally(() => setLoading(false));
}, [resource]);
@@ -28,7 +28,7 @@ export function FavoriteList({ title, resource, itemUrl, emptyState }) {
</div>
{!isEmpty(items) && (
<div role="list" className="list-group">
{items.map(item => (
{items.map((item) => (
<Link key={itemUrl(item)} role="listitem" className="list-group-item" href={itemUrl(item)}>
<span className="btn-favorite m-r-5">
<i className="fa fa-star" aria-hidden="true" />
@@ -61,7 +61,7 @@ export function DashboardAndQueryFavoritesList() {
<FavoriteList
title="Favorite Dashboards"
resource={Dashboard}
itemUrl={dashboard => dashboard.url}
itemUrl={(dashboard) => dashboard.url}
emptyState={
<p>
<span className="btn-favorite m-r-5">
@@ -76,7 +76,7 @@ export function DashboardAndQueryFavoritesList() {
<FavoriteList
title="Favorite Queries"
resource={Query}
itemUrl={query => `queries/${query.id}`}
itemUrl={(query) => `queries/${query.id}`}
emptyState={
<p>
<span className="btn-favorite m-r-5">

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useRef } from "react";
import React, { useCallback, useEffect, useRef } from "react";
import cx from "classnames";
import routeWithUserSession from "@/components/ApplicationArea/routeWithUserSession";
@@ -20,7 +20,7 @@ import ItemsTable, { Columns } from "@/components/items-list/components/ItemsTab
import Layout from "@/components/layouts/ContentWithSidebar";
import { Query } from "@/services/query";
import { currentUser } from "@/services/auth";
import { clientConfig, currentUser } from "@/services/auth";
import location from "@/services/location";
import routes from "@/services/routes";
@@ -95,25 +95,39 @@ function QueriesList({ controller }) {
const controllerRef = useRef();
controllerRef.current = controller;
const updateSearch = useCallback(
(searchTemm) => {
controller.updateSearch(searchTemm, { isServerSideFTS: !clientConfig.multiByteSearchEnabled });
},
[controller]
);
useEffect(() => {
const unlistenLocationChanges = location.listen((unused, action) => {
const searchTerm = location.search.q || "";
if (action === "PUSH" && searchTerm !== controllerRef.current.searchTerm) {
controllerRef.current.updateSearch(searchTerm);
updateSearch(searchTerm);
}
});
return () => {
unlistenLocationChanges();
};
}, []);
}, [updateSearch]);
let usedListColumns = listColumns;
if (controller.params.currentPage === "favorites") {
usedListColumns = [
...usedListColumns,
Columns.dateTime.sortable({ title: "Starred At", field: "starred_at", width: "1%" }),
];
}
const {
areExtraActionsAvailable,
listColumns: tableColumns,
Component: ExtraActionsComponent,
selectedItems,
} = useItemsListExtraActions(controller, listColumns, QueriesListExtraActions);
} = useItemsListExtraActions(controller, usedListColumns, QueriesListExtraActions);
return (
<div className="page-queries-list">
@@ -135,7 +149,7 @@ function QueriesList({ controller }) {
placeholder="Search Queries..."
label="Search queries"
value={controller.searchTerm}
onChange={controller.updateSearch}
onChange={updateSearch}
/>
<Sidebar.Menu items={sidebarMenu} selected={controller.params.currentPage} />
<Sidebar.Tags url="api/queries/tags" onChange={controller.updateSelectedTags} showUnselectAll />
@@ -200,7 +214,7 @@ const QueriesListPage = itemsList(
return (item) => new Query(item);
},
}),
() => new UrlStateStorage({ orderByField: "created_at", orderByReverse: true })
({ ...props }) => new UrlStateStorage({ orderByField: props.orderByField ?? "created_at", orderByReverse: true })
);
routes.register(
@@ -216,7 +230,7 @@ routes.register(
routeWithUserSession({
path: "/queries/favorites",
title: "Favorite Queries",
render: (pageProps) => <QueriesListPage {...pageProps} currentPage="favorites" />,
render: (pageProps) => <QueriesListPage {...pageProps} currentPage="favorites" orderByField="starred_at" />,
})
);
routes.register(

View File

@@ -9,7 +9,7 @@ function normalizeLocation(rawLocation) {
const result = {};
result.path = pathname;
result.search = mapValues(qs.parse(search), value => (isNil(value) ? true : value));
result.search = mapValues(qs.parse(search), (value) => (isNil(value) ? true : value));
result.hash = trimStart(hash, "#");
result.url = `${pathname}${search}${hash}`;
@@ -27,7 +27,7 @@ const location = {
confirmChange(handler) {
if (isFunction(handler)) {
return history.block(nextLocation => {
return history.block((nextLocation) => {
return handler(normalizeLocation(nextLocation), location);
});
} else {
@@ -60,12 +60,18 @@ const location = {
// serialize search and keep existing search parameters (!)
if (isObject(newLocation.search)) {
newLocation.search = omitBy(extend({}, location.search, newLocation.search), isNil);
newLocation.search = mapValues(newLocation.search, value => (value === true ? null : value));
newLocation.search = mapValues(newLocation.search, (value) => (value === true ? null : value));
newLocation.search = qs.stringify(newLocation.search);
}
}
if (replace) {
history.replace(newLocation);
if (
newLocation.pathname !== location.path ||
newLocation.search !== qs.stringify(location.search) ||
newLocation.hash !== location.hash
) {
history.replace(newLocation);
}
} else {
history.push(newLocation);
}

View File

@@ -17,7 +17,9 @@ const DYNAMIC_PREFIX = "d_";
* @param now {function(): moment.Moment=} moment - defaults to now
* @returns {function(withNow: boolean): [moment.Moment, moment.Moment|undefined]}
*/
const untilNow = (from, now = () => moment()) => (withNow = true) => [from(), withNow ? now() : undefined];
const untilNow =
(from, now = () => moment()) =>
(withNow = true) => [from(), withNow ? now() : undefined];
const DYNAMIC_DATE_RANGES = {
today: {
@@ -26,14 +28,7 @@ const DYNAMIC_DATE_RANGES = {
},
yesterday: {
name: "Yesterday",
value: () => [
moment()
.subtract(1, "day")
.startOf("day"),
moment()
.subtract(1, "day")
.endOf("day"),
],
value: () => [moment().subtract(1, "day").startOf("day"), moment().subtract(1, "day").endOf("day")],
},
this_week: {
name: "This week",
@@ -49,36 +44,15 @@ const DYNAMIC_DATE_RANGES = {
},
last_week: {
name: "Last week",
value: () => [
moment()
.subtract(1, "week")
.startOf("week"),
moment()
.subtract(1, "week")
.endOf("week"),
],
value: () => [moment().subtract(1, "week").startOf("week"), moment().subtract(1, "week").endOf("week")],
},
last_month: {
name: "Last month",
value: () => [
moment()
.subtract(1, "month")
.startOf("month"),
moment()
.subtract(1, "month")
.endOf("month"),
],
value: () => [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")],
},
last_year: {
name: "Last year",
value: () => [
moment()
.subtract(1, "year")
.startOf("year"),
moment()
.subtract(1, "year")
.endOf("year"),
],
value: () => [moment().subtract(1, "year").startOf("year"), moment().subtract(1, "year").endOf("year")],
},
last_hour: {
name: "Last hour",
@@ -94,63 +68,31 @@ const DYNAMIC_DATE_RANGES = {
},
last_7_days: {
name: "Last 7 days",
value: untilNow(
() =>
moment()
.subtract(7, "days")
.startOf("day"),
() => moment().endOf("day")
),
value: untilNow(() => moment().subtract(7, "days").startOf("day")),
},
last_14_days: {
name: "Last 14 days",
value: untilNow(
() =>
moment()
.subtract(14, "days")
.startOf("day"),
() => moment().endOf("day")
),
value: untilNow(() => moment().subtract(14, "days").startOf("day")),
},
last_30_days: {
name: "Last 30 days",
value: untilNow(
() =>
moment()
.subtract(30, "days")
.startOf("day"),
() => moment().endOf("day")
),
value: untilNow(() => moment().subtract(30, "days").startOf("day")),
},
last_60_days: {
name: "Last 60 days",
value: untilNow(
() =>
moment()
.subtract(60, "days")
.startOf("day"),
() => moment().endOf("day")
),
value: untilNow(() => moment().subtract(60, "days").startOf("day")),
},
last_90_days: {
name: "Last 90 days",
value: untilNow(
() =>
moment()
.subtract(90, "days")
.startOf("day"),
() => moment().endOf("day")
),
value: untilNow(() => moment().subtract(90, "days").startOf("day")),
},
last_12_months: {
name: "Last 12 months",
value: untilNow(
() =>
moment()
.subtract(12, "months")
.startOf("day"),
() => moment().endOf("day")
),
value: untilNow(() => moment().subtract(12, "months").startOf("day")),
},
last_10_years: {
name: "Last 10 years",
value: untilNow(() => moment().subtract(10, "years").startOf("day")),
},
};
@@ -164,7 +106,7 @@ export function isDynamicDateRangeString(value) {
}
export function getDynamicDateRangeStringFromName(dynamicRangeName) {
const key = findKey(DYNAMIC_DATE_RANGES, range => range.name === dynamicRangeName);
const key = findKey(DYNAMIC_DATE_RANGES, (range) => range.name === dynamicRangeName);
return key ? DYNAMIC_PREFIX + key : undefined;
}
@@ -233,7 +175,7 @@ class DateRangeParameter extends Parameter {
getExecutionValue() {
if (this.hasDynamicValue) {
const format = date => date.format(DATETIME_FORMATS[this.type]);
const format = (date) => date.format(DATETIME_FORMATS[this.type]);
const [start, end] = this.normalizedValue.value().map(format);
return { start, end };
}

View File

@@ -23,7 +23,7 @@ describe("Dashboard", () => {
cy.getByTestId("DashboardSaveButton").click();
});
cy.wait("@NewDashboard").then(xhr => {
cy.wait("@NewDashboard").then((xhr) => {
const id = Cypress._.get(xhr, "response.body.id");
assert.isDefined(id, "Dashboard api call returns id");
@@ -40,13 +40,9 @@ describe("Dashboard", () => {
cy.getByTestId("DashboardMoreButton").click();
cy.getByTestId("DashboardMoreButtonMenu")
.contains("Archive")
.click();
cy.getByTestId("DashboardMoreButtonMenu").contains("Archive").click();
cy.get(".ant-modal .ant-btn")
.contains("Archive")
.click({ force: true });
cy.get(".ant-modal .ant-btn").contains("Archive").click({ force: true });
cy.get(".label-tag-archived").should("exist");
cy.visit("/dashboards");
@@ -60,7 +56,7 @@ describe("Dashboard", () => {
cy.server();
cy.route("GET", "**/api/dashboards/*").as("LoadDashboard");
cy.createDashboard("Dashboard multiple urls").then(({ id, slug }) => {
[`/dashboards/${id}`, `/dashboards/${id}-anything-here`, `/dashboard/${slug}`].forEach(url => {
[`/dashboards/${id}`, `/dashboards/${id}-anything-here`, `/dashboard/${slug}`].forEach((url) => {
cy.visit(url);
cy.wait("@LoadDashboard");
cy.getByTestId(`DashboardId${id}Container`).should("exist");
@@ -72,7 +68,7 @@ describe("Dashboard", () => {
});
context("viewport width is at 800px", () => {
before(function() {
before(function () {
cy.login();
cy.createDashboard("Foo Bar")
.then(({ id }) => {
@@ -80,49 +76,42 @@ describe("Dashboard", () => {
this.dashboardEditUrl = `/dashboards/${id}?edit`;
return cy.addTextbox(id, "Hello World!").then(getWidgetTestId);
})
.then(elTestId => {
.then((elTestId) => {
cy.visit(this.dashboardUrl);
cy.getByTestId(elTestId).as("textboxEl");
});
});
beforeEach(function() {
beforeEach(function () {
cy.login();
cy.visit(this.dashboardUrl);
cy.viewport(800 + menuWidth, 800);
});
it("shows widgets with full width", () => {
cy.get("@textboxEl").should($el => {
cy.get("@textboxEl").should(($el) => {
expect($el.width()).to.eq(770);
});
cy.viewport(801 + menuWidth, 800);
cy.get("@textboxEl").should($el => {
expect($el.width()).to.eq(378);
cy.get("@textboxEl").should(($el) => {
expect($el.width()).to.eq(182);
});
});
it("hides edit option", () => {
cy.getByTestId("DashboardMoreButton")
.click()
.should("be.visible");
cy.getByTestId("DashboardMoreButton").click().should("be.visible");
cy.getByTestId("DashboardMoreButtonMenu")
.contains("Edit")
.as("editButton")
.should("not.be.visible");
cy.getByTestId("DashboardMoreButtonMenu").contains("Edit").as("editButton").should("not.be.visible");
cy.viewport(801 + menuWidth, 800);
cy.get("@editButton").should("be.visible");
});
it("disables edit mode", function() {
it("disables edit mode", function () {
cy.viewport(801 + menuWidth, 800);
cy.visit(this.dashboardEditUrl);
cy.contains("button", "Done Editing")
.as("saveButton")
.should("exist");
cy.contains("button", "Done Editing").as("saveButton").should("exist");
cy.viewport(800 + menuWidth, 800);
cy.contains("button", "Done Editing").should("not.exist");
@@ -130,14 +119,14 @@ describe("Dashboard", () => {
});
context("viewport width is at 767px", () => {
before(function() {
before(function () {
cy.login();
cy.createDashboard("Foo Bar").then(({ id }) => {
this.dashboardUrl = `/dashboards/${id}`;
});
});
beforeEach(function() {
beforeEach(function () {
cy.visit(this.dashboardUrl);
cy.viewport(767, 800);
});

View File

@@ -23,7 +23,7 @@ describe("Dashboard Filters", () => {
name: "Query Filters",
query: `SELECT stage1 AS "stage1::filter", stage2, value FROM (${SQL}) q`,
};
cy.createDashboard("Dashboard Filters").then(dashboard => {
cy.createDashboard("Dashboard Filters").then((dashboard) => {
createQueryAndAddWidget(dashboard.id, queryData)
.as("widget1TestId")
.then(() => createQueryAndAddWidget(dashboard.id, queryData, { position: { col: 4 } }))
@@ -32,26 +32,23 @@ describe("Dashboard Filters", () => {
});
});
it("filters rows in a Table Visualization", function() {
it("filters rows in a Table Visualization", function () {
editDashboard();
cy.getByTestId("DashboardFilters").should("not.exist");
cy.getByTestId("DashboardFiltersCheckbox").click();
cy.getByTestId("DashboardFilters").within(() => {
cy.getByTestId("FilterName-stage1::filter")
.find(".ant-select-selection-item")
.should("have.text", "a");
cy.getByTestId("FilterName-stage1::filter").find(".ant-select-selection-item").should("have.text", "a");
});
cy.getByTestId(this.widget1TestId).within(() => {
expectTableToHaveLength(4);
expectFirstColumnToHaveMembers(["a", "a", "a", "a"]);
cy.getByTestId("FilterName-stage1::filter")
.find(".ant-select")
.click();
cy.getByTestId("FilterName-stage1::filter").find(".ant-select").click();
});
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.contains(".ant-select-item-option-content:visible", "b").click();
cy.getByTestId(this.widget1TestId).within(() => {
@@ -69,14 +66,13 @@ describe("Dashboard Filters", () => {
// assert that changing a global filter affects all widgets
cy.getByTestId("DashboardFilters").within(() => {
cy.getByTestId("FilterName-stage1::filter")
.find(".ant-select")
.click();
cy.getByTestId("FilterName-stage1::filter").find(".ant-select").click();
});
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.contains(".ant-select-item-option-content:visible", "c").click();
[this.widget1TestId, this.widget2TestId].forEach(widgetTestId =>
[this.widget1TestId, this.widget2TestId].forEach((widgetTestId) =>
cy.getByTestId(widgetTestId).within(() => {
expectTableToHaveLength(4);
expectFirstColumnToHaveMembers(["c", "c", "c", "c"]);

View File

@@ -5,7 +5,7 @@ import { getWidgetTestId, editDashboard, resizeBy } from "../../support/dashboar
const menuWidth = 80;
describe("Grid compliant widgets", () => {
beforeEach(function() {
beforeEach(function () {
cy.login();
cy.viewport(1215 + menuWidth, 800);
cy.createDashboard("Foo Bar")
@@ -13,7 +13,7 @@ describe("Grid compliant widgets", () => {
this.dashboardUrl = `/dashboards/${id}`;
return cy.addTextbox(id, "Hello World!").then(getWidgetTestId);
})
.then(elTestId => {
.then((elTestId) => {
cy.visit(this.dashboardUrl);
cy.getByTestId(elTestId).as("textboxEl");
});
@@ -27,7 +27,7 @@ describe("Grid compliant widgets", () => {
it("stays put when dragged under snap threshold", () => {
cy.get("@textboxEl")
.dragBy(90)
.dragBy(30)
.invoke("offset")
.should("have.property", "left", 15 + menuWidth); // no change, 15 -> 15
});
@@ -36,14 +36,14 @@ describe("Grid compliant widgets", () => {
cy.get("@textboxEl")
.dragBy(110)
.invoke("offset")
.should("have.property", "left", 215 + menuWidth); // moved by 200, 15 -> 215
.should("have.property", "left", 115 + menuWidth); // moved by 100, 15 -> 115
});
it("moves two columns when dragged over snap threshold", () => {
cy.get("@textboxEl")
.dragBy(330)
.dragBy(200)
.invoke("offset")
.should("have.property", "left", 415 + menuWidth); // moved by 400, 15 -> 415
.should("have.property", "left", 215 + menuWidth); // moved by 200, 15 -> 215
});
});
@@ -52,7 +52,7 @@ describe("Grid compliant widgets", () => {
cy.route("POST", "**/api/widgets/*").as("WidgetSave");
editDashboard();
cy.get("@textboxEl").dragBy(330);
cy.get("@textboxEl").dragBy(100);
cy.wait("@WidgetSave");
});
});
@@ -64,24 +64,24 @@ describe("Grid compliant widgets", () => {
});
it("stays put when dragged under snap threshold", () => {
resizeBy(cy.get("@textboxEl"), 90)
resizeBy(cy.get("@textboxEl"), 30)
.then(() => cy.get("@textboxEl"))
.invoke("width")
.should("eq", 585); // no change, 585 -> 585
.should("eq", 285); // no change, 285 -> 285
});
it("moves one column when dragged over snap threshold", () => {
resizeBy(cy.get("@textboxEl"), 110)
.then(() => cy.get("@textboxEl"))
.invoke("width")
.should("eq", 785); // resized by 200, 585 -> 785
.should("eq", 385); // resized by 200, 185 -> 385
});
it("moves two columns when dragged over snap threshold", () => {
resizeBy(cy.get("@textboxEl"), 400)
.then(() => cy.get("@textboxEl"))
.invoke("width")
.should("eq", 985); // resized by 400, 585 -> 985
.should("eq", 685); // resized by 400, 285 -> 685
});
});
@@ -101,16 +101,16 @@ describe("Grid compliant widgets", () => {
resizeBy(cy.get("@textboxEl"), 0, 30)
.then(() => cy.get("@textboxEl"))
.invoke("height")
.should("eq", 185); // resized by 50, , 135 -> 185
.should("eq", 185);
});
it("shrinks to minimum", () => {
cy.get("@textboxEl")
.then($el => resizeBy(cy.get("@textboxEl"), -$el.width(), -$el.height())) // resize to 0,0
.then(($el) => resizeBy(cy.get("@textboxEl"), -$el.width(), -$el.height())) // resize to 0,0
.then(() => cy.get("@textboxEl"))
.should($el => {
.should(($el) => {
expect($el.width()).to.eq(185); // min textbox width
expect($el.height()).to.eq(35); // min textbox height
expect($el.height()).to.eq(85); // min textbox height
});
});
});

View File

@@ -3,7 +3,7 @@
import { getWidgetTestId, editDashboard } from "../../support/dashboard";
describe("Textbox", () => {
beforeEach(function() {
beforeEach(function () {
cy.login();
cy.createDashboard("Foo Bar").then(({ id }) => {
this.dashboardId = id;
@@ -12,12 +12,10 @@ describe("Textbox", () => {
});
const confirmDeletionInModal = () => {
cy.get(".ant-modal .ant-btn")
.contains("Delete")
.click({ force: true });
cy.get(".ant-modal .ant-btn").contains("Delete").click({ force: true });
};
it("adds textbox", function() {
it("adds textbox", function () {
cy.visit(this.dashboardUrl);
editDashboard();
cy.getByTestId("AddTextboxButton").click();
@@ -29,10 +27,10 @@ describe("Textbox", () => {
cy.get(".widget-text").should("exist");
});
it("removes textbox by X button", function() {
it("removes textbox by X button", function () {
cy.addTextbox(this.dashboardId, "Hello World!")
.then(getWidgetTestId)
.then(elTestId => {
.then((elTestId) => {
cy.visit(this.dashboardUrl);
editDashboard();
@@ -45,32 +43,30 @@ describe("Textbox", () => {
});
});
it("removes textbox by menu", function() {
it("removes textbox by menu", function () {
cy.addTextbox(this.dashboardId, "Hello World!")
.then(getWidgetTestId)
.then(elTestId => {
.then((elTestId) => {
cy.visit(this.dashboardUrl);
cy.getByTestId(elTestId).within(() => {
cy.getByTestId("WidgetDropdownButton").click();
});
cy.getByTestId("WidgetDropdownButtonMenu")
.contains("Remove from Dashboard")
.click();
cy.getByTestId("WidgetDropdownButtonMenu").contains("Remove from Dashboard").click();
confirmDeletionInModal();
cy.getByTestId(elTestId).should("not.exist");
});
});
it("allows opening menu after removal", function() {
it("allows opening menu after removal", function () {
let elTestId1;
cy.addTextbox(this.dashboardId, "txb 1")
.then(getWidgetTestId)
.then(elTestId => {
.then((elTestId) => {
elTestId1 = elTestId;
return cy.addTextbox(this.dashboardId, "txb 2").then(getWidgetTestId);
})
.then(elTestId2 => {
.then((elTestId2) => {
cy.visit(this.dashboardUrl);
editDashboard();
@@ -97,10 +93,10 @@ describe("Textbox", () => {
});
});
it("edits textbox", function() {
it("edits textbox", function () {
cy.addTextbox(this.dashboardId, "Hello World!")
.then(getWidgetTestId)
.then(elTestId => {
.then((elTestId) => {
cy.visit(this.dashboardUrl);
cy.getByTestId(elTestId)
.as("textboxEl")
@@ -108,17 +104,13 @@ describe("Textbox", () => {
cy.getByTestId("WidgetDropdownButton").click();
});
cy.getByTestId("WidgetDropdownButtonMenu")
.contains("Edit")
.click();
cy.getByTestId("WidgetDropdownButtonMenu").contains("Edit").click();
const newContent = "[edited]";
cy.getByTestId("TextboxDialog")
.should("exist")
.within(() => {
cy.get("textarea")
.clear()
.type(newContent);
cy.get("textarea").clear().type(newContent);
cy.contains("button", "Save").click();
});
@@ -126,7 +118,7 @@ describe("Textbox", () => {
});
});
it("renders textbox according to position configuration", function() {
it("renders textbox according to position configuration", function () {
const id = this.dashboardId;
const txb1Pos = { col: 0, row: 0, sizeX: 3, sizeY: 2 };
const txb2Pos = { col: 1, row: 1, sizeX: 3, sizeY: 4 };
@@ -135,15 +127,15 @@ describe("Textbox", () => {
cy.addTextbox(id, "x", { position: txb1Pos })
.then(() => cy.addTextbox(id, "x", { position: txb2Pos }))
.then(getWidgetTestId)
.then(elTestId => {
.then((elTestId) => {
cy.visit(this.dashboardUrl);
return cy.getByTestId(elTestId);
})
.should($el => {
.should(($el) => {
const { top, left } = $el.offset();
expect(top).to.be.oneOf([162, 162.015625]);
expect(left).to.eq(282);
expect($el.width()).to.eq(545);
expect(left).to.eq(188);
expect($el.width()).to.eq(265);
expect($el.height()).to.eq(185);
});
});

View File

@@ -5,8 +5,9 @@ describe("Embedded Queries", () => {
});
it("is unavailable when public urls feature is disabled", () => {
cy.createQuery({ query: "select name from users order by name" }).then(query => {
cy.createQuery({ query: "select name from users order by name" }).then((query) => {
cy.visit(`/queries/${query.id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
cy.getByTestId("QueryPageVisualizationTabs", { timeout: 10000 }).should("exist");
cy.clickThrough(`
@@ -15,7 +16,7 @@ describe("Embedded Queries", () => {
`);
cy.getByTestId("EmbedIframe")
.invoke("text")
.then(embedUrl => {
.then((embedUrl) => {
// disable the feature
cy.updateOrgSettings({ disable_public_urls: true });
@@ -23,9 +24,7 @@ describe("Embedded Queries", () => {
cy.visit(`/queries/${query.id}/source`);
cy.getByTestId("QueryPageVisualizationTabs", { timeout: 10000 }).should("exist");
cy.getByTestId("QueryPageHeaderMoreButton").click();
cy.get(".ant-dropdown-menu-item")
.should("exist")
.should("not.contain", "Show API Key");
cy.get(".ant-dropdown-menu-item").should("exist").should("not.contain", "Show API Key");
cy.getByTestId("QueryControlDropdownButton").click();
cy.get(".ant-dropdown-menu-item").should("exist");
cy.getByTestId("ShowEmbedDialogButton").should("not.exist");
@@ -42,8 +41,9 @@ describe("Embedded Queries", () => {
});
it("can be shared without parameters", () => {
cy.createQuery({ query: "select name from users order by name" }).then(query => {
cy.createQuery({ query: "select name from users order by name" }).then((query) => {
cy.visit(`/queries/${query.id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
cy.getByTestId("QueryPageVisualizationTabs", { timeout: 10000 }).should("exist");
cy.clickThrough(`
@@ -52,7 +52,7 @@ describe("Embedded Queries", () => {
`);
cy.getByTestId("EmbedIframe")
.invoke("text")
.then(embedUrl => {
.then((embedUrl) => {
cy.logout();
cy.visit(embedUrl);
cy.getByTestId("VisualizationEmbed", { timeout: 10000 }).should("exist");
@@ -90,7 +90,7 @@ describe("Embedded Queries", () => {
cy.getByTestId("EmbedIframe")
.invoke("text")
.then(embedUrl => {
.then((embedUrl) => {
cy.logout();
cy.visit(embedUrl);
cy.getByTestId("VisualizationEmbed", { timeout: 10000 }).should("exist");

View File

@@ -44,6 +44,7 @@ describe("Box Plot", () => {
.then(({ id }) => cy.createVisualization(id, "BOXPLOT", "Boxplot (Deprecated)", {}))
.then(({ id: visualizationId, query_id: queryId }) => {
cy.visit(`queries/${queryId}/source#${visualizationId}`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
});
@@ -61,9 +62,7 @@ describe("Box Plot", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("svg")
.should("exist");
cy.getByTestId("VisualizationPreview").find("svg").should("exist");
cy.percySnapshot("Visualizations - Box Plot", { widths: [viewportWidth] });
});

View File

@@ -31,6 +31,7 @@ describe("Chart", () => {
it("creates Bar charts", function () {
cy.visit(`queries/${this.queryId}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
const getBarChartAssertionFunction =
@@ -109,6 +110,7 @@ describe("Chart", () => {
});
it("colors Bar charts", function () {
cy.visit(`queries/${this.queryId}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
cy.getByTestId("NewVisualization").click();
cy.getByTestId("Chart.ColumnMapping.x").selectAntdOption("Chart.ColumnMapping.x.stage");
@@ -123,6 +125,7 @@ describe("Chart", () => {
});
it("colors Pie charts", function () {
cy.visit(`queries/${this.queryId}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
cy.getByTestId("NewVisualization").click();
cy.getByTestId("Chart.GlobalSeriesType").click();

View File

@@ -34,6 +34,7 @@ describe("Choropleth", () => {
cy.login();
cy.createQuery({ query: SQL }).then(({ id }) => {
cy.visit(`queries/${id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
cy.getByTestId("NewVisualization").click();
@@ -76,9 +77,7 @@ describe("Choropleth", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find(".map-visualization-container.leaflet-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".map-visualization-container.leaflet-container").should("exist");
cy.percySnapshot("Visualizations - Choropleth", { widths: [viewportWidth] });
});

View File

@@ -24,6 +24,7 @@ describe("Cohort", () => {
cy.login();
cy.createQuery({ query: SQL }).then(({ id }) => {
cy.visit(`queries/${id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
cy.getByTestId("NewVisualization").click();
@@ -51,9 +52,7 @@ describe("Cohort", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("table")
.should("exist");
cy.getByTestId("VisualizationPreview").find("table").should("exist");
cy.percySnapshot("Visualizations - Cohort (simple)", { widths: [viewportWidth] });
cy.clickThrough(`
@@ -64,9 +63,7 @@ describe("Cohort", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("table")
.should("exist");
cy.getByTestId("VisualizationPreview").find("table").should("exist");
cy.percySnapshot("Visualizations - Cohort (diagonal)", { widths: [viewportWidth] });
});
});

View File

@@ -12,6 +12,7 @@ describe("Counter", () => {
cy.login();
cy.createQuery({ query: SQL }).then(({ id }) => {
cy.visit(`queries/${id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
cy.getByTestId("NewVisualization").click();
@@ -24,9 +25,7 @@ describe("Counter", () => {
Counter.General.ValueColumn.a
`);
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -43,9 +42,7 @@ describe("Counter", () => {
"Counter.General.Label": "Custom Label",
});
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -65,9 +62,7 @@ describe("Counter", () => {
"Counter.General.TargetValueRowNumber": "2",
});
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -83,9 +78,7 @@ describe("Counter", () => {
Counter.General.TargetValueColumn.b
`);
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -106,9 +99,7 @@ describe("Counter", () => {
"Counter.General.TargetValueRowNumber": "2",
});
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -123,9 +114,7 @@ describe("Counter", () => {
Counter.General.CountRows
`);
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -151,9 +140,7 @@ describe("Counter", () => {
"Counter.Formatting.StringSuffix": "%",
});
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -180,9 +167,7 @@ describe("Counter", () => {
"Counter.Formatting.StringSuffix": "%",
});
cy.getByTestId("VisualizationPreview")
.find(".counter-visualization-container")
.should("exist");
cy.getByTestId("VisualizationPreview").find(".counter-visualization-container").should("exist");
// wait a bit before taking snapshot
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting

View File

@@ -5,34 +5,25 @@ describe("Edit visualization dialog", () => {
cy.login();
cy.createQuery().then(({ id }) => {
cy.visit(`queries/${id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
});
it("opens New Visualization dialog", () => {
cy.getByTestId("NewVisualization")
.should("exist")
.click();
cy.getByTestId("NewVisualization").should("exist").click();
cy.getByTestId("EditVisualizationDialog").should("exist");
// Default visualization should be selected
cy.getByTestId("VisualizationType")
.should("exist")
.should("contain", "Chart");
cy.getByTestId("VisualizationName")
.should("exist")
.should("have.value", "Chart");
cy.getByTestId("VisualizationType").should("exist").should("contain", "Chart");
cy.getByTestId("VisualizationName").should("exist").should("have.value", "Chart");
});
it("opens Edit Visualization dialog", () => {
cy.getByTestId("EditVisualization").click();
cy.getByTestId("EditVisualizationDialog").should("exist");
// Default `Table` visualization should be selected
cy.getByTestId("VisualizationType")
.should("exist")
.should("contain", "Table");
cy.getByTestId("VisualizationName")
.should("exist")
.should("have.value", "Table");
cy.getByTestId("VisualizationType").should("exist").should("contain", "Table");
cy.getByTestId("VisualizationName").should("exist").should("have.value", "Table");
});
it("creates visualization with custom name", () => {
@@ -44,15 +35,9 @@ describe("Edit visualization dialog", () => {
VisualizationType.TABLE
`);
cy.getByTestId("VisualizationName")
.clear()
.type(visualizationName);
cy.getByTestId("VisualizationName").clear().type(visualizationName);
cy.getByTestId("EditVisualizationDialog")
.contains("button", "Save")
.click();
cy.getByTestId("QueryPageVisualizationTabs")
.contains("span", visualizationName)
.should("exist");
cy.getByTestId("EditVisualizationDialog").contains("button", "Save").click();
cy.getByTestId("QueryPageVisualizationTabs").contains("span", visualizationName).should("exist");
});
});

View File

@@ -25,6 +25,7 @@ describe("Funnel", () => {
cy.login();
cy.createQuery({ query: SQL }).then(({ id }) => {
cy.visit(`queries/${id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
});
@@ -59,9 +60,7 @@ describe("Funnel", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("table")
.should("exist");
cy.getByTestId("VisualizationPreview").find("table").should("exist");
cy.percySnapshot("Visualizations - Funnel (basic)", { widths: [viewportWidth] });
cy.clickThrough(`
@@ -81,9 +80,7 @@ describe("Funnel", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("table")
.should("exist");
cy.getByTestId("VisualizationPreview").find("table").should("exist");
cy.percySnapshot("Visualizations - Funnel (extra options)", { widths: [viewportWidth] });
});
});

View File

@@ -24,6 +24,7 @@ describe("Map (Markers)", () => {
.then(({ id }) => cy.createVisualization(id, "MAP", "Map (Markers)", { mapTileUrl }))
.then(({ id: visualizationId, query_id: queryId }) => {
cy.visit(`queries/${queryId}/source#${visualizationId}`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
});
@@ -51,9 +52,7 @@ describe("Map (Markers)", () => {
cy.fillInputs({ "ColorPicker.CustomColor": "blue{enter}" });
cy.getByTestId("ColorPicker.CustomColor").should("not.be.visible");
cy.getByTestId("VisualizationPreview")
.find(".leaflet-control-zoom-in")
.click();
cy.getByTestId("VisualizationPreview").find(".leaflet-control-zoom-in").click();
// Wait for proper initialization of visualization
cy.wait(1000); // eslint-disable-line cypress/no-unnecessary-waiting
@@ -85,9 +84,7 @@ describe("Map (Markers)", () => {
cy.fillInputs({ "ColorPicker.CustomColor": "maroon{enter}" });
cy.getByTestId("ColorPicker.CustomColor").should("not.be.visible");
cy.getByTestId("VisualizationPreview")
.find(".leaflet-control-zoom-in")
.click();
cy.getByTestId("VisualizationPreview").find(".leaflet-control-zoom-in").click();
// Wait for proper initialization of visualization
cy.wait(1000); // eslint-disable-line cypress/no-unnecessary-waiting

View File

@@ -19,9 +19,7 @@ const SQL = `
function createPivotThroughUI(visualizationName, options = {}) {
cy.getByTestId("NewVisualization").click();
cy.getByTestId("VisualizationType").selectAntdOption("VisualizationType.PIVOT");
cy.getByTestId("VisualizationName")
.clear()
.type(visualizationName);
cy.getByTestId("VisualizationName").clear().type(visualizationName);
if (options.hideControls) {
cy.getByTestId("PivotEditor.HideControls").click();
cy.getByTestId("VisualizationPreview")
@@ -29,36 +27,30 @@ function createPivotThroughUI(visualizationName, options = {}) {
.find(".pvtAxisContainer, .pvtRenderer, .pvtVals")
.should("be.not.visible");
}
cy.getByTestId("VisualizationPreview")
.find("table")
.should("exist");
cy.getByTestId("EditVisualizationDialog")
.contains("button", "Save")
.click();
cy.getByTestId("VisualizationPreview").find("table").should("exist");
cy.getByTestId("EditVisualizationDialog").contains("button", "Save").click();
}
describe("Pivot", () => {
beforeEach(() => {
cy.login();
cy.createQuery({ name: "Pivot Visualization", query: SQL })
.its("id")
.as("queryId");
cy.createQuery({ name: "Pivot Visualization", query: SQL }).its("id").as("queryId");
});
it("creates Pivot with controls", function() {
it("creates Pivot with controls", function () {
cy.visit(`queries/${this.queryId}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
const visualizationName = "Pivot";
createPivotThroughUI(visualizationName);
cy.getByTestId("QueryPageVisualizationTabs")
.contains("span", visualizationName)
.should("exist");
cy.getByTestId("QueryPageVisualizationTabs").contains("span", visualizationName).should("exist");
});
it("creates Pivot without controls", function() {
it("creates Pivot without controls", function () {
cy.visit(`queries/${this.queryId}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
const visualizationName = "Pivot";
@@ -76,7 +68,7 @@ describe("Pivot", () => {
.should("be.not.visible");
});
it("updates the visualization when results change", function() {
it("updates the visualization when results change", function () {
const options = {
aggregatorName: "Count",
data: [], // force it to have a data object, although it shouldn't
@@ -86,8 +78,9 @@ describe("Pivot", () => {
vals: ["value"],
};
cy.createVisualization(this.queryId, "PIVOT", "Pivot", options).then(visualization => {
cy.createVisualization(this.queryId, "PIVOT", "Pivot", options).then((visualization) => {
cy.visit(`queries/${this.queryId}/source#${visualization.id}`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
// assert number of rows is 11
@@ -104,16 +97,14 @@ describe("Pivot", () => {
cy.wait(200);
cy.getByTestId("SaveButton").click();
cy.getByTestId("ExecuteButton")
.should("be.enabled")
.click();
cy.getByTestId("ExecuteButton").should("be.enabled").click();
// assert number of rows is 12
cy.getByTestId("PivotTableVisualization").contains(".pvtGrandTotal", "12");
});
});
it("takes a snapshot with different configured Pivots", function() {
it("takes a snapshot with different configured Pivots", function () {
const options = {
aggregatorName: "Sum",
controls: { enabled: true },
@@ -142,19 +133,20 @@ describe("Pivot", () => {
];
cy.createDashboard("Pivot Visualization")
.then(dashboard => {
.then((dashboard) => {
this.dashboardUrl = `/dashboards/${dashboard.id}`;
return cy.all(
pivotTables.map(pivot => () =>
cy
.createVisualization(this.queryId, "PIVOT", pivot.name, pivot.options)
.then(visualization => cy.addWidget(dashboard.id, visualization.id, { position: pivot.position }))
pivotTables.map(
(pivot) => () =>
cy
.createVisualization(this.queryId, "PIVOT", pivot.name, pivot.options)
.then((visualization) => cy.addWidget(dashboard.id, visualization.id, { position: pivot.position }))
)
);
})
.then(widgets => {
.then((widgets) => {
cy.visit(this.dashboardUrl);
widgets.forEach(widget => {
widgets.forEach((widget) => {
cy.getByTestId(getWidgetTestId(widget)).within(() =>
cy.getByTestId("PivotTableVisualization").should("exist")
);

View File

@@ -25,6 +25,7 @@ describe("Sankey and Sunburst", () => {
beforeEach(() => {
cy.createQuery({ query: SQL }).then(({ id }) => {
cy.visit(`queries/${id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
cy.getByTestId("NewVisualization").click();
cy.getByTestId("VisualizationType").selectAntdOption("VisualizationType.SUNBURST_SEQUENCE");
@@ -34,37 +35,21 @@ describe("Sankey and Sunburst", () => {
it("creates Sunburst", () => {
const visualizationName = "Sunburst";
cy.getByTestId("VisualizationName")
.clear()
.type(visualizationName);
cy.getByTestId("VisualizationPreview")
.find("svg")
.should("exist");
cy.getByTestId("VisualizationName").clear().type(visualizationName);
cy.getByTestId("VisualizationPreview").find("svg").should("exist");
cy.getByTestId("EditVisualizationDialog")
.contains("button", "Save")
.click();
cy.getByTestId("QueryPageVisualizationTabs")
.contains("span", visualizationName)
.should("exist");
cy.getByTestId("EditVisualizationDialog").contains("button", "Save").click();
cy.getByTestId("QueryPageVisualizationTabs").contains("span", visualizationName).should("exist");
});
it("creates Sankey", () => {
const visualizationName = "Sankey";
cy.getByTestId("VisualizationName")
.clear()
.type(visualizationName);
cy.getByTestId("VisualizationPreview")
.find("svg")
.should("exist");
cy.getByTestId("VisualizationName").clear().type(visualizationName);
cy.getByTestId("VisualizationPreview").find("svg").should("exist");
cy.getByTestId("EditVisualizationDialog")
.contains("button", "Save")
.click();
cy.getByTestId("QueryPageVisualizationTabs")
.contains("span", visualizationName)
.should("exist");
cy.getByTestId("EditVisualizationDialog").contains("button", "Save").click();
cy.getByTestId("QueryPageVisualizationTabs").contains("span", visualizationName).should("exist");
});
});
@@ -92,21 +77,22 @@ describe("Sankey and Sunburst", () => {
},
];
it("takes a snapshot with Sunburst (1 - 5 stages)", function() {
cy.createDashboard("Sunburst Visualization").then(dashboard => {
it("takes a snapshot with Sunburst (1 - 5 stages)", function () {
cy.createDashboard("Sunburst Visualization").then((dashboard) => {
this.dashboardUrl = `/dashboards/${dashboard.id}`;
return cy
.all(
STAGES_WIDGETS.map(sunburst => () =>
cy
.createQuery({ name: `Sunburst with ${sunburst.name}`, query: sunburst.query })
.then(queryData => cy.createVisualization(queryData.id, "SUNBURST_SEQUENCE", "Sunburst", {}))
.then(visualization => cy.addWidget(dashboard.id, visualization.id, { position: sunburst.position }))
STAGES_WIDGETS.map(
(sunburst) => () =>
cy
.createQuery({ name: `Sunburst with ${sunburst.name}`, query: sunburst.query })
.then((queryData) => cy.createVisualization(queryData.id, "SUNBURST_SEQUENCE", "Sunburst", {}))
.then((visualization) => cy.addWidget(dashboard.id, visualization.id, { position: sunburst.position }))
)
)
.then(widgets => {
.then((widgets) => {
cy.visit(this.dashboardUrl);
widgets.forEach(widget => {
widgets.forEach((widget) => {
cy.getByTestId(getWidgetTestId(widget)).within(() => cy.get("svg").should("exist"));
});
@@ -117,21 +103,22 @@ describe("Sankey and Sunburst", () => {
});
});
it("takes a snapshot with Sankey (1 - 5 stages)", function() {
cy.createDashboard("Sankey Visualization").then(dashboard => {
it("takes a snapshot with Sankey (1 - 5 stages)", function () {
cy.createDashboard("Sankey Visualization").then((dashboard) => {
this.dashboardUrl = `/dashboards/${dashboard.id}`;
return cy
.all(
STAGES_WIDGETS.map(sankey => () =>
cy
.createQuery({ name: `Sankey with ${sankey.name}`, query: sankey.query })
.then(queryData => cy.createVisualization(queryData.id, "SANKEY", "Sankey", {}))
.then(visualization => cy.addWidget(dashboard.id, visualization.id, { position: sankey.position }))
STAGES_WIDGETS.map(
(sankey) => () =>
cy
.createQuery({ name: `Sankey with ${sankey.name}`, query: sankey.query })
.then((queryData) => cy.createVisualization(queryData.id, "SANKEY", "Sankey", {}))
.then((visualization) => cy.addWidget(dashboard.id, visualization.id, { position: sankey.position }))
)
)
.then(widgets => {
.then((widgets) => {
cy.visit(this.dashboardUrl);
widgets.forEach(widget => {
widgets.forEach((widget) => {
cy.getByTestId(getWidgetTestId(widget)).within(() => cy.get("svg").should("exist"));
});

View File

@@ -64,6 +64,7 @@ describe("Word Cloud", () => {
cy.login();
cy.createQuery({ query: SQL }).then(({ id }) => {
cy.visit(`queries/${id}/source`);
cy.wait(1500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("ExecuteButton").click();
});
cy.document().then(injectFont);
@@ -80,9 +81,7 @@ describe("Word Cloud", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("svg text")
.should("have.length", 11);
cy.getByTestId("VisualizationPreview").find("svg text").should("have.length", 11);
cy.percySnapshot("Visualizations - Word Cloud (Automatic word frequencies)", { widths: [viewportWidth] });
});
@@ -99,9 +98,7 @@ describe("Word Cloud", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("svg text")
.should("have.length", 5);
cy.getByTestId("VisualizationPreview").find("svg text").should("have.length", 5);
cy.percySnapshot("Visualizations - Word Cloud (Frequencies from another column)", { widths: [viewportWidth] });
});
@@ -125,9 +122,7 @@ describe("Word Cloud", () => {
// Wait for proper initialization of visualization
cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting
cy.getByTestId("VisualizationPreview")
.find("svg text")
.should("have.length", 2);
cy.getByTestId("VisualizationPreview").find("svg text").should("have.length", 2);
cy.percySnapshot("Visualizations - Word Cloud (With filters)", { widths: [viewportWidth] });
});

View File

@@ -53,7 +53,7 @@ services:
image: redis:7-alpine
restart: unless-stopped
postgres:
image: pgautoupgrade/pgautoupgrade:latest
image: postgres:18-alpine
ports:
- "15432:5432"
# The following turns the DB into less durable, but gains significant performance improvements for the tests run (x3

View File

@@ -0,0 +1,26 @@
"""set default alert selector
Revision ID: 1655999df5e3
Revises: 9e8c841d1a30
Create Date: 2025-07-09 14:44:00
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = '1655999df5e3'
down_revision = '9e8c841d1a30'
branch_labels = None
depends_on = None
def upgrade():
op.execute("""
UPDATE alerts
SET options = jsonb_set(options, '{selector}', '"first"')
WHERE options->>'selector' IS NULL;
""")
def downgrade():
pass

View File

@@ -0,0 +1,34 @@
"""12-column dashboard layout
Revision ID: db0aca1ebd32
Revises: 1655999df5e3
Create Date: 2025-03-31 13:45:43.160893
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'db0aca1ebd32'
down_revision = '1655999df5e3'
branch_labels = None
depends_on = None
def upgrade():
op.execute("""
UPDATE widgets
SET options = jsonb_set(options, '{position,col}', to_json((options->'position'->>'col')::int * 2)::jsonb);
UPDATE widgets
SET options = jsonb_set(options, '{position,sizeX}', to_json((options->'position'->>'sizeX')::int * 2)::jsonb);
""")
def downgrade():
op.execute("""
UPDATE widgets
SET options = jsonb_set(options, '{position,col}', to_json((options->'position'->>'col')::int / 2)::jsonb);
UPDATE widgets
SET options = jsonb_set(options, '{position,sizeX}', to_json((options->'position'->>'sizeX')::int / 2)::jsonb);
""")

View File

@@ -1,6 +1,6 @@
{
"name": "redash-client",
"version": "25.07.0-dev",
"version": "25.12.0-dev",
"description": "The frontend part of Redash.",
"main": "index.js",
"scripts": {
@@ -46,8 +46,8 @@
"dependencies": {
"@ant-design/icons": "^4.2.1",
"@redash/viz": "file:viz-lib",
"ace-builds": "^1.4.12",
"antd": "^4.4.3",
"ace-builds": "^1.43.3",
"antd": "4.4.3",
"axios": "0.27.2",
"axios-auth-refresh": "3.3.6",
"bootstrap": "^3.4.1",
@@ -68,7 +68,7 @@
"prop-types": "^15.6.1",
"query-string": "^6.9.0",
"react": "16.14.0",
"react-ace": "^9.1.1",
"react-ace": "^14.0.1",
"react-dom": "^16.14.0",
"react-grid-layout": "^0.18.2",
"react-resizable": "^1.10.1",
@@ -100,6 +100,7 @@
"@types/sql-formatter": "^2.3.0",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"assert": "^2.1.0",
"atob": "^2.1.2",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.1.0",
@@ -138,21 +139,24 @@
"mini-css-extract-plugin": "^1.6.2",
"mockdate": "^2.0.2",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"prettier": "3.3.2",
"process": "^0.11.10",
"raw-loader": "^0.5.1",
"react-refresh": "^0.14.0",
"react-test-renderer": "^16.14.0",
"request-cookies": "^1.1.0",
"source-map-loader": "^1.1.3",
"stream-browserify": "^3.0.0",
"style-loader": "^2.0.0",
"typescript": "^4.1.2",
"typescript": "4.1.2",
"url": "^0.11.4",
"url-loader": "^4.1.1",
"webpack": "^4.46.0",
"webpack-build-notifier": "^2.3.0",
"webpack": "^5.101.3",
"webpack-build-notifier": "^3.0.1",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.1",
"webpack-manifest-plugin": "^2.0.4"
"webpack-manifest-plugin": "^5.0.1"
},
"optionalDependencies": {
"fsevents": "^2.3.2"

374
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,17 @@
[project]
name = "redash"
version = "25.12.0-dev"
requires-python = ">=3.8"
description = "Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data."
authors = [
{ name = "Arik Fraimovich", email = "<arik@redash.io>" }
]
# to be added to/removed from the mailing list, please reach out to Arik via the above email or Discord
maintainers = [
{ name = "Redash maintainers and contributors", email = "<maintainers@redash.io>" }
]
readme = "README.md"
dependencies = []
[tool.black]
target-version = ['py38']
@@ -10,17 +22,6 @@ force-exclude = '''
)/
'''
[tool.poetry]
name = "redash"
version = "25.07.0-dev"
description = "Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data."
authors = ["Arik Fraimovich <arik@redash.io>"]
# to be added to/removed from the mailing list, please reach out to Arik via the above email or Discord
maintainers = [
"Redash maintainers and contributors <maintainers@redash.io>",
]
readme = "README.md"
[tool.poetry.dependencies]
python = ">=3.8,<3.11"
advocate = "1.0.0"
@@ -103,6 +104,7 @@ certifi = ">=2019.9.11"
cmem-cmempy = "21.2.3"
databend-py = "0.4.6"
databend-sqlalchemy = "0.2.4"
duckdb = "1.3.2"
google-api-python-client = "1.7.11"
gspread = "5.11.2"
impyla = "0.16.0"

View File

@@ -14,7 +14,7 @@ from redash.app import create_app # noqa
from redash.destinations import import_destinations
from redash.query_runner import import_query_runners
__version__ = "25.07.0-dev"
__version__ = "25.12.0-dev"
if os.environ.get("REMOTE_DEBUG"):

View File

@@ -4,7 +4,7 @@ import requests
from authlib.integrations.flask_client import OAuth
from flask import Blueprint, flash, redirect, request, session, url_for
from redash import models
from redash import models, settings
from redash.authentication import (
create_and_login_user,
get_next_path,
@@ -29,6 +29,41 @@ def verify_profile(org, profile):
return False
def get_user_profile(access_token, logger):
headers = {"Authorization": f"OAuth {access_token}"}
response = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers=headers)
if response.status_code == 401:
logger.warning("Failed getting user profile (response code 401).")
return None
return response.json()
def build_redirect_uri():
scheme = settings.GOOGLE_OAUTH_SCHEME_OVERRIDE or None
return url_for(".callback", _external=True, _scheme=scheme)
def build_next_path(org_slug=None):
next_path = request.args.get("next")
if not next_path:
if org_slug is None:
org_slug = session.get("org_slug")
scheme = None
if settings.GOOGLE_OAUTH_SCHEME_OVERRIDE:
scheme = settings.GOOGLE_OAUTH_SCHEME_OVERRIDE
next_path = url_for(
"redash.index",
org_slug=org_slug,
_external=True,
_scheme=scheme,
)
return next_path
def create_google_oauth_blueprint(app):
oauth = OAuth(app)
@@ -36,23 +71,12 @@ def create_google_oauth_blueprint(app):
blueprint = Blueprint("google_oauth", __name__)
CONF_URL = "https://accounts.google.com/.well-known/openid-configuration"
oauth = OAuth(app)
oauth.register(
name="google",
server_metadata_url=CONF_URL,
client_kwargs={"scope": "openid email profile"},
)
def get_user_profile(access_token):
headers = {"Authorization": "OAuth {}".format(access_token)}
response = requests.get("https://www.googleapis.com/oauth2/v1/userinfo", headers=headers)
if response.status_code == 401:
logger.warning("Failed getting user profile (response code 401).")
return None
return response.json()
@blueprint.route("/<org_slug>/oauth/google", endpoint="authorize_org")
def org_login(org_slug):
session["org_slug"] = current_org.slug
@@ -60,9 +84,9 @@ def create_google_oauth_blueprint(app):
@blueprint.route("/oauth/google", endpoint="authorize")
def login():
redirect_uri = url_for(".callback", _external=True)
redirect_uri = build_redirect_uri()
next_path = request.args.get("next", url_for("redash.index", org_slug=session.get("org_slug")))
next_path = build_next_path()
logger.debug("Callback url: %s", redirect_uri)
logger.debug("Next is: %s", next_path)
@@ -86,7 +110,7 @@ def create_google_oauth_blueprint(app):
flash("Validation error. Please retry.")
return redirect(url_for("redash.login"))
profile = get_user_profile(access_token)
profile = get_user_profile(access_token, logger)
if profile is None:
flash("Validation error. Please retry.")
return redirect(url_for("redash.login"))
@@ -110,7 +134,9 @@ def create_google_oauth_blueprint(app):
if user is None:
return logout_and_redirect_to_index()
unsafe_next_path = session.get("next_url") or url_for("redash.index", org_slug=org.slug)
unsafe_next_path = session.get("next_url")
if not unsafe_next_path:
unsafe_next_path = build_next_path(org.slug)
next_path = get_next_path(unsafe_next_path)
return redirect(next_path)

View File

@@ -255,6 +255,12 @@ def number_format_config():
}
def null_value_config():
return {
"nullValue": current_org.get_setting("null_value"),
}
def client_config():
if not current_user.is_api_user() and current_user.is_authenticated:
client_config = {
@@ -272,6 +278,7 @@ def client_config():
"showPermissionsControl": current_org.get_setting("feature_show_permissions_control"),
"hidePlotlyModeBar": current_org.get_setting("hide_plotly_mode_bar"),
"disablePublicUrls": current_org.get_setting("disable_public_urls"),
"multiByteSearchEnabled": current_org.get_setting("multi_byte_search_enabled"),
"allowCustomJSVisualizations": settings.FEATURE_ALLOW_CUSTOM_JS_VISUALIZATIONS,
"autoPublishNamedQueries": settings.FEATURE_AUTO_PUBLISH_NAMED_QUERIES,
"extendedAlertOptions": settings.FEATURE_EXTENDED_ALERT_OPTIONS,
@@ -289,6 +296,7 @@ def client_config():
client_config.update({"basePath": base_href()})
client_config.update(date_time_format_config())
client_config.update(number_format_config())
client_config.update(null_value_config())
return client_config

View File

@@ -26,6 +26,8 @@ order_map = {
"-name": "-lowercase_name",
"created_at": "created_at",
"-created_at": "-created_at",
"starred_at": "favorites-created_at",
"-starred_at": "-favorites-created_at",
}
order_results = partial(_order_results, default_order="-created_at", allowed_orders=order_map)

View File

@@ -44,6 +44,8 @@ order_map = {
"-executed_at": "-query_results-retrieved_at",
"created_by": "users-name",
"-created_by": "-users-name",
"starred_at": "favorites-created_at",
"-starred_at": "-favorites-created_at",
}
order_results = partial(_order_results, default_order="-created_at", allowed_orders=order_map)
@@ -239,6 +241,8 @@ class QueryListResource(BaseQueryListResource):
query = models.Query.create(**query_def)
models.db.session.add(query)
models.db.session.commit()
query.update_latest_result_by_query_hash()
models.db.session.commit()
self.record_event({"action": "create", "object_id": query.id, "object_type": "query"})
@@ -362,6 +366,8 @@ class QueryResource(BaseResource):
try:
self.update_model(query, query_def)
models.db.session.commit()
query.update_latest_result_by_query_hash()
models.db.session.commit()
except StaleDataError:
abort(409)

View File

@@ -2,6 +2,7 @@ import calendar
import datetime
import logging
import numbers
import re
import time
import pytz
@@ -228,7 +229,7 @@ class DataSource(BelongsToOrgMixin, db.Model):
def _sort_schema(self, schema):
return [
{"name": i["name"], "columns": sorted(i["columns"], key=lambda x: x["name"] if isinstance(x, dict) else x)}
{**i, "columns": sorted(i["columns"], key=lambda x: x["name"] if isinstance(x, dict) else x)}
for i in sorted(schema, key=lambda x: x["name"])
]
@@ -564,7 +565,7 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
db.session.query(tag_column, usage_count)
.group_by(tag_column)
.filter(Query.id.in_(queries.options(load_only("id"))))
.order_by(usage_count.desc())
.order_by(tag_column)
)
return query
@@ -644,6 +645,43 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
return list(outdated_queries.values())
@classmethod
def _do_multi_byte_search(cls, all_queries, term, limit=None):
# term examples:
# - word
# - name:word
# - query:word
# - "multiple words"
# - name:"multiple words"
# - word1 word2 word3
# - word1 "multiple word" query:"select foo"
tokens = re.findall(r'(?:([^:\s]+):)?(?:"([^"]+)"|(\S+))', term)
conditions = []
for token in tokens:
key = None
if token[0]:
key = token[0]
if token[1]:
value = token[1]
else:
value = token[2]
pattern = f"%{value}%"
if key == "id" and value.isdigit():
conditions.append(cls.id.equal(int(value)))
elif key == "name":
conditions.append(cls.name.ilike(pattern))
elif key == "query":
conditions.append(cls.query_text.ilike(pattern))
elif key == "description":
conditions.append(cls.description.ilike(pattern))
else:
conditions.append(or_(cls.name.ilike(pattern), cls.description.ilike(pattern)))
return all_queries.filter(and_(*conditions)).order_by(Query.id).limit(limit)
@classmethod
def search(
cls,
@@ -664,12 +702,7 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
if multi_byte_search:
# Since tsvector doesn't work well with CJK languages, use `ilike` too
pattern = "%{}%".format(term)
return (
all_queries.filter(or_(cls.name.ilike(pattern), cls.description.ilike(pattern)))
.order_by(Query.id)
.limit(limit)
)
return cls._do_multi_byte_search(all_queries, term, limit)
# sort the result using the weight as defined in the search vector column
return all_queries.search(term, sort=True).limit(limit)
@@ -678,13 +711,7 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
def search_by_user(cls, term, user, limit=None, multi_byte_search=False):
if multi_byte_search:
# Since tsvector doesn't work well with CJK languages, use `ilike` too
pattern = "%{}%".format(term)
return (
cls.by_user(user)
.filter(or_(cls.name.ilike(pattern), cls.description.ilike(pattern)))
.order_by(Query.id)
.limit(limit)
)
return cls._do_multi_byte_search(cls.by_user(user), term, limit)
return cls.by_user(user).search(term, sort=True).limit(limit)
@@ -726,6 +753,23 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
return db.session.execute(query, {"ids": tuple(query_ids)}).fetchall()
def update_latest_result_by_query_hash(self):
query_hash = self.query_hash
data_source_id = self.data_source_id
query_result = (
QueryResult.query.options(load_only("id"))
.filter(
QueryResult.query_hash == query_hash,
QueryResult.data_source_id == data_source_id,
)
.order_by(QueryResult.retrieved_at.desc())
.first()
)
if query_result:
latest_query_data_id = query_result.id
self.latest_query_data_id = latest_query_data_id
db.session.add(self)
@classmethod
def update_latest_result(cls, query_result):
# TODO: Investigate how big an impact this select-before-update makes.
@@ -1137,7 +1181,7 @@ class Dashboard(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model
db.session.query(tag_column, usage_count)
.group_by(tag_column)
.filter(Dashboard.id.in_(dashboards.options(load_only("id"))))
.order_by(usage_count.desc())
.order_by(tag_column)
)
return query
@@ -1145,15 +1189,19 @@ class Dashboard(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model
def favorites(cls, user, base_query=None):
if base_query is None:
base_query = cls.all(user.org, user.group_ids, user.id)
return base_query.join(
(
Favorite,
and_(
Favorite.object_type == "Dashboard",
Favorite.object_id == Dashboard.id,
),
return (
base_query.distinct(cls.lowercase_name, Dashboard.created_at, Dashboard.slug, Favorite.created_at)
.join(
(
Favorite,
and_(
Favorite.object_type == "Dashboard",
Favorite.object_id == Dashboard.id,
),
)
)
).filter(Favorite.user_id == user.id)
.filter(Favorite.user_id == user.id)
)
@classmethod
def by_user(cls, user):

View File

@@ -156,6 +156,11 @@ class BigQuery(BaseSQLQueryRunner):
"secret": ["jsonKeyFile"],
}
def annotate_query(self, query, metadata):
# Remove "Job ID" before annotating the query to avoid cache misses
metadata = {k: v for k, v in metadata.items() if k != "Job ID"}
return super().annotate_query(query, metadata)
def _get_bigquery_service(self):
socket.setdefaulttimeout(settings.BIGQUERY_HTTP_TIMEOUT)
@@ -215,11 +220,12 @@ class BigQuery(BaseSQLQueryRunner):
job_data = self._get_job_data(query)
insert_response = jobs.insert(projectId=project_id, body=job_data).execute()
self.current_job_id = insert_response["jobReference"]["jobId"]
self.current_job_location = insert_response["jobReference"]["location"]
current_row = 0
query_reply = _get_query_results(
jobs,
project_id=project_id,
location=self._get_location(),
location=self.current_job_location,
job_id=self.current_job_id,
start_index=current_row,
)
@@ -236,13 +242,11 @@ class BigQuery(BaseSQLQueryRunner):
query_result_request = {
"projectId": project_id,
"jobId": query_reply["jobReference"]["jobId"],
"jobId": self.current_job_id,
"startIndex": current_row,
"location": self.current_job_location,
}
if self._get_location():
query_result_request["location"] = self._get_location()
query_reply = jobs.getQueryResults(**query_result_request).execute()
columns = [
@@ -304,28 +308,70 @@ class BigQuery(BaseSQLQueryRunner):
datasets = self._get_project_datasets(project_id)
query_base = """
SELECT table_schema, table_name, field_path, data_type
SELECT table_schema, table_name, field_path, data_type, description
FROM `{dataset_id}`.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS
WHERE table_schema NOT IN ('information_schema')
"""
table_query_base = """
SELECT table_schema, table_name, JSON_VALUE(option_value) as table_description
FROM `{dataset_id}`.INFORMATION_SCHEMA.TABLE_OPTIONS
WHERE table_schema NOT IN ('information_schema')
AND option_name = 'description'
"""
location_dataset_ids = {}
schema = {}
queries = []
for dataset in datasets:
dataset_id = dataset["datasetReference"]["datasetId"]
query = query_base.format(dataset_id=dataset_id)
queries.append(query)
location = dataset["location"]
if self._get_location() and location != self._get_location():
logger.debug("dataset location is different: %s", location)
continue
query = "\nUNION ALL\n".join(queries)
results, error = self.run_query(query, None)
if error is not None:
self._handle_run_query_error(error)
if location not in location_dataset_ids:
location_dataset_ids[location] = []
location_dataset_ids[location].append(dataset_id)
for row in results["rows"]:
table_name = "{0}.{1}".format(row["table_schema"], row["table_name"])
if table_name not in schema:
schema[table_name] = {"name": table_name, "columns": []}
schema[table_name]["columns"].append({"name": row["field_path"], "type": row["data_type"]})
for location, datasets in location_dataset_ids.items():
queries = []
for dataset_id in datasets:
query = query_base.format(dataset_id=dataset_id)
queries.append(query)
query = "\nUNION ALL\n".join(queries)
results, error = self.run_query(query, None)
if error is not None:
self._handle_run_query_error(error)
for row in results["rows"]:
table_name = "{0}.{1}".format(row["table_schema"], row["table_name"])
if table_name not in schema:
schema[table_name] = {"name": table_name, "columns": []}
schema[table_name]["columns"].append(
{
"name": row["field_path"],
"type": row["data_type"],
"description": row["description"],
}
)
table_queries = []
for dataset_id in datasets:
table_query = table_query_base.format(dataset_id=dataset_id)
table_queries.append(table_query)
table_query = "\nUNION ALL\n".join(table_queries)
results, error = self.run_query(table_query, None)
if error is not None:
self._handle_run_query_error(error)
for row in results["rows"]:
table_name = "{0}.{1}".format(row["table_schema"], row["table_name"])
if table_name not in schema:
schema[table_name] = {"name": table_name, "columns": []}
if "table_description" in row:
schema[table_name]["description"] = row["table_description"]
return list(schema.values())
@@ -359,7 +405,7 @@ class BigQuery(BaseSQLQueryRunner):
self._get_bigquery_service().jobs().cancel(
projectId=self._get_project_id(),
jobId=self.current_job_id,
location=self._get_location(),
location=self.current_job_location,
).execute()
raise

View File

@@ -77,7 +77,11 @@ class ClickHouse(BaseSQLQueryRunner):
self._url = self._url._replace(netloc="{}:{}".format(self._url.hostname, port))
def _get_tables(self, schema):
query = "SELECT database, table, name FROM system.columns WHERE database NOT IN ('system')"
query = """
SELECT database, table, name, type as data_type
FROM system.columns
WHERE database NOT IN ('system', 'information_schema', 'INFORMATION_SCHEMA')
"""
results, error = self.run_query(query, None)
@@ -90,7 +94,7 @@ class ClickHouse(BaseSQLQueryRunner):
if table_name not in schema:
schema[table_name] = {"name": table_name, "columns": []}
schema[table_name]["columns"].append(row["name"])
schema[table_name]["columns"].append({"name": row["name"], "type": row["data_type"]})
return list(schema.values())

View File

@@ -0,0 +1,174 @@
import logging
from redash.query_runner import (
TYPE_BOOLEAN,
TYPE_DATE,
TYPE_DATETIME,
TYPE_FLOAT,
TYPE_INTEGER,
TYPE_STRING,
BaseSQLQueryRunner,
InterruptException,
register,
)
logger = logging.getLogger(__name__)
try:
import duckdb
enabled = True
except ImportError:
enabled = False
# Map DuckDB types to Redash column types
TYPES_MAP = {
"BOOLEAN": TYPE_BOOLEAN,
"TINYINT": TYPE_INTEGER,
"SMALLINT": TYPE_INTEGER,
"INTEGER": TYPE_INTEGER,
"BIGINT": TYPE_INTEGER,
"HUGEINT": TYPE_INTEGER,
"REAL": TYPE_FLOAT,
"DOUBLE": TYPE_FLOAT,
"DECIMAL": TYPE_FLOAT,
"VARCHAR": TYPE_STRING,
"BLOB": TYPE_STRING,
"DATE": TYPE_DATE,
"TIMESTAMP": TYPE_DATETIME,
"TIMESTAMP WITH TIME ZONE": TYPE_DATETIME,
"TIME": TYPE_DATETIME,
"INTERVAL": TYPE_STRING,
"UUID": TYPE_STRING,
"JSON": TYPE_STRING,
"STRUCT": TYPE_STRING,
"MAP": TYPE_STRING,
"UNION": TYPE_STRING,
}
class DuckDB(BaseSQLQueryRunner):
noop_query = "SELECT 1"
def __init__(self, configuration):
super().__init__(configuration)
self.dbpath = configuration.get("dbpath", ":memory:")
exts = configuration.get("extensions", "")
self.extensions = [e.strip() for e in exts.split(",") if e.strip()]
self._connect()
@classmethod
def configuration_schema(cls):
return {
"type": "object",
"properties": {
"dbpath": {
"type": "string",
"title": "Database Path",
"default": ":memory:",
},
"extensions": {"type": "string", "title": "Extensions (comma separated)"},
},
"order": ["dbpath", "extensions"],
"required": ["dbpath"],
}
@classmethod
def enabled(cls) -> bool:
return enabled
def _connect(self) -> None:
self.con = duckdb.connect(self.dbpath)
for ext in self.extensions:
try:
if "." in ext:
prefix, name = ext.split(".", 1)
if prefix == "community":
self.con.execute(f"INSTALL {name} FROM community")
self.con.execute(f"LOAD {name}")
else:
raise Exception("Unknown extension prefix.")
else:
self.con.execute(f"INSTALL {ext}")
self.con.execute(f"LOAD {ext}")
except Exception as e:
logger.warning("Failed to load extension %s: %s", ext, e)
def run_query(self, query, user) -> tuple:
try:
cursor = self.con.cursor()
cursor.execute(query)
columns = self.fetch_columns(
[(d[0], TYPES_MAP.get(d[1].upper(), TYPE_STRING)) for d in cursor.description]
)
rows = [dict(zip((col["name"] for col in columns), row)) for row in cursor.fetchall()]
data = {"columns": columns, "rows": rows}
return data, None
except duckdb.InterruptException:
raise InterruptException("Query cancelled by user.")
except Exception as e:
logger.exception("Error running query: %s", e)
return None, str(e)
def get_schema(self, get_stats=False) -> list:
tables_query = """
SELECT table_schema, table_name FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'pg_catalog');
"""
tables_results, error = self.run_query(tables_query, None)
if error:
raise Exception(f"Failed to get tables: {error}")
schema = {}
for table_row in tables_results["rows"]:
full_table_name = f"{table_row['table_schema']}.{table_row['table_name']}"
schema[full_table_name] = {"name": full_table_name, "columns": []}
describe_query = f'DESCRIBE "{table_row["table_schema"]}"."{table_row["table_name"]}";'
columns_results, error = self.run_query(describe_query, None)
if error:
logger.warning("Failed to describe table %s: %s", full_table_name, error)
continue
for col_row in columns_results["rows"]:
col = {"name": col_row["column_name"], "type": col_row["column_type"]}
schema[full_table_name]["columns"].append(col)
if col_row["column_type"].startswith("STRUCT("):
schema[full_table_name]["columns"].extend(
self._expand_struct_fields(col["name"], col_row["column_type"])
)
return list(schema.values())
def _expand_struct_fields(self, base_name: str, struct_type: str) -> list:
"""Recursively expand STRUCT(...) definitions into pseudo-columns."""
fields = []
# strip STRUCT( ... )
inner = struct_type[len("STRUCT(") : -1].strip()
# careful: nested structs, so parse comma-separated parts properly
depth, current, parts = 0, [], []
for c in inner:
if c == "(":
depth += 1
elif c == ")":
depth -= 1
if c == "," and depth == 0:
parts.append("".join(current).strip())
current = []
else:
current.append(c)
if current:
parts.append("".join(current).strip())
for part in parts:
# each part looks like: "fieldname TYPE"
fname, ftype = part.split(" ", 1)
colname = f"{base_name}.{fname}"
fields.append({"name": colname, "type": ftype})
if ftype.startswith("STRUCT("):
fields.extend(self._expand_struct_fields(colname, ftype))
return fields
register(DuckDB)

View File

@@ -34,9 +34,13 @@ class ResultSet:
def parse_issue(issue, field_mapping): # noqa: C901
result = OrderedDict()
result["key"] = issue["key"]
for k, v in issue["fields"].items(): #
# Handle API v3 response format: key field may be missing, use id as fallback
result["key"] = issue.get("key", issue.get("id", "unknown"))
# Handle API v3 response format: fields may be missing
fields = issue.get("fields", {})
for k, v in fields.items(): #
output_name = field_mapping.get_output_field_name(k)
member_names = field_mapping.get_dict_members(k)
@@ -98,7 +102,9 @@ def parse_issues(data, field_mapping):
def parse_count(data):
results = ResultSet()
results.add_row({"count": data["total"]})
# API v3 may not return 'total' field, fallback to counting issues
count = data.get("total", len(data.get("issues", [])))
results.add_row({"count": count})
return results
@@ -160,18 +166,26 @@ class JiraJQL(BaseHTTPQueryRunner):
self.syntax = "json"
def run_query(self, query, user):
jql_url = "{}/rest/api/2/search".format(self.configuration["url"])
# Updated to API v3 endpoint, fix double slash issue
jql_url = "{}/rest/api/3/search/jql".format(self.configuration["url"].rstrip("/"))
query = json_loads(query)
query_type = query.pop("queryType", "select")
field_mapping = FieldMapping(query.pop("fieldMapping", {}))
# API v3 requires mandatory jql parameter with restrictions
if "jql" not in query or not query["jql"]:
query["jql"] = "created >= -30d order by created DESC"
if query_type == "count":
query["maxResults"] = 1
query["fields"] = ""
else:
query["maxResults"] = query.get("maxResults", 1000)
if "fields" not in query:
query["fields"] = "*all"
response, error = self.get_response(jql_url, params=query)
if error is not None:
return None, error
@@ -182,17 +196,15 @@ class JiraJQL(BaseHTTPQueryRunner):
results = parse_count(data)
else:
results = parse_issues(data, field_mapping)
index = data["startAt"] + data["maxResults"]
while data["total"] > index:
query["startAt"] = index
# API v3 uses token-based pagination instead of startAt/total
while not data.get("isLast", True) and "nextPageToken" in data:
query["nextPageToken"] = data["nextPageToken"]
response, error = self.get_response(jql_url, params=query)
if error is not None:
return None, error
data = response.json()
index = data["startAt"] + data["maxResults"]
addl_results = parse_issues(data, field_mapping)
results.merge(addl_results)

View File

@@ -215,10 +215,10 @@ class MongoDB(BaseQueryRunner):
if readPreference:
kwargs["readPreference"] = readPreference
if "username" in self.configuration:
if self.configuration.get("username"):
kwargs["username"] = self.configuration["username"]
if "password" in self.configuration:
if self.configuration.get("password"):
kwargs["password"] = self.configuration["password"]
db_connection = pymongo.MongoClient(self.configuration["connectionString"], **kwargs)

View File

@@ -150,7 +150,9 @@ class Mysql(BaseSQLQueryRunner):
query = """
SELECT col.table_schema as table_schema,
col.table_name as table_name,
col.column_name as column_name
col.column_name as column_name,
col.data_type as data_type,
col.column_comment as column_comment
FROM `information_schema`.`columns` col
WHERE LOWER(col.table_schema) NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys');
"""
@@ -169,7 +171,38 @@ class Mysql(BaseSQLQueryRunner):
if table_name not in schema:
schema[table_name] = {"name": table_name, "columns": []}
schema[table_name]["columns"].append(row["column_name"])
schema[table_name]["columns"].append(
{
"name": row["column_name"],
"type": row["data_type"],
"description": row["column_comment"],
}
)
table_query = """
SELECT col.table_schema as table_schema,
col.table_name as table_name,
col.table_comment as table_comment
FROM `information_schema`.`tables` col
WHERE LOWER(col.table_schema) NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys'); \
"""
results, error = self.run_query(table_query, None)
if error is not None:
self._handle_run_query_error(error)
for row in results["rows"]:
if row["table_schema"] != self.configuration["db"]:
table_name = "{}.{}".format(row["table_schema"], row["table_name"])
else:
table_name = row["table_name"]
if table_name not in schema:
schema[table_name] = {"name": table_name, "columns": []}
if "table_comment" in row and row["table_comment"]:
schema[table_name]["description"] = row["table_comment"]
return list(schema.values())

View File

@@ -138,6 +138,15 @@ def _get_ssl_config(configuration):
return ssl_config
def _parse_dsn(configuration):
standard_params = {"user", "password", "host", "port", "dbname"}
params = psycopg2.extensions.parse_dsn(configuration.get("dsn", ""))
overlap = standard_params.intersection(params.keys())
if overlap:
raise ValueError("Extra parameters may not contain {}".format(overlap))
return params
class PostgreSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
@@ -151,6 +160,7 @@ class PostgreSQL(BaseSQLQueryRunner):
"host": {"type": "string", "default": "127.0.0.1"},
"port": {"type": "number", "default": 5432},
"dbname": {"type": "string", "title": "Database Name"},
"dsn": {"type": "string", "default": "application_name=redash", "title": "Parameters"},
"sslmode": {
"type": "string",
"title": "SSL Mode",
@@ -205,24 +215,15 @@ class PostgreSQL(BaseSQLQueryRunner):
def _get_tables(self, schema):
"""
relkind constants per https://www.postgresql.org/docs/10/static/catalog-pg-class.html
r = regular table
v = view
relkind constants from https://www.postgresql.org/docs/current/catalog-pg-class.html
m = materialized view
f = foreign table
p = partitioned table (new in 10)
---
i = index
S = sequence
t = TOAST table
c = composite type
"""
query = """
SELECT s.nspname as table_schema,
c.relname as table_name,
a.attname as column_name,
null as data_type
SELECT s.nspname AS table_schema,
c.relname AS table_name,
a.attname AS column_name,
NULL AS data_type
FROM pg_class c
JOIN pg_namespace s
ON c.relnamespace = s.oid
@@ -231,8 +232,8 @@ class PostgreSQL(BaseSQLQueryRunner):
ON a.attrelid = c.oid
AND a.attnum > 0
AND NOT a.attisdropped
WHERE c.relkind IN ('m', 'f', 'p')
AND has_table_privilege(s.nspname || '.' || c.relname, 'select')
WHERE c.relkind = 'm'
AND has_table_privilege(quote_ident(s.nspname) || '.' || quote_ident(c.relname), 'select')
AND has_schema_privilege(s.nspname, 'usage')
UNION
@@ -243,6 +244,8 @@ class PostgreSQL(BaseSQLQueryRunner):
data_type
FROM information_schema.columns
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
AND has_table_privilege(quote_ident(table_schema) || '.' || quote_ident(table_name), 'select')
AND has_schema_privilege(table_schema, 'usage')
"""
self._get_definitions(schema, query)
@@ -251,6 +254,7 @@ class PostgreSQL(BaseSQLQueryRunner):
def _get_connection(self):
self.ssl_config = _get_ssl_config(self.configuration)
self.dsn = _parse_dsn(self.configuration)
connection = psycopg2.connect(
user=self.configuration.get("user"),
password=self.configuration.get("password"),
@@ -259,6 +263,7 @@ class PostgreSQL(BaseSQLQueryRunner):
dbname=self.configuration.get("dbname"),
async_=True,
**self.ssl_config,
**self.dsn,
)
return connection

View File

@@ -1,11 +1,14 @@
try:
import snowflake.connector
from cryptography.hazmat.primitives.serialization import load_pem_private_key
enabled = True
except ImportError:
enabled = False
from base64 import b64decode
from redash import __version__
from redash.query_runner import (
TYPE_BOOLEAN,
@@ -43,6 +46,8 @@ class Snowflake(BaseSQLQueryRunner):
"account": {"type": "string"},
"user": {"type": "string"},
"password": {"type": "string"},
"private_key_File": {"type": "string"},
"private_key_pwd": {"type": "string"},
"warehouse": {"type": "string"},
"database": {"type": "string"},
"region": {"type": "string", "default": "us-west"},
@@ -57,13 +62,15 @@ class Snowflake(BaseSQLQueryRunner):
"account",
"user",
"password",
"private_key_File",
"private_key_pwd",
"warehouse",
"database",
"region",
"host",
],
"required": ["user", "password", "account", "database", "warehouse"],
"secret": ["password"],
"required": ["user", "account", "database", "warehouse"],
"secret": ["password", "private_key_File", "private_key_pwd"],
"extra_options": [
"host",
],
@@ -88,7 +95,7 @@ class Snowflake(BaseSQLQueryRunner):
if region == "us-west":
region = None
if self.configuration.__contains__("host"):
if self.configuration.get("host"):
host = self.configuration.get("host")
else:
if region:
@@ -96,14 +103,29 @@ class Snowflake(BaseSQLQueryRunner):
else:
host = "{}.snowflakecomputing.com".format(account)
connection = snowflake.connector.connect(
user=self.configuration["user"],
password=self.configuration["password"],
account=account,
region=region,
host=host,
application="Redash/{} (Snowflake)".format(__version__.split("-")[0]),
)
params = {
"user": self.configuration["user"],
"account": account,
"region": region,
"host": host,
"application": "Redash/{} (Snowflake)".format(__version__.split("-")[0]),
}
if self.configuration.get("password"):
params["password"] = self.configuration["password"]
elif self.configuration.get("private_key_File"):
private_key_b64 = self.configuration.get("private_key_File")
private_key_bytes = b64decode(private_key_b64)
if self.configuration.get("private_key_pwd"):
private_key_pwd = self.configuration.get("private_key_pwd").encode()
else:
private_key_pwd = None
private_key_pem = load_pem_private_key(private_key_bytes, private_key_pwd)
params["private_key"] = private_key_pem
else:
raise Exception("Neither password nor private_key_b64 is set.")
connection = snowflake.connector.connect(**params)
return connection

View File

@@ -25,6 +25,7 @@ def init_app(app):
app.config["WTF_CSRF_CHECK_DEFAULT"] = False
app.config["WTF_CSRF_SSL_STRICT"] = False
app.config["WTF_CSRF_TIME_LIMIT"] = settings.CSRF_TIME_LIMIT
app.config["SESSION_COOKIE_NAME"] = settings.SESSION_COOKIE_NAME
@app.after_request
def inject_csrf_token(response):

View File

@@ -82,9 +82,19 @@ class QuerySerializer(Serializer):
else:
result = [serialize_query(query, **self.options) for query in self.object_or_list]
if self.options.get("with_favorite_state", True):
favorite_ids = models.Favorite.are_favorites(current_user.id, self.object_or_list)
queries = list(self.object_or_list)
favorites = models.Favorite.query.filter(
models.Favorite.object_id.in_([o.id for o in queries]),
models.Favorite.object_type == "Query",
models.Favorite.user_id == current_user.id,
)
favorites_dict = {fav.object_id: fav for fav in favorites}
for query in result:
query["is_favorite"] = query["id"] in favorite_ids
favorite = favorites_dict.get(query["id"])
query["is_favorite"] = favorite is not None
if favorite:
query["starred_at"] = favorite.created_at
return result
@@ -263,9 +273,19 @@ class DashboardSerializer(Serializer):
else:
result = [serialize_dashboard(obj, **self.options) for obj in self.object_or_list]
if self.options.get("with_favorite_state", True):
favorite_ids = models.Favorite.are_favorites(current_user.id, self.object_or_list)
for obj in result:
obj["is_favorite"] = obj["id"] in favorite_ids
dashboards = list(self.object_or_list)
favorites = models.Favorite.query.filter(
models.Favorite.object_id.in_([o.id for o in dashboards]),
models.Favorite.object_type == "Dashboard",
models.Favorite.user_id == current_user.id,
)
favorites_dict = {fav.object_id: fav for fav in favorites}
for query in result:
favorite = favorites_dict.get(query["id"])
query["is_favorite"] = favorite is not None
if favorite:
query["starred_at"] = favorite.created_at
return result

View File

@@ -82,6 +82,7 @@ SESSION_COOKIE_SECURE = parse_boolean(os.environ.get("REDASH_SESSION_COOKIE_SECU
# Whether the session cookie is set HttpOnly.
SESSION_COOKIE_HTTPONLY = parse_boolean(os.environ.get("REDASH_SESSION_COOKIE_HTTPONLY", "true"))
SESSION_EXPIRY_TIME = int(os.environ.get("REDASH_SESSION_EXPIRY_TIME", 60 * 60 * 6))
SESSION_COOKIE_NAME = os.environ.get("REDASH_SESSION_COOKIE_NAME", "session")
# Whether the session cookie is set to secure.
REMEMBER_COOKIE_SECURE = parse_boolean(os.environ.get("REDASH_REMEMBER_COOKIE_SECURE") or str(COOKIES_SECURE))
@@ -135,6 +136,13 @@ FEATURE_POLICY = os.environ.get("REDASH_FEATURE_POLICY", "")
MULTI_ORG = parse_boolean(os.environ.get("REDASH_MULTI_ORG", "false"))
# If Redash is behind a proxy it might sometimes receive a X-Forwarded-Proto of HTTP
# even if your actual Redash URL scheme is HTTPS. This will cause Flask to build
# the OAuth redirect URL incorrectly thus failing auth. This is especially common if
# you're behind a SSL/TCP configured AWS ELB or similar.
# This setting will force the URL scheme.
GOOGLE_OAUTH_SCHEME_OVERRIDE = os.environ.get("REDASH_GOOGLE_OAUTH_SCHEME_OVERRIDE", "")
GOOGLE_CLIENT_ID = os.environ.get("REDASH_GOOGLE_CLIENT_ID", "")
GOOGLE_CLIENT_SECRET = os.environ.get("REDASH_GOOGLE_CLIENT_SECRET", "")
GOOGLE_OAUTH_ENABLED = bool(GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET)
@@ -340,6 +348,7 @@ default_query_runners = [
"redash.query_runner.oracle",
"redash.query_runner.e6data",
"redash.query_runner.risingwave",
"redash.query_runner.duckdb",
]
enabled_query_runners = array_from_string(

View File

@@ -27,6 +27,7 @@ DATE_FORMAT = os.environ.get("REDASH_DATE_FORMAT", "DD/MM/YY")
TIME_FORMAT = os.environ.get("REDASH_TIME_FORMAT", "HH:mm")
INTEGER_FORMAT = os.environ.get("REDASH_INTEGER_FORMAT", "0,0")
FLOAT_FORMAT = os.environ.get("REDASH_FLOAT_FORMAT", "0,0.00")
NULL_VALUE = os.environ.get("REDASH_NULL_VALUE", "null")
MULTI_BYTE_SEARCH_ENABLED = parse_boolean(os.environ.get("MULTI_BYTE_SEARCH_ENABLED", "false"))
JWT_LOGIN_ENABLED = parse_boolean(os.environ.get("REDASH_JWT_LOGIN_ENABLED", "false"))
@@ -59,6 +60,7 @@ settings = {
"time_format": TIME_FORMAT,
"integer_format": INTEGER_FORMAT,
"float_format": FLOAT_FORMAT,
"null_value": NULL_VALUE,
"multi_byte_search_enabled": MULTI_BYTE_SEARCH_ENABLED,
"auth_jwt_login_enabled": JWT_LOGIN_ENABLED,
"auth_jwt_auth_issuer": JWT_AUTH_ISSUER,

View File

@@ -20,7 +20,7 @@ class TestBigQueryQueryRunner(unittest.TestCase):
query = "SELECT a FROM tbl"
expect = (
"/* Username: username, query_id: adhoc, "
"Job ID: job-id, Query Hash: query-hash, "
"Query Hash: query-hash, "
"Scheduled: False */ SELECT a FROM tbl"
)

View File

@@ -0,0 +1,107 @@
from unittest import TestCase
from unittest.mock import patch
from redash.query_runner.duckdb import DuckDB
class TestDuckDBSchema(TestCase):
def setUp(self) -> None:
self.runner = DuckDB({"dbpath": ":memory:"})
@patch.object(DuckDB, "run_query")
def test_simple_schema_build(self, mock_run_query) -> None:
# Simulate queries: first for tables, then for DESCRIBE
mock_run_query.side_effect = [
(
{"rows": [{"table_schema": "main", "table_name": "users"}]},
None,
),
(
{
"rows": [
{"column_name": "id", "column_type": "INTEGER"},
{"column_name": "name", "column_type": "VARCHAR"},
]
},
None,
),
]
schema = self.runner.get_schema()
self.assertEqual(len(schema), 1)
self.assertEqual(schema[0]["name"], "main.users")
self.assertListEqual(
schema[0]["columns"],
[{"name": "id", "type": "INTEGER"}, {"name": "name", "type": "VARCHAR"}],
)
@patch.object(DuckDB, "run_query")
def test_struct_column_expansion(self, mock_run_query) -> None:
# First call to run_query -> tables list
mock_run_query.side_effect = [
(
{"rows": [{"table_schema": "main", "table_name": "events"}]},
None,
),
# Second call -> DESCRIBE output
(
{
"rows": [
{
"column_name": "payload",
"column_type": "STRUCT(a INTEGER, b VARCHAR)",
}
]
},
None,
),
]
schema_list = self.runner.get_schema()
self.assertEqual(len(schema_list), 1)
schema = schema_list[0]
# Ensure both raw and expanded struct fields are present
self.assertIn("main.events", schema["name"])
self.assertListEqual(
schema["columns"],
[
{"name": "payload", "type": "STRUCT(a INTEGER, b VARCHAR)"},
{"name": "payload.a", "type": "INTEGER"},
{"name": "payload.b", "type": "VARCHAR"},
],
)
def test_nested_struct_expansion(self) -> None:
runner = DuckDB({"dbpath": ":memory:"})
runner.con.execute(
"""
CREATE TABLE sample_struct_table (
id INTEGER,
info STRUCT(
name VARCHAR,
metrics STRUCT(score DOUBLE, rank INTEGER),
tags STRUCT(primary_tag VARCHAR, secondary_tag VARCHAR)
)
);
"""
)
schema = runner.get_schema()
table = next(t for t in schema if t["name"] == "main.sample_struct_table")
colnames = [c["name"] for c in table["columns"]]
assert "info" in colnames
assert 'info."name"' in colnames
assert "info.metrics" in colnames
assert "info.metrics.score" in colnames
assert "info.metrics.rank" in colnames
assert "info.tags.primary_tag" in colnames
assert "info.tags.secondary_tag" in colnames
@patch.object(DuckDB, "run_query")
def test_error_propagation(self, mock_run_query) -> None:
mock_run_query.return_value = (None, "boom")
with self.assertRaises(Exception) as ctx:
self.runner.get_schema()
self.assertIn("boom", str(ctx.exception))

View File

@@ -1,6 +1,16 @@
from unittest import TestCase
from redash.query_runner.pg import build_schema
from redash.query_runner.pg import _parse_dsn, build_schema
class TestParameters(TestCase):
def test_parse_dsn(self):
configuration = {"dsn": "application_name=redash connect_timeout=5"}
self.assertDictEqual(_parse_dsn(configuration), {"application_name": "redash", "connect_timeout": "5"})
def test_parse_dsn_not_permitted(self):
configuration = {"dsn": "password=xyz"}
self.assertRaises(ValueError, _parse_dsn, configuration)
class TestBuildSchema(TestCase):

View File

@@ -46,7 +46,7 @@
"@types/jest": "^26.0.18",
"@types/leaflet": "^1.5.19",
"@types/numeral": "0.0.28",
"@types/plotly.js": "^2.35.2",
"@types/plotly.js": "^3.0.3",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/tinycolor2": "^1.4.2",
@@ -62,7 +62,7 @@
"less-loader": "^11.1.3",
"less-plugin-autoprefix": "^2.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"prettier": "3.3.2",
"prop-types": "^15.7.2",
"style-loader": "^3.3.3",
"ts-migrate": "^0.1.35",
@@ -91,7 +91,7 @@
"leaflet.markercluster": "^1.1.0",
"lodash": "^4.17.10",
"numeral": "^2.0.6",
"plotly.js": "2.35.3",
"plotly.js": "3.1.0",
"react-pivottable": "^0.9.0",
"react-sortable-hoc": "^1.10.1",
"tinycolor2": "^1.4.1",

View File

@@ -5,6 +5,7 @@ import numeral from "numeral";
import { isString, isArray, isUndefined, isFinite, isNil, toString } from "lodash";
import { visualizationsSettings } from "@/visualizations/visualizationsSettings";
numeral.options.scalePercentBy100 = false;
// eslint-disable-next-line
@@ -12,9 +13,16 @@ const urlPattern = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019
const hasOwnProperty = Object.prototype.hasOwnProperty;
function NullValueComponent() {
return <span className="display-as-null">{visualizationsSettings.nullValue}</span>;
}
export function createTextFormatter(highlightLinks: any) {
if (highlightLinks) {
return (value: any) => {
if (value === null) {
return <NullValueComponent/>
}
if (isString(value)) {
const Link = visualizationsSettings.LinkComponent;
value = value.replace(urlPattern, (unused, prefix, href) => {
@@ -29,7 +37,7 @@ export function createTextFormatter(highlightLinks: any) {
return toString(value);
};
}
return (value: any) => toString(value);
return (value: any) => value === null ? <NullValueComponent/> : toString(value);
}
function toMoment(value: any) {
@@ -46,11 +54,14 @@ function toMoment(value: any) {
export function createDateTimeFormatter(format: any) {
if (isString(format) && format !== "") {
return (value: any) => {
if (value === null) {
return <NullValueComponent/>;
}
const wrapped = toMoment(value);
return wrapped.isValid() ? wrapped.format(format) : toString(value);
};
}
return (value: any) => toString(value);
return (value: any) => value === null ? <NullValueComponent/> : toString(value);
}
export function createBooleanFormatter(values: any) {
@@ -58,6 +69,9 @@ export function createBooleanFormatter(values: any) {
if (values.length >= 2) {
// Both `true` and `false` specified
return (value: any) => {
if (value === null) {
return <NullValueComponent/>;
}
if (isNil(value)) {
return "";
}
@@ -69,6 +83,9 @@ export function createBooleanFormatter(values: any) {
}
}
return (value: any) => {
if (value === null) {
return <NullValueComponent/>;
}
if (isNil(value)) {
return "";
}
@@ -76,12 +93,20 @@ export function createBooleanFormatter(values: any) {
};
}
export function createNumberFormatter(format: any) {
export function createNumberFormatter(format: any, canReturnHTMLElement: boolean = false) {
if (isString(format) && format !== "") {
const n = numeral(0); // cache `numeral` instance
return (value: any) => (value === null || value === "" ? "" : n.set(value).format(format));
return (value: any) => {
if (canReturnHTMLElement && value === null) {
return <NullValueComponent/>;
}
if (value === "" || value === null) {
return "";
}
return n.set(value).format(format);
}
}
return (value: any) => toString(value);
return (value: any) => (canReturnHTMLElement && value === null) ? <NullValueComponent/> : toString(value);
}
export function formatSimpleTemplate(str: any, data: any) {

View File

@@ -6,7 +6,7 @@ import { EditorPropTypes } from "@/visualizations/prop-types";
const defaultCustomCode = trimStart(`
// Available variables are x, ys, element, and Plotly
// Type console.log(x, ys); for more info about x and ys
// To plot your graph call Plotly.plot(element, ...)
// To plot your graph call Plotly.newPlot(element, ...)
// Plotly examples and docs: https://plot.ly/javascript/
`);

View File

@@ -336,7 +336,39 @@ export default function GeneralSettings({ options, data, onOptionsChange }: any)
</Section>
)}
{!includes(["custom", "heatmap", "bubble", "scatter"], options.globalSeriesType) && (
{includes(["line", "area"], options.globalSeriesType) && (
// @ts-expect-error ts-migrate(2745) FIXME: This JSX tag's 'children' prop expects type 'never... Remove this comment to see the full error message
<Section>
<Select
label="Line Shape"
data-test="Chart.LineShape"
defaultValue={options.lineShape}
onChange={(val: any) => onOptionsChange({ lineShape: val })}>
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
<Select.Option value="linear" data-test="Chart.LineShape.Linear">
Linear
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
</Select.Option>
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
<Select.Option value="spline" data-test="Chart.LineShape.Spline">
Spline
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
</Select.Option>
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
<Select.Option value="hv" data-test="Chart.LineShape.HorizontalVertical">
Horizontal-Vertical
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
</Select.Option>
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
<Select.Option value="vh" data-test="Chart.LineShape.VerticalHorizontal">
Vertical-Horizontal
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
</Select.Option>
</Select>
</Section>
)}
{!includes(["custom", "heatmap", "bubble"], options.globalSeriesType) && (
// @ts-expect-error ts-migrate(2745) FIXME: This JSX tag's 'children' prop expects type 'never... Remove this comment to see the full error message
<Section>
<Select

View File

@@ -18,6 +18,7 @@ const DEFAULT_OPTIONS = {
coefficient: 1,
piesort: true,
color_scheme: "Redash",
lineShape: "linear",
// showDataLabels: false, // depends on chart type
numberFormat: "0,0[.]00000",

View File

@@ -10,7 +10,7 @@ export default {
Renderer,
Editor,
defaultColumns: 3,
defaultColumns: 6,
defaultRows: 8,
minColumns: 1,
minRows: 5,

View File

@@ -48,7 +48,6 @@
"series": [
{
"visible": true,
"offsetgroup": "0",
"type": "bar",
"name": "a",
"x": ["x1", "x2", "x3", "x4"],
@@ -64,7 +63,6 @@
},
{
"visible": true,
"offsetgroup": "1",
"type": "bar",
"name": "b",
"x": ["x1", "x2", "x3", "x4"],

View File

@@ -48,7 +48,6 @@
"series": [
{
"visible": true,
"offsetgroup": "0",
"type": "bar",
"name": "a",
"x": ["x1", "x2", "x3", "x4"],
@@ -64,7 +63,6 @@
},
{
"visible": true,
"offsetgroup": "1",
"type": "bar",
"name": "b",
"x": ["x1", "x2", "x3", "x4"],

View File

@@ -20,7 +20,8 @@
"x": "x",
"y1": "y"
},
"missingValuesAsZero": true
"missingValuesAsZero": true,
"lineShape": "linear"
},
"data": [
{
@@ -46,6 +47,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
"line": { "shape": "linear" },
"marker": { "color": "red" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"

View File

@@ -21,7 +21,8 @@
"x": "x",
"y1": "y"
},
"missingValuesAsZero": false
"missingValuesAsZero": false,
"lineShape": "linear"
},
"data": [
{
@@ -54,6 +55,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
"line": { "shape": "linear" },
"marker": { "color": "red" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"
@@ -68,6 +70,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["", "2 ± 0", "", "4 ± 0"],
"line": { "shape": "linear" },
"marker": { "color": "blue" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"

View File

@@ -21,7 +21,8 @@
"x": "x",
"y1": "y"
},
"missingValuesAsZero": true
"missingValuesAsZero": true,
"lineShape": "linear"
},
"data": [
{
@@ -54,6 +55,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
"line": { "shape": "linear" },
"marker": { "color": "red" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"
@@ -68,6 +70,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["0", "2 ± 0", "0", "4 ± 0"],
"line": { "shape": "linear" },
"marker": { "color": "blue" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"

View File

@@ -21,7 +21,8 @@
"x": "x",
"y1": "y"
},
"missingValuesAsZero": true
"missingValuesAsZero": true,
"lineShape": "linear"
},
"data": [
{
@@ -56,6 +57,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["20% (10 ± 0)", "40% (20 ± 0)", "60% (30 ± 0)", "80% (40 ± 0)"],
"line": { "shape": "linear" },
"marker": { "color": "red" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"
@@ -70,6 +72,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["80% (40 ± 0)", "60% (30 ± 0)", "40% (20 ± 0)", "20% (10 ± 0)"],
"line": { "shape": "linear" },
"marker": { "color": "blue" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"

View File

@@ -21,7 +21,8 @@
"x": "x",
"y1": "y"
},
"missingValuesAsZero": true
"missingValuesAsZero": true,
"lineShape": "linear"
},
"data": [
{
@@ -56,6 +57,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["20% (10 ± 0)", "40% (20 ± 0)", "60% (30 ± 0)", "80% (40 ± 0)"],
"line": { "shape": "linear" },
"marker": { "color": "red" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"
@@ -70,6 +72,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["80% (40 ± 0)", "60% (30 ± 0)", "40% (20 ± 0)", "20% (10 ± 0)"],
"line": { "shape": "linear" },
"marker": { "color": "blue" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"

View File

@@ -21,7 +21,8 @@
"x": "x",
"y1": "y"
},
"missingValuesAsZero": true
"missingValuesAsZero": true,
"lineShape": "linear"
},
"data": [
{
@@ -56,6 +57,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
"line": { "shape": "linear" },
"marker": { "color": "red" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"
@@ -70,6 +72,7 @@
"hoverinfo": "text+x+name",
"hover": [],
"text": ["1 ± 0", "2 ± 0", "3 ± 0", "4 ± 0"],
"line": { "shape": "linear" },
"marker": { "color": "blue" },
"insidetextfont": { "color": "#ffffff" },
"yaxis": "y"

View File

@@ -8,10 +8,30 @@ import updateAxes from "./updateAxes";
import updateChartSize from "./updateChartSize";
import { prepareCustomChartData, createCustomChartRenderer } from "./customChartUtils";
// @ts-expect-error ts-migrate(2339) FIXME: Property 'setPlotConfig' does not exist on type 't... Remove this comment to see the full error message
const rangeSliderIcon = {
'width': 400,
'height': 400,
'path': 'M50 180h300a20 20 0 0 1 0 40H50a20 20 0 0 1 0-40z M160 200a40 40 0 1 0 -80 0a40 40 0 1 0 80 0 M320 200a40 40 0 1 0 -80 0a40 40 0 1 0 80 0',
};
Plotly.setPlotConfig({
modeBarButtonsToRemove: ["sendDataToCloud"],
modeBarButtonsToAdd: ["togglespikelines", "v1hovermode"],
modeBarButtonsToAdd: ["togglespikelines", "v1hovermode",
{
name: 'toggleRangeslider',
title: 'Toggle rangeslider',
icon: rangeSliderIcon,
click: function(gd: any) {
if(gd?.layout?.xaxis) {
let newRangeslider: any = {};
if (gd.layout.xaxis?.rangeslider) {
newRangeslider = null;
}
(Plotly.relayout as any)(gd, 'xaxis.rangeslider', newRangeslider);
}
}
},
],
locale: window.navigator.language,
});

View File

@@ -26,7 +26,9 @@ function getHoverInfoPattern(options: any) {
function prepareBarSeries(series: any, options: any, additionalOptions: any) {
series.type = "bar";
series.offsetgroup = toString(additionalOptions.index);
if (!options.series.stacking) {
series.offsetgroup = toString(additionalOptions.index);
}
if (options.showDataLabels) {
series.textposition = "inside";
} else {
@@ -37,11 +39,17 @@ function prepareBarSeries(series: any, options: any, additionalOptions: any) {
function prepareLineSeries(series: any, options: any) {
series.mode = "lines" + (options.showDataLabels ? "+text" : "");
series.line = {
shape: options.lineShape,
}
return series;
}
function prepareAreaSeries(series: any, options: any) {
series.mode = "lines" + (options.showDataLabels ? "+text" : "");
series.line = {
shape: options.lineShape,
}
series.fill = options.series.stacking ? "tonexty" : "tozeroy";
return series;
}
@@ -94,7 +102,10 @@ function prepareSeries(series: any, options: any, numSeries: any, additionalOpti
// For bubble/scatter charts `y` may be any (similar to `x`) - numeric is only bubble size;
// for other types `y` is always number
const cleanYValue = includes(["bubble", "scatter"], seriesOptions.type)
? normalizeValue
? (v: any, axixType: any) => {
v = normalizeValue(v, axixType);
return includes(["scatter"], seriesOptions.type) && options.missingValuesAsZero && isNil(v) ? 0.0 : v;
}
: (v: any) => {
v = cleanNumber(v);
return options.missingValuesAsZero && isNil(v) ? 0.0 : v;

View File

@@ -9,7 +9,7 @@ export default {
Renderer,
Editor,
defaultColumns: 3,
defaultColumns: 6,
defaultRows: 8,
minColumns: 2,
};

View File

@@ -22,6 +22,6 @@ export default {
Renderer,
Editor,
defaultColumns: 2,
defaultColumns: 4,
defaultRows: 5,
};

View File

@@ -1,64 +0,0 @@
import React, { useState } from "react";
import { map, mapValues, keyBy } from "lodash";
import moment from "moment";
import { RendererPropTypes } from "@/visualizations/prop-types";
import { visualizationsSettings } from "@/visualizations/visualizationsSettings";
import Descriptions from "antd/lib/descriptions";
import Pagination from "antd/lib/pagination";
import "./details.less";
function renderValue(value: any, type: any) {
const formats = {
date: visualizationsSettings.dateFormat,
datetime: visualizationsSettings.dateTimeFormat,
};
if (type === "date" || type === "datetime") {
if (moment.isMoment(value)) {
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return value.format(formats[type]);
}
}
return "" + value;
}
export default function DetailsRenderer({ data }: any) {
const [page, setPage] = useState(0);
if (!data || !data.rows || data.rows.length === 0) {
return null;
}
const types = mapValues(keyBy(data.columns, "name"), "type");
// We use columsn to maintain order of columns in the view.
const columns = data.columns.map((column: any) => column.name);
const row = data.rows[page];
return (
<div className="details-viz">
<Descriptions size="small" column={1} bordered>
{map(columns, key => (
<Descriptions.Item key={key} label={key}>
{renderValue(row[key], types[key])}
</Descriptions.Item>
))}
</Descriptions>
{data.rows.length > 1 && (
<div className="paginator-container">
<Pagination
showSizeChanger={false}
current={page + 1}
defaultPageSize={1}
total={data.rows.length}
onChange={p => setPage(p - 1)}
/>
</div>
)}
</div>
);
}
DetailsRenderer.propTypes = RendererPropTypes;

View File

@@ -0,0 +1,31 @@
import React from "react";
import SharedColumnEditor from "../../shared/components/ColumnEditor";
type OwnProps = {
column: {
name: string;
title?: string;
visible?: boolean;
alignContent?: "left" | "center" | "right";
displayAs?: any;
description?: string;
};
onChange?: (...args: any[]) => any;
};
type Props = OwnProps & typeof ColumnEditor.defaultProps;
export default function ColumnEditor({ column, onChange }: Props) {
return (
<SharedColumnEditor
column={column}
onChange={onChange}
variant="details"
showSearch={false}
/>
);
}
ColumnEditor.defaultProps = {
onChange: (...args: any[]) => {},
};

View File

@@ -0,0 +1,98 @@
import React from "react";
import enzyme from "enzyme";
import getOptions from "../getOptions";
import ColumnsSettings from "./ColumnsSettings";
function findByTestID(wrapper: any, testId: any) {
return wrapper.find(`[data-test="${testId}"]`);
}
function mount(options: any, done: any) {
const data = {
columns: [
{ name: "id", type: "integer" },
{ name: "name", type: "string" },
{ name: "created_at", type: "datetime" },
],
rows: [{ id: 1, name: "test", created_at: "2023-01-01T00:00:00Z" }],
};
options = getOptions(options, data);
return enzyme.mount(
<ColumnsSettings
visualizationName="Details"
data={data}
options={options}
onOptionsChange={changedOptions => {
expect(changedOptions).toMatchSnapshot();
done();
}}
/>
);
}
describe("Visualizations -> Details -> Editor -> Columns Settings", () => {
test("Toggles column visibility", done => {
const el = mount({}, done);
findByTestID(el, "Details.Column.id.Visibility")
.last()
.simulate("click");
});
test("Changes column title", done => {
const el = mount({}, done);
findByTestID(el, "Details.Column.name.Name")
.last()
.simulate("click"); // expand settings
findByTestID(el, "Details.Column.name.Title")
.last()
.simulate("change", { target: { value: "Full Name" } });
});
test("Changes column alignment", done => {
const el = mount({}, done);
findByTestID(el, "Details.Column.id.Name")
.last()
.simulate("click"); // expand settings
findByTestID(el, "Details.Column.id.TextAlignment")
.last()
.find('[data-test="TextAlignmentSelect.Center"] input')
.simulate("change", { target: { checked: true } });
});
test("Changes column description", done => {
const el = mount({}, done);
findByTestID(el, "Details.Column.name.Name")
.last()
.simulate("click"); // expand settings
findByTestID(el, "Details.Column.name.Description")
.last()
.simulate("change", { target: { value: "User full name" } });
});
test("Changes column display type", done => {
const el = mount({}, done);
findByTestID(el, "Details.Column.created_at.Name")
.last()
.simulate("click"); // expand settings
findByTestID(el, "Details.Column.created_at.DisplayAs")
.last()
.simulate("mouseDown");
findByTestID(el, "Details.Column.created_at.DisplayAs.string")
.last()
.simulate("click");
});
test("Hides multiple columns", done => {
const el = mount({}, done);
findByTestID(el, "Details.Column.id.Visibility")
.last()
.simulate("click");
});
});

View File

@@ -0,0 +1,15 @@
import React from "react";
import SharedColumnsSettings from "../../shared/components/ColumnsSettings";
import { EditorPropTypes } from "@/visualizations/prop-types";
export default function ColumnsSettings({ options, onOptionsChange, data }: any) {
return (
<SharedColumnsSettings
options={options}
onOptionsChange={onOptionsChange}
variant="details"
/>
);
}
ColumnsSettings.propTypes = EditorPropTypes;

View File

@@ -0,0 +1,529 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Visualizations -> Details -> Editor -> Columns Settings Changes column alignment 1`] = `
Object {
"columns": Array [
Object {
"alignContent": "center",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "number",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "id",
"nullValue": "null",
"numberFormat": "0,0",
"order": 100000,
"title": "id",
"type": "integer",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "string",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "name",
"nullValue": "null",
"numberFormat": undefined,
"order": 100001,
"title": "name",
"type": "string",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": "DD/MM/YYYY HH:mm",
"description": "",
"displayAs": "datetime",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "created_at",
"nullValue": "null",
"numberFormat": undefined,
"order": 100002,
"title": "created_at",
"type": "datetime",
"visible": true,
},
],
}
`;
exports[`Visualizations -> Details -> Editor -> Columns Settings Changes column description 1`] = `
Object {
"columns": Array [
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "number",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "id",
"nullValue": "null",
"numberFormat": "0,0",
"order": 100000,
"title": "id",
"type": "integer",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "User full name",
"displayAs": "string",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "name",
"nullValue": "null",
"numberFormat": undefined,
"order": 100001,
"title": "name",
"type": "string",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": "DD/MM/YYYY HH:mm",
"description": "",
"displayAs": "datetime",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "created_at",
"nullValue": "null",
"numberFormat": undefined,
"order": 100002,
"title": "created_at",
"type": "datetime",
"visible": true,
},
],
}
`;
exports[`Visualizations -> Details -> Editor -> Columns Settings Changes column display type 1`] = `
Object {
"columns": Array [
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "number",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "id",
"nullValue": "null",
"numberFormat": "0,0",
"order": 100000,
"title": "id",
"type": "integer",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "string",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "name",
"nullValue": "null",
"numberFormat": undefined,
"order": 100001,
"title": "name",
"type": "string",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": "DD/MM/YYYY HH:mm",
"description": "",
"displayAs": "string",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "created_at",
"nullValue": "null",
"numberFormat": undefined,
"order": 100002,
"title": "created_at",
"type": "datetime",
"visible": true,
},
],
}
`;
exports[`Visualizations -> Details -> Editor -> Columns Settings Changes column title 1`] = `
Object {
"columns": Array [
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "number",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "id",
"nullValue": "null",
"numberFormat": "0,0",
"order": 100000,
"title": "id",
"type": "integer",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "string",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "name",
"nullValue": "null",
"numberFormat": undefined,
"order": 100001,
"title": "Full Name",
"type": "string",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": "DD/MM/YYYY HH:mm",
"description": "",
"displayAs": "datetime",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "created_at",
"nullValue": "null",
"numberFormat": undefined,
"order": 100002,
"title": "created_at",
"type": "datetime",
"visible": true,
},
],
}
`;
exports[`Visualizations -> Details -> Editor -> Columns Settings Hides multiple columns 1`] = `
Object {
"columns": Array [
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "number",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "id",
"nullValue": "null",
"numberFormat": "0,0",
"order": 100000,
"title": "id",
"type": "integer",
"visible": false,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "string",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "name",
"nullValue": "null",
"numberFormat": undefined,
"order": 100001,
"title": "name",
"type": "string",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": "DD/MM/YYYY HH:mm",
"description": "",
"displayAs": "datetime",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "created_at",
"nullValue": "null",
"numberFormat": undefined,
"order": 100002,
"title": "created_at",
"type": "datetime",
"visible": true,
},
],
}
`;
exports[`Visualizations -> Details -> Editor -> Columns Settings Toggles column visibility 1`] = `
Object {
"columns": Array [
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "number",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "id",
"nullValue": "null",
"numberFormat": "0,0",
"order": 100000,
"title": "id",
"type": "integer",
"visible": false,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": undefined,
"description": "",
"displayAs": "string",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "name",
"nullValue": "null",
"numberFormat": undefined,
"order": 100001,
"title": "name",
"type": "string",
"visible": true,
},
Object {
"alignContent": "left",
"allowHTML": false,
"booleanValues": Array [
"false",
"true",
],
"dateTimeFormat": "DD/MM/YYYY HH:mm",
"description": "",
"displayAs": "datetime",
"highlightLinks": false,
"imageHeight": "",
"imageTitleTemplate": "{{ @ }}",
"imageUrlTemplate": "{{ @ }}",
"imageWidth": "",
"linkOpenInNewTab": true,
"linkTextTemplate": "{{ @ }}",
"linkTitleTemplate": "{{ @ }}",
"linkUrlTemplate": "{{ @ }}",
"name": "created_at",
"nullValue": "null",
"numberFormat": undefined,
"order": 100002,
"title": "created_at",
"type": "datetime",
"visible": true,
},
],
}
`;

View File

@@ -0,0 +1,33 @@
.details-visualization-editor-columns {
.ant-collapse {
background: transparent;
}
.ant-collapse-item {
background: #ffffff;
.drag-handle {
height: 20px;
margin-left: -16px;
padding: 0 16px;
}
}
.details-editor-columns-dragged-item {
z-index: 1;
}
}
.details-visualization-editor-column {
padding-left: 6px;
.image-dimension-selector {
display: flex;
align-items: center;
.image-dimension-selector-spacer {
padding-left: 5px;
padding-right: 5px;
}
}
}

View File

@@ -0,0 +1,9 @@
import createTabbedEditor from "@/components/visualizations/editor/createTabbedEditor";
import ColumnsSettings from "./ColumnsSettings";
import "./editor.less";
export default createTabbedEditor([
{ key: "Columns", title: "Columns", component: ColumnsSettings },
]);

View File

@@ -0,0 +1,179 @@
import React from "react";
import enzyme from "enzyme";
import moment from "moment";
import Renderer from "./Renderer";
import getOptions from "./getOptions";
function mount(data: any, options: any = {}) {
options = getOptions(options, data);
return enzyme.mount(<Renderer data={data} options={options} />);
}
describe("Visualizations -> Details -> Renderer", () => {
const sampleData = {
columns: [
{ name: "id", type: "integer" },
{ name: "name", type: "string" },
{ name: "created_at", type: "datetime" },
{ name: "active", type: "boolean" },
],
rows: [
{
id: 1,
name: "John Doe",
created_at: moment("2023-01-01T12:00:00Z"),
active: true,
},
{
id: 2,
name: "Jane Smith",
created_at: moment("2023-02-01T12:00:00Z"),
active: false,
},
],
};
test("Renders all columns when no options provided", () => {
const el = mount(sampleData);
// Check that the component renders with expected data
expect(el.text()).toContain("id");
expect(el.text()).toContain("name");
expect(el.text()).toContain("created_at");
expect(el.text()).toContain("active");
expect(el.text()).toContain("1"); // id value
expect(el.text()).toContain("John Doe"); // name value
});
test("Renders only visible columns", () => {
const options = {
columns: [
{ name: "id", visible: true, order: 0 },
{ name: "name", visible: false, order: 1 },
{ name: "created_at", visible: true, order: 2 },
{ name: "active", visible: false, order: 3 },
],
};
const el = mount(sampleData, options);
// Should show id and created_at, but not name and active
expect(el.text()).toContain("id");
expect(el.text()).toContain("created_at");
expect(el.text()).not.toContain("name");
expect(el.text()).not.toContain("active");
});
test("Respects column order", () => {
const options = {
columns: [
{ name: "active", visible: true, order: 0 },
{ name: "name", visible: true, order: 1 },
{ name: "created_at", visible: true, order: 2 },
{ name: "id", visible: true, order: 3 },
],
};
const el = mount(sampleData, options);
// Get all description item labels in order
const labels = el.find('.ant-descriptions-item-label').map(node => node.text());
// Should appear in order: active (0), name (1), created_at (2), id (3)
expect(labels).toEqual(['active', 'name', 'created_at', 'id']);
});
test("Uses custom column titles", () => {
const options = {
columns: [
{ name: "id", visible: true, title: "User ID", order: 0 },
{ name: "name", visible: true, title: "Full Name", order: 1 },
],
};
const el = mount(sampleData, options);
expect(el.text()).toContain("User ID");
expect(el.text()).toContain("Full Name");
});
test("Applies text alignment", () => {
const options = {
columns: [
{ name: "id", visible: true, alignContent: "center", order: 0 },
{ name: "name", visible: true, alignContent: "right", order: 1 },
],
};
const el = mount(sampleData, options);
// Check that alignment styles are applied
const alignedDivs = el.find('div[style]');
expect(alignedDivs.length).toBeGreaterThan(0);
});
test("Shows pagination for multiple rows", () => {
const el = mount(sampleData);
// Check that pagination is present - look for pagination elements
const paginationElements = el.find('[className*="paginator"]');
expect(paginationElements.length).toBeGreaterThan(0);
});
test("Hides pagination for single row", () => {
const singleRowData = {
...sampleData,
rows: [sampleData.rows[0]],
};
const el = mount(singleRowData);
// Check that pagination is not present for single row
const paginationElements = el.find('[className*="paginator"]');
expect(paginationElements.length).toBe(0);
});
test("Handles empty data", () => {
const emptyData = {
columns: [],
rows: [],
};
const el = mount(emptyData);
expect(el.html()).toBeNull();
});
test("Handles null data", () => {
// Suppress PropTypes warning for this test
const originalError = console.error;
console.error = jest.fn();
// Test the component directly with null data instead of using mount helper
const el = enzyme.mount(<Renderer data={null as any} options={{}} />);
expect(el.html()).toBeNull();
// Restore console.error
console.error = originalError;
});
test("Navigates between rows with pagination", () => {
const el = mount(sampleData);
// Check first row is displayed
expect(el.text()).toContain("John Doe");
expect(el.text()).not.toContain("Jane Smith");
// Find and click next button
const nextButton = el.find('button').filterWhere(n => n.text().includes('Next') || n.prop('aria-label') === 'Next Page');
if (nextButton.length > 0) {
nextButton.first().simulate("click");
// Check second row is displayed after state update
el.update();
expect(el.text()).toContain("Jane Smith");
}
});
});

View File

@@ -0,0 +1,82 @@
import React, { useState, useMemo } from "react";
import { map, filter, sortBy } from "lodash";
import { RendererPropTypes } from "@/visualizations/prop-types";
import Descriptions from "antd/lib/descriptions";
import Pagination from "antd/lib/pagination";
import Tooltip from "antd/lib/tooltip";
import ColumnTypes from "../shared/columns";
import "./details.less";
export default function Renderer({ data, options }: any) {
const [page, setPage] = useState(0);
const visibleColumns = useMemo(() => {
if (!options?.columns) return [];
const columns = sortBy(filter(options.columns, "visible"), "order");
return columns.map((column: any) => {
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
const ColumnType = ColumnTypes[column.displayAs] || ColumnTypes.string;
const Component = ColumnType(column);
return {
...column,
Component,
};
});
}, [options?.columns]);
if (!data || !data.rows || data.rows.length === 0) {
return null;
}
const row = data.rows[page];
return (
<div className="details-viz">
<Descriptions size="small" column={1} bordered>
{map(visibleColumns, column => {
const { Component } = column;
return (
<Descriptions.Item
key={column.name}
label={
<React.Fragment>
{column.description && (
<span style={{ paddingRight: 5 }}>
<Tooltip placement="top" title={column.description}>
<i className="fa fa-info-circle" aria-hidden="true"></i>
</Tooltip>
</span>
)}
{column.title || column.name}
</React.Fragment>
}
>
<div style={{ textAlign: column.alignContent || "left" }}>
<Component row={row} />
</div>
</Descriptions.Item>
);
})}
</Descriptions>
{data.rows.length > 1 && (
<div className="paginator-container">
<Pagination
showSizeChanger={false}
current={page + 1}
defaultPageSize={1}
total={data.rows.length}
onChange={p => setPage(p - 1)}
/>
</div>
)}
</div>
);
}
Renderer.propTypes = RendererPropTypes;

View File

@@ -0,0 +1,160 @@
import getOptions from "./getOptions";
describe("Visualizations -> Details -> getOptions", () => {
const sampleData = {
columns: [
{ name: "id", type: "integer" },
{ name: "name", type: "string" },
{ name: "created_at", type: "datetime" },
{ name: "is_active", type: "boolean" },
{ name: "score", type: "float" },
],
};
test("Returns default options when no options provided", () => {
const result = getOptions({}, sampleData);
expect(result.columns).toHaveLength(5);
expect(result.columns[0]).toEqual(
expect.objectContaining({
name: "id",
type: "integer",
displayAs: "number",
visible: true,
alignContent: "left",
title: "id",
description: "",
allowHTML: false,
highlightLinks: false,
})
);
});
test("Preserves existing column options", () => {
const existingOptions = {
columns: [
{
name: "id",
visible: false,
title: "User ID",
alignContent: "center",
},
],
};
const result = getOptions(existingOptions, sampleData);
const idColumn = result.columns.find((col: any) => col.name === "id");
expect(idColumn).toEqual(
expect.objectContaining({
visible: false,
title: "User ID",
alignContent: "center",
})
);
});
test("Sets correct default display types", () => {
const result = getOptions({}, sampleData);
const columnsByName = result.columns.reduce((acc: any, col: any) => {
acc[col.name] = col;
return acc;
}, {} as any);
expect(columnsByName.id.displayAs).toBe("number");
expect(columnsByName.name.displayAs).toBe("string");
expect(columnsByName.created_at.displayAs).toBe("datetime");
expect(columnsByName.is_active.displayAs).toBe("boolean");
expect(columnsByName.score.displayAs).toBe("number");
});
test("Sets correct default alignments", () => {
const result = getOptions({}, sampleData);
const columnsByName = result.columns.reduce((acc: any, col: any) => {
acc[col.name] = col;
return acc;
}, {} as any);
expect(columnsByName.id.alignContent).toBe("left");
expect(columnsByName.name.alignContent).toBe("left");
expect(columnsByName.created_at.alignContent).toBe("left");
expect(columnsByName.is_active.alignContent).toBe("left");
expect(columnsByName.score.alignContent).toBe("left");
});
test("Handles column name type suffixes", () => {
const dataWithTypeSuffixes = {
columns: [
{ name: "user::filter", type: "string" },
{ name: "amount__multiFilter", type: "float" },
{ name: "::date_field", type: "date" },
],
};
const result = getOptions({}, dataWithTypeSuffixes);
expect(result.columns[0].title).toBe("user");
expect(result.columns[1].title).toBe("amount");
expect(result.columns[2].title).toBe("date_field");
});
test("Maintains column order from existing options", () => {
const existingOptions = {
columns: [
{ name: "name", order: 0 },
{ name: "id", order: 1 },
],
};
const result = getOptions(existingOptions, sampleData);
expect(result.columns[0].name).toBe("name");
expect(result.columns[1].name).toBe("id");
});
test("Handles missing columns in existing options", () => {
const existingOptions = {
columns: [
{ name: "id", visible: false },
{ name: "nonexistent", visible: true },
],
};
const result = getOptions(existingOptions, sampleData);
// Should include all data columns
expect(result.columns).toHaveLength(5);
// Should preserve settings for existing columns
const idColumn = result.columns.find((col: any) => col.name === "id");
expect(idColumn.visible).toBe(false);
});
test("Includes default format options", () => {
const result = getOptions({}, sampleData);
const column = result.columns[0];
expect(column).toEqual(
expect.objectContaining({
booleanValues: ["false", "true"],
imageUrlTemplate: "{{ @ }}",
imageTitleTemplate: "{{ @ }}",
imageWidth: "",
imageHeight: "",
linkUrlTemplate: "{{ @ }}",
linkTextTemplate: "{{ @ }}",
linkTitleTemplate: "{{ @ }}",
linkOpenInNewTab: true,
})
);
});
test("Handles empty data", () => {
const emptyData = { columns: [] };
const result = getOptions({}, emptyData);
expect(result.columns).toEqual([]);
});
});

View File

@@ -0,0 +1,17 @@
import _ from "lodash";
import {
getDefaultFormatOptions,
getColumnsOptions,
} from "@/visualizations/shared/columnUtils";
const DEFAULT_OPTIONS = {};
export default function getOptions(options: any, { columns }: any) {
options = { ...DEFAULT_OPTIONS, ...options };
options.columns = _.map(getColumnsOptions(columns, options.columns, { alignContent: "left" }), col => ({
...getDefaultFormatOptions(col),
...col,
}));
return options;
}

View File

@@ -1,15 +1,13 @@
import DetailsRenderer from "./DetailsRenderer";
const DEFAULT_OPTIONS = {};
import getOptions from "./getOptions";
import Renderer from "./Renderer";
import Editor from "./Editor";
export default {
type: "DETAILS",
name: "Details View",
getOptions: (options: any) => ({
...DEFAULT_OPTIONS,
...options,
}),
Renderer: DetailsRenderer,
defaultColumns: 2,
getOptions,
Renderer,
Editor,
defaultColumns: 4,
defaultRows: 2,
};

View File

@@ -9,7 +9,7 @@ export default {
Renderer,
Editor,
defaultColumns: 3,
defaultColumns: 6,
defaultRows: 8,
minColumns: 2,
};

View File

@@ -23,6 +23,6 @@ export default {
Editor,
defaultRows: 10,
defaultColumns: 3,
defaultColumns: 6,
minColumns: 2,
};

Some files were not shown because too many files have changed in this diff Show More