feat(api): dashboard separated config and default config
This commit is contained in:
parent
c26b77ca89
commit
577185c304
6 changed files with 16 additions and 16 deletions
|
|
@ -18,7 +18,7 @@ CATEGORY_DESCRIPTION = {
|
|||
def get_templates(project_id, user_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
pg_query = cur.mogrify(f"""SELECT category, jsonb_agg(metrics ORDER BY name) AS widgets
|
||||
FROM (SELECT *
|
||||
FROM (SELECT * , default_config AS config
|
||||
FROM metrics LEFT JOIN LATERAL (SELECT COALESCE(jsonb_agg(metric_series.* ORDER BY index), '[]'::jsonb) AS series
|
||||
FROM metric_series
|
||||
WHERE metric_series.metric_id = metrics.metric_id
|
||||
|
|
|
|||
|
|
@ -899,7 +899,7 @@ class EditDashboardSchema(CreateDashboardSchema):
|
|||
|
||||
class UpdateWidgetPayloadSchema(BaseModel):
|
||||
# if you change the config attribute name, please make sure to update it in dashboard2.py
|
||||
config: dict = Field(default={"col": 1, "row": 1, "position": 0})
|
||||
config: dict = Field(default={"col": 2, "row": 2, "position": 0})
|
||||
|
||||
class Config:
|
||||
alias_generator = attribute_to_camel_case
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ ALTER TABLE IF EXISTS metrics
|
|||
DROP CONSTRAINT IF EXISTS unique_key;
|
||||
|
||||
ALTER TABLE IF EXISTS metrics
|
||||
ADD COLUMN IF NOT EXISTS edited_at timestamp NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS edited_at timestamp NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS is_pinned boolean NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS category text NULL DEFAULT 'custom',
|
||||
ADD COLUMN IF NOT EXISTS category text NULL DEFAULT 'custom',
|
||||
ADD COLUMN IF NOT EXISTS is_predefined boolean NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS is_template boolean NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS predefined_key text NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS config jsonb NOT NULL DEFAULT '{"col":2,"row":2,"position":0}'::jsonb,
|
||||
ADD COLUMN IF NOT EXISTS predefined_key text NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS default_config jsonb NOT NULL DEFAULT '{"col": 2,"row": 2,"position": 0}'::jsonb,
|
||||
ALTER COLUMN project_id DROP NOT NULL,
|
||||
ADD CONSTRAINT null_project_id_for_template_only
|
||||
CHECK ( (metrics.category != 'custom') != (metrics.project_id IS NOT NULL) ),
|
||||
|
|
@ -58,7 +58,7 @@ ALTER TYPE metric_view_type ADD VALUE IF NOT EXISTS 'map';
|
|||
ALTER TYPE metric_type ADD VALUE IF NOT EXISTS 'predefined';
|
||||
|
||||
|
||||
INSERT INTO metrics (name, category, config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
INSERT INTO metrics (name, category, default_config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
VALUES ('Captured sessions', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'count_sessions', 'predefined', 'overview'),
|
||||
('Request Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_request_load_time', 'predefined', 'overview'),
|
||||
('Page Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_page_load_time', 'predefined', 'overview'),
|
||||
|
|
|
|||
|
|
@ -811,7 +811,7 @@ $$
|
|||
is_predefined boolean NOT NULL DEFAULT FALSE,
|
||||
is_template boolean NOT NULL DEFAULT FALSE,
|
||||
predefined_key text NULL DEFAULT NULL,
|
||||
config jsonb NOT NULL DEFAULT '{"col": 2,"row": 2,"position": 0}'::jsonb,
|
||||
default_config jsonb NOT NULL DEFAULT '{"col": 2,"row": 2,"position": 0}'::jsonb,
|
||||
CONSTRAINT null_project_id_for_template_only
|
||||
CHECK ( (metrics.category != 'custom') != (metrics.project_id IS NOT NULL) ),
|
||||
CONSTRAINT unique_key UNIQUE (predefined_key)
|
||||
|
|
@ -1257,7 +1257,7 @@ $$
|
|||
$$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
INSERT INTO metrics (name, category, config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
INSERT INTO metrics (name, category, default_config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
VALUES ('Captured sessions', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'count_sessions', 'predefined', 'overview'),
|
||||
('Request Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_request_load_time', 'predefined', 'overview'),
|
||||
('Page Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_page_load_time', 'predefined', 'overview'),
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ ALTER TABLE IF EXISTS metrics
|
|||
DROP CONSTRAINT IF EXISTS unique_key;
|
||||
|
||||
ALTER TABLE IF EXISTS metrics
|
||||
ADD COLUMN IF NOT EXISTS edited_at timestamp NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS edited_at timestamp NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS is_pinned boolean NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS category text NULL DEFAULT 'custom',
|
||||
ADD COLUMN IF NOT EXISTS category text NULL DEFAULT 'custom',
|
||||
ADD COLUMN IF NOT EXISTS is_predefined boolean NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS is_template boolean NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS predefined_key text NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS config jsonb NOT NULL DEFAULT '{"col":2,"row":2,"position":0}'::jsonb,
|
||||
ADD COLUMN IF NOT EXISTS predefined_key text NULL DEFAULT NULL,
|
||||
ADD COLUMN IF NOT EXISTS default_config jsonb NOT NULL DEFAULT '{"col": 2,"row": 2,"position": 0}'::jsonb,
|
||||
ALTER COLUMN project_id DROP NOT NULL,
|
||||
ADD CONSTRAINT null_project_id_for_template_only
|
||||
CHECK ( (metrics.category != 'custom') != (metrics.project_id IS NOT NULL) ),
|
||||
|
|
@ -57,7 +57,7 @@ ALTER TYPE metric_view_type ADD VALUE IF NOT EXISTS 'overview';
|
|||
ALTER TYPE metric_view_type ADD VALUE IF NOT EXISTS 'map';
|
||||
ALTER TYPE metric_type ADD VALUE IF NOT EXISTS 'predefined';
|
||||
|
||||
INSERT INTO metrics (name, category, config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
INSERT INTO metrics (name, category, default_config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
VALUES ('Captured sessions', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'count_sessions', 'predefined', 'overview'),
|
||||
('Request Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_request_load_time', 'predefined', 'overview'),
|
||||
('Page Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_page_load_time', 'predefined', 'overview'),
|
||||
|
|
|
|||
|
|
@ -958,7 +958,7 @@ $$
|
|||
is_predefined boolean NOT NULL DEFAULT FALSE,
|
||||
is_template boolean NOT NULL DEFAULT FALSE,
|
||||
predefined_key text NULL DEFAULT NULL,
|
||||
config jsonb NOT NULL DEFAULT '{"col": 2,"row": 2,"position": 0}'::jsonb,
|
||||
default_config jsonb NOT NULL DEFAULT '{"col": 2,"row": 2,"position": 0}'::jsonb,
|
||||
CONSTRAINT null_project_id_for_template_only
|
||||
CHECK ( (metrics.category != 'custom') != (metrics.project_id IS NOT NULL) ),
|
||||
CONSTRAINT unique_key UNIQUE (predefined_key)
|
||||
|
|
@ -1048,7 +1048,7 @@ $$
|
|||
$$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
INSERT INTO metrics (name, category, config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
INSERT INTO metrics (name, category, default_config, is_predefined, is_template, is_public, predefined_key, metric_type, view_type)
|
||||
VALUES ('Captured sessions', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'count_sessions', 'predefined', 'overview'),
|
||||
('Request Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_request_load_time', 'predefined', 'overview'),
|
||||
('Page Load Time', 'overview', '{"col":1,"row":1,"position":0}', true, true, true, 'avg_page_load_time', 'predefined', 'overview'),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue