示例#1
0
    def test_default_layout_when_widgets_do_not_have_layout_set(self):
        existing_widgets = DashboardWidget.objects.bulk_create([
            DashboardWidget(
                dashboard=self.dashboard,
                order=i,
                title=f"Existing Widget {i}",
                display_type=DashboardWidgetDisplayTypes.LINE_CHART,
                widget_type=DashboardWidgetTypes.DISCOVER,
                interval="1d",
            ) for i in range(4)
        ])
        DashboardWidgetQuery.objects.bulk_create([
            DashboardWidgetQuery(
                widget=existing_widget,
                fields=["count()"],
                columns=[],
                aggregates=["count()"],
                order=0,
            ) for existing_widget in existing_widgets
        ])

        with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
            self.page.visit_dashboard_detail()

            self.page.wait_until_loaded()
            self.browser.snapshot(
                "dashboards - default layout when widgets do not have layout set"
            )
示例#2
0
    def update_widget_queries(self, widget, data):
        query_ids = [query["id"] for query in data if "id" in query]
        self.remove_missing_queries(widget.id, query_ids)

        existing = DashboardWidgetQuery.objects.filter(widget=widget,
                                                       id__in=query_ids)
        existing_map = {query.id: query for query in existing}

        # Get new ordering start point to avoid constraint errors
        next_order = get_next_query_order(widget.id)

        new_queries = []
        for i, query_data in enumerate(data):
            query_id = query_data.get("id")
            if query_id and query_id in existing_map:
                self.update_widget_query(existing_map[query_id], query_data,
                                         next_order + i)
            if not query_id:
                new_queries.append(
                    DashboardWidgetQuery(
                        widget=widget,
                        fields=query_data["fields"],
                        conditions=query_data["conditions"],
                        name=query_data.get("name", ""),
                        order=next_order + i,
                    ))
        DashboardWidgetQuery.objects.bulk_create(new_queries)
示例#3
0
    def update_widget_queries(self, widget, data):
        query_ids = [query["id"] for query in data if "id" in query]
        self.remove_missing_queries(widget.id, query_ids)

        existing = DashboardWidgetQuery.objects.filter(widget=widget,
                                                       id__in=query_ids)
        existing_map = {query.id: query for query in existing}

        # Get new ordering start point to avoid constraint errors
        next_order = get_next_query_order(widget.id)

        new_queries = []
        for i, query_data in enumerate(data):
            query_id = query_data.get("id")
            if query_id and query_id in existing_map:
                self.update_widget_query(existing_map[query_id], query_data,
                                         next_order + i)
            elif not query_id:
                new_queries.append(
                    DashboardWidgetQuery(
                        widget=widget,
                        fields=query_data["fields"],
                        aggregates=query_data.get("aggregates"),
                        columns=query_data.get("columns"),
                        conditions=query_data["conditions"],
                        name=query_data.get("name", ""),
                        orderby=query_data.get("orderby", ""),
                        order=next_order + i,
                    ))
            else:
                raise serializers.ValidationError(
                    "You cannot use a query not owned by this widget")
        DashboardWidgetQuery.objects.bulk_create(new_queries)
示例#4
0
 def create_widget(self, dashboard, widget_data, order):
     widget = DashboardWidget.objects.create(
         dashboard=dashboard,
         display_type=widget_data["display_type"],
         title=widget_data["title"],
         interval=widget_data.get("interval", "5m"),
         widget_type=widget_data.get("widget_type",
                                     DashboardWidgetTypes.DISCOVER),
         order=order,
         limit=widget_data.get("limit", None),
         detail={"layout": widget_data.get("layout")},
     )
     new_queries = []
     for i, query in enumerate(widget_data.pop("queries")):
         new_queries.append(
             DashboardWidgetQuery(
                 widget=widget,
                 fields=query["fields"],
                 aggregates=query.get("aggregates"),
                 columns=query.get("columns"),
                 conditions=query["conditions"],
                 name=query.get("name", ""),
                 orderby=query.get("orderby", ""),
                 order=i,
             ))
     DashboardWidgetQuery.objects.bulk_create(new_queries)
示例#5
0
    def test_deleting_stacked_widgets_by_context_menu_does_not_trigger_confirm_on_edit_cancel(
        self, ):
        layouts = [
            {
                "x": 0,
                "y": 0,
                "w": 2,
                "h": 2,
                "minH": 2
            },
            {
                "x": 0,
                "y": 2,
                "w": 2,
                "h": 2,
                "minH": 2
            },
        ]
        existing_widgets = DashboardWidget.objects.bulk_create([
            DashboardWidget(
                dashboard=self.dashboard,
                order=i,
                title=f"Existing Widget {i}",
                display_type=DashboardWidgetDisplayTypes.LINE_CHART,
                widget_type=DashboardWidgetTypes.DISCOVER,
                interval="1d",
                detail={"layout": layout},
            ) for i, layout in enumerate(layouts)
        ])
        DashboardWidgetQuery.objects.bulk_create(
            DashboardWidgetQuery(widget=widget,
                                 fields=["count()"],
                                 columns=[],
                                 aggregates=["count()"],
                                 order=0) for widget in existing_widgets)
        with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE +
                          WIDGET_LIBRARY_FEATURE):
            self.page.visit_dashboard_detail()

            dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
            dropdown_trigger.click()

            delete_widget_menu_item = self.browser.element(
                '[data-test-id="delete-widget"]')
            delete_widget_menu_item.click()

            confirm_button = self.browser.element(
                '[data-test-id="confirm-button"]')
            confirm_button.click()

            wait = WebDriverWait(self.browser.driver, 5)
            wait.until(
                EC.presence_of_element_located(
                    (By.XPATH, "//*[contains(text(),'Dashboard updated')]")))

            # Should not trigger confirm dialog
            self.page.enter_edit_state()
            self.page.click_cancel_button()
            wait.until_not(EC.alert_is_present())
示例#6
0
 def create_widget(self, dashboard, widget_data, order):
     widget = DashboardWidget.objects.create(
         dashboard=dashboard,
         display_type=widget_data["display_type"],
         title=widget_data["title"],
         interval=widget_data.get("interval", "5m"),
         order=order,
     )
     new_queries = []
     for i, query in enumerate(widget_data.pop("queries")):
         new_queries.append(
             DashboardWidgetQuery(
                 widget=widget,
                 fields=query["fields"],
                 conditions=query["conditions"],
                 name=query.get("name", ""),
                 order=i,
             ))
     DashboardWidgetQuery.objects.bulk_create(new_queries)
示例#7
0
    def test_changing_number_widget_to_area_updates_widget_height(self, ):
        layouts = [
            (DashboardWidgetDisplayTypes.BIG_NUMBER, {
                "x": 0,
                "y": 0,
                "w": 2,
                "h": 1,
                "minH": 1
            }),
            (DashboardWidgetDisplayTypes.LINE_CHART, {
                "x": 0,
                "y": 1,
                "w": 2,
                "h": 2,
                "minH": 2
            }),
        ]
        existing_widgets = DashboardWidget.objects.bulk_create([
            DashboardWidget(
                dashboard=self.dashboard,
                order=i,
                title=f"Widget {i}",
                display_type=display_type,
                widget_type=DashboardWidgetTypes.DISCOVER,
                interval="1d",
                detail={"layout": layout},
            ) for i, (display_type, layout) in enumerate(layouts)
        ])
        DashboardWidgetQuery.objects.bulk_create(
            DashboardWidgetQuery(widget=widget,
                                 fields=["count()"],
                                 columns=[],
                                 aggregates=["count()"],
                                 order=0) for widget in existing_widgets)
        with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE +
                          WIDGET_LIBRARY_FEATURE):
            self.page.visit_dashboard_detail()

            # Open edit modal for first widget
            dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
            dropdown_trigger.click()
            edit_widget_menu_item = self.browser.element(
                '[data-test-id="edit-widget"]')
            edit_widget_menu_item.click()

            # Change the chart type to the first visualization option - Area chart
            chart_type_input = self.browser.element("#react-select-2-input")
            chart_type_input.send_keys("Area", Keys.ENTER)
            button = self.browser.element('[data-test-id="add-widget"]')
            button.click()

            # No confirm dialog because of shifting lower element
            self.page.enter_edit_state()
            self.page.click_cancel_button()
            wait = WebDriverWait(self.browser.driver, 5)
            wait.until_not(EC.alert_is_present())

            # Try to decrease height to 1 row, should stay at 2 rows
            self.page.enter_edit_state()
            resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
            action = ActionChains(self.browser.driver)
            action.drag_and_drop_by_offset(resizeHandle, 0, -100).perform()

            self.page.save_dashboard()

            self.browser.snapshot(
                "dashboards - change from big number to area chart increases widget to min height"
            )