improve tab (and other lexorank entities) sorting, ordering and reordering
This commit is contained in:
@@ -31,47 +31,56 @@ CREATE TABLE toolbar_button_configs (
|
||||
|
||||
CREATE INDEX idx_toolbar_order_key ON toolbar_button_configs(order_key);
|
||||
|
||||
toolbarLeadingOrderKey(:bucket AS INTEGER):
|
||||
-- All four queries are scoped to a visibility partition (`is_visible`) so the
|
||||
-- generated key falls strictly within the targeted section. The Customize
|
||||
-- Toolbar UI renders Enabled and Disabled as two independent reorderable
|
||||
-- lists; without the partition, leading/trailing keys would cross the section
|
||||
-- boundary and surface as buttons "jumping" after a visibility toggle.
|
||||
toolbarLeadingOrderKey(:bucket AS INTEGER, :is_visible AS BOOL):
|
||||
SELECT lexo_rank_previous(
|
||||
:bucket,
|
||||
(
|
||||
SELECT order_key
|
||||
FROM toolbar_button_configs
|
||||
WHERE is_visible = :is_visible
|
||||
ORDER BY order_key
|
||||
LIMIT 1
|
||||
)
|
||||
);
|
||||
|
||||
toolbarTrailingOrderKey(:bucket AS INTEGER):
|
||||
toolbarTrailingOrderKey(:bucket AS INTEGER, :is_visible AS BOOL):
|
||||
SELECT lexo_rank_next(
|
||||
:bucket,
|
||||
(
|
||||
SELECT order_key
|
||||
FROM toolbar_button_configs
|
||||
WHERE is_visible = :is_visible
|
||||
ORDER BY order_key DESC
|
||||
LIMIT 1
|
||||
)
|
||||
);
|
||||
|
||||
toolbarOrderKeyAfterButton(:button_id AS TEXT):
|
||||
toolbarOrderKeyAfterButton(:button_id AS TEXT, :is_visible AS BOOL):
|
||||
WITH ordered_table AS (
|
||||
SELECT
|
||||
button_id,
|
||||
order_key,
|
||||
LEAD(order_key) OVER (ORDER BY order_key) AS next_order_key
|
||||
FROM toolbar_button_configs
|
||||
WHERE is_visible = :is_visible
|
||||
)
|
||||
SELECT lexo_rank_reorder_after(order_key, next_order_key)
|
||||
FROM ordered_table
|
||||
WHERE button_id = :button_id;
|
||||
|
||||
toolbarOrderKeyBeforeButton(:button_id AS TEXT):
|
||||
toolbarOrderKeyBeforeButton(:button_id AS TEXT, :is_visible AS BOOL):
|
||||
WITH ordered_table AS (
|
||||
SELECT
|
||||
button_id,
|
||||
order_key,
|
||||
LAG(order_key) OVER (ORDER BY order_key) AS prev_order_key
|
||||
FROM toolbar_button_configs
|
||||
WHERE is_visible = :is_visible
|
||||
)
|
||||
SELECT lexo_rank_reorder_before(order_key, prev_order_key)
|
||||
FROM ordered_table
|
||||
|
||||
Reference in New Issue
Block a user