Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix/improve-delete-ta…
Browse files Browse the repository at this point in the history
…b-ux
  • Loading branch information
Shifan-Gu committed Apr 25, 2024
2 parents 717eb5a + 061c3e6 commit 7338156
Show file tree
Hide file tree
Showing 44 changed files with 507 additions and 178 deletions.
49 changes: 49 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,52 @@
## [0.1076.4](https://github.com/lightdash/lightdash/compare/0.1076.3...0.1076.4) (2024-04-25)


### Bug Fixes

* fix foreign key constraint error when delete last tab ([#9865](https://github.com/lightdash/lightdash/issues/9865)) ([8265e7d](https://github.com/lightdash/lightdash/commit/8265e7d94205842ca4943923eb5b2d1ba43c547c))

## [0.1076.3](https://github.com/lightdash/lightdash/compare/0.1076.2...0.1076.3) (2024-04-25)


### Bug Fixes

* incorrect default table calc type ([#9888](https://github.com/lightdash/lightdash/issues/9888)) ([3ddaa89](https://github.com/lightdash/lightdash/commit/3ddaa894664cc5992f97c78e5f0685c7b5afde55))

## [0.1076.2](https://github.com/lightdash/lightdash/compare/0.1076.1...0.1076.2) (2024-04-24)


### Bug Fixes

* date ranger picker value not rendered to UTC in sql ([#9860](https://github.com/lightdash/lightdash/issues/9860)) ([3013867](https://github.com/lightdash/lightdash/commit/3013867ddcaaa3c9d80c7b7c23577e2dc307d107))

## [0.1076.1](https://github.com/lightdash/lightdash/compare/0.1076.0...0.1076.1) (2024-04-24)


### Bug Fixes

* add await to scheduler access calculation ([#9881](https://github.com/lightdash/lightdash/issues/9881)) ([a7441e2](https://github.com/lightdash/lightdash/commit/a7441e258e53fc340709bfb0c44335a7cbf52cf9))

# [0.1076.0](https://github.com/lightdash/lightdash/compare/0.1075.6...0.1076.0) (2024-04-24)


### Features

* select table calculation type ([#9862](https://github.com/lightdash/lightdash/issues/9862)) ([fcff1e7](https://github.com/lightdash/lightdash/commit/fcff1e7f4f99a04bf4a5d6f2a0aca8b7ff624efa))

## [0.1075.6](https://github.com/lightdash/lightdash/compare/0.1075.5...0.1075.6) (2024-04-24)


### Bug Fixes

* add NULL as an extra bin ([#9866](https://github.com/lightdash/lightdash/issues/9866)) ([bf852bc](https://github.com/lightdash/lightdash/commit/bf852bc7092c76f83734b181534af2d13f0d0d83))

## [0.1075.5](https://github.com/lightdash/lightdash/compare/0.1075.4...0.1075.5) (2024-04-24)


### Bug Fixes

* fix tabs for create dashboard api ([#9864](https://github.com/lightdash/lightdash/issues/9864)) ([95c3d76](https://github.com/lightdash/lightdash/commit/95c3d768177ce3e6aac233d4a138f2d5d90ff550))

## [0.1075.4](https://github.com/lightdash/lightdash/compare/0.1075.3...0.1075.4) (2024-04-23)


Expand Down
20 changes: 20 additions & 0 deletions examples/api/dashboard.http
@@ -0,0 +1,20 @@
### Login
POST http://localhost:3000/api/v1/login
Content-Type: application/json

{
"email": "demo@lightdash.com",
"password": "demo_password!"
}


#### Create dashboard
POST http://localhost:3000/api/v1/projects/3675b69e-8324-4110-bdca-059031aa8da3/dashboards
Content-Type: application/json

{
"description":"",
"name": "dashboard test",
"spaceUuid": "c219601e-034d-44a3-b0cd-853d7a8bf31f",
"tiles": []
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "lightdash",
"version": "0.1075.4",
"version": "0.1076.4",
"main": "index.js",
"license": "MIT",
"private": true,
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/package.json
@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "0.1075.4",
"version": "0.1076.4",
"main": "dist/index",
"license": "MIT",
"devDependencies": {
Expand Down Expand Up @@ -35,8 +35,8 @@
"@godaddy/terminus": "^4.12.0",
"@langchain/core": "^0.1.51",
"@langchain/openai": "^0.0.23",
"@lightdash/common": "^0.1075.4",
"@lightdash/warehouses": "^0.1075.4",
"@lightdash/common": "^0.1076.4",
"@lightdash/warehouses": "^0.1076.4",
"@octokit/app": "^14.0.2",
"@octokit/auth-app": "^6.0.3",
"@octokit/auth-token": "^4.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/database/entities/savedCharts.ts
Expand Up @@ -9,6 +9,7 @@ import {
MetricFilterRule,
MetricType,
NumberSeparator,
TableCalculationType,
TimeZone,
} from '@lightdash/common';
import { Knex } from 'knex';
Expand Down Expand Up @@ -152,6 +153,7 @@ export type DbSavedChartTableCalculation = {
calculation_raw_sql: string;
saved_queries_version_id: number;
format?: CustomFormat;
type?: TableCalculationType;
};

export type DbSavedChartTableCalculationInsert = Omit<
Expand Down
@@ -0,0 +1,18 @@
import { Knex } from 'knex';

const tableCalculationVersionsTable =
'saved_queries_version_table_calculations';

export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable(tableCalculationVersionsTable, (table) => {
table.string('type');
});
}

export async function down(knex: Knex): Promise<void> {
if (await knex.schema.hasColumn(tableCalculationVersionsTable, 'type')) {
await knex.schema.alterTable(tableCalculationVersionsTable, (table) => {
table.dropColumn('type');
});
}
}
8 changes: 7 additions & 1 deletion packages/backend/src/generated/routes.ts
Expand Up @@ -845,11 +845,17 @@ const models: TsoaRoute.Models = {
additionalProperties: true,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
TableCalculationType: {
dataType: 'refEnum',
enums: ['number', 'string', 'date', 'timestamp', 'boolean'],
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
TableCalculation: {
dataType: 'refAlias',
type: {
dataType: 'nestedObjectLiteral',
nestedProperties: {
type: { ref: 'TableCalculationType' },
format: { ref: 'CustomFormat' },
sql: { dataType: 'string', required: true },
displayName: { dataType: 'string', required: true },
Expand Down Expand Up @@ -2906,7 +2912,7 @@ const models: TsoaRoute.Models = {
dataType: 'nestedObjectLiteral',
nestedProperties: {
dbtVersion: { ref: 'SupportedDbtVersions', required: true },
copiedFromProjectUuid: { dataType: 'string' },
upstreamProjectUuid: { dataType: 'string' },
pinnedListUuid: { dataType: 'string' },
warehouseConnection: { ref: 'WarehouseCredentials' },
dbtConnection: { ref: 'DbtProjectConfig', required: true },
Expand Down
11 changes: 9 additions & 2 deletions packages/backend/src/generated/swagger.json
Expand Up @@ -832,8 +832,15 @@
"type": "object",
"additionalProperties": true
},
"TableCalculationType": {
"enum": ["number", "string", "date", "timestamp", "boolean"],
"type": "string"
},
"TableCalculation": {
"properties": {
"type": {
"$ref": "#/components/schemas/TableCalculationType"
},
"format": {
"$ref": "#/components/schemas/CustomFormat"
},
Expand Down Expand Up @@ -3223,7 +3230,7 @@
"dbtVersion": {
"$ref": "#/components/schemas/SupportedDbtVersions"
},
"copiedFromProjectUuid": {
"upstreamProjectUuid": {
"type": "string"
},
"pinnedListUuid": {
Expand Down Expand Up @@ -6758,7 +6765,7 @@
},
"info": {
"title": "Lightdash API",
"version": "0.1074.2",
"version": "0.1076.2",
"description": "Open API documentation for all public Lightdash API endpoints. # Authentication Before you get started, you might need to create a Personal Access Token to authenticate via the API. You can create a token by following this guide: https://docs.lightdash.com/references/personal_tokens\n",
"license": {
"name": "MIT"
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/models/DashboardModel/DashboardModel.ts
Expand Up @@ -736,6 +736,7 @@ export class DashboardModel {

await DashboardModel.createVersion(trx, newDashboard.dashboard_id, {
...dashboard,
tabs: dashboard.tabs || [],
updatedByUser: user,
});

Expand Down Expand Up @@ -821,6 +822,7 @@ export class DashboardModel {
await this.database.transaction(async (trx) => {
await DashboardModel.createVersion(trx, dashboard.dashboard_id, {
...version,
tabs: version.tabs || [],
updatedByUser: user,
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/models/ProjectModel/ProjectModel.ts
Expand Up @@ -265,10 +265,10 @@ export class ProjectModel {
}

// Make sure the project to copy exists and is owned by the same organization
const copiedProjects = data.copiedFromProjectUuid
const copiedProjects = data.upstreamProjectUuid
? await trx('projects')
.where('organization_id', orgs[0].organization_id)
.andWhere('project_uuid', data.copiedFromProjectUuid)
.andWhere('project_uuid', data.upstreamProjectUuid)
: [];
const [project] = await trx('projects')
.insert({
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/models/SavedChartModel.ts
Expand Up @@ -207,6 +207,7 @@ const createSavedChartVersion = async (
order: tableConfig.columnOrder.findIndex(
(column) => column === tableCalculation.name,
),
type: tableCalculation.type,
}),
);
});
Expand Down Expand Up @@ -685,6 +686,7 @@ export class SavedChartModel {
'calculation_raw_sql',
'order',
'format',
'type',
])
.where('saved_queries_version_id', savedQueriesVersionId);

Expand Down Expand Up @@ -819,6 +821,7 @@ export class SavedChartModel {
displayName: tableCalculation.display_name,
sql: tableCalculation.calculation_raw_sql,
format: tableCalculation.format || undefined,
type: tableCalculation.type || undefined,
}),
),
additionalMetrics,
Expand Down
21 changes: 14 additions & 7 deletions packages/backend/src/queryBuilder.test.ts
Expand Up @@ -543,7 +543,8 @@ describe('with custom dimensions', () => {
joins: ['age_range_cte'],
selects: [
`CASE
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 IS NULL THEN NULL
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 1 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 2 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 1, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 2)
ELSE CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 2, ' - ', age_range_cte.max_id)
END
Expand Down Expand Up @@ -613,7 +614,8 @@ ELSE CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 2, ' - ', age_range
SELECT
"table1".dim1 AS \`table1_dim1\`,
CASE
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 IS NULL THEN NULL
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 1 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 2 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 1, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 2)
ELSE CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 2, ' - ', age_range_cte.max_id)
END
Expand Down Expand Up @@ -700,7 +702,8 @@ metrics AS (
SELECT
"table1".dim1 AS \`table1_dim1\`,
CASE
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 IS NULL THEN NULL
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 1 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 2 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 1, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 2)
ELSE CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 2, ' - ', age_range_cte.max_id)
END
Expand Down Expand Up @@ -745,13 +748,15 @@ LIMIT 10`);
joins: ['age_range_cte'],
selects: [
`CASE
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 IS NULL THEN NULL
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 1 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 2 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 1, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 2)
ELSE CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 2, ' - ', age_range_cte.max_id)
END
AS \`age_range\``,
`CASE
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN 0
WHEN "table1".dim1 IS NULL THEN 3
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN 0
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 1 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 2 THEN 1
ELSE 2
END
Expand Down Expand Up @@ -784,13 +789,15 @@ ELSE 2
SELECT
"table1".dim1 AS \`table1_dim1\`,
CASE
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 IS NULL THEN NULL
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 0, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 1)
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 1 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 2 THEN CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 1, ' - ', age_range_cte.min_id + age_range_cte.bin_width * 2)
ELSE CONCAT(age_range_cte.min_id + age_range_cte.bin_width * 2, ' - ', age_range_cte.max_id)
END
AS \`age_range\`,
CASE
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN 0
WHEN "table1".dim1 IS NULL THEN 3
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 0 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 1 THEN 0
WHEN "table1".dim1 >= age_range_cte.min_id + age_range_cte.bin_width * 1 AND "table1".dim1 < age_range_cte.min_id + age_range_cte.bin_width * 2 THEN 1
ELSE 2
END
Expand Down

0 comments on commit 7338156

Please sign in to comment.