Skip to content

Commit

Permalink
Merge pull request #3 from getredash/master
Browse files Browse the repository at this point in the history
upstream update
  • Loading branch information
lotreal authored Jan 13, 2021
2 parents 47374db + 7d33af4 commit 340ef74
Show file tree
Hide file tree
Showing 47 changed files with 900 additions and 287 deletions.
2 changes: 0 additions & 2 deletions client/app/components/ParameterValueInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class ParameterValueInput extends React.Component {
<SelectWithVirtualScroll
className={this.props.className}
mode={parameter.multiValuesOptions ? "multiple" : "default"}
optionFilterProp="children"
value={normalize(value)}
onChange={this.onSelect}
options={map(enumOptionsArray, opt => ({ label: String(opt), value: opt }))}
Expand All @@ -120,7 +119,6 @@ class ParameterValueInput extends React.Component {
<QueryBasedParameterInput
className={this.props.className}
mode={parameter.multiValuesOptions ? "multiple" : "default"}
optionFilterProp="children"
parameter={parameter}
value={value}
queryId={queryId}
Expand Down
21 changes: 15 additions & 6 deletions client/app/components/Parameters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ export default class Parameters extends React.Component {
static propTypes = {
parameters: PropTypes.arrayOf(PropTypes.instanceOf(Parameter)),
editable: PropTypes.bool,
sortable: PropTypes.bool,
disableUrlUpdate: PropTypes.bool,
onValuesChange: PropTypes.func,
onPendingValuesChange: PropTypes.func,
onParametersEdit: PropTypes.func,
appendSortableToParent: PropTypes.bool,
};

static defaultProps = {
parameters: [],
editable: false,
sortable: false,
disableUrlUpdate: false,
onValuesChange: () => {},
onPendingValuesChange: () => {},
onParametersEdit: () => {},
appendSortableToParent: true,
};

constructor(props) {
Expand Down Expand Up @@ -85,7 +89,7 @@ export default class Parameters extends React.Component {
if (oldIndex !== newIndex) {
this.setState(({ parameters }) => {
parameters.splice(newIndex, 0, parameters.splice(oldIndex, 1)[0]);
onParametersEdit();
onParametersEdit(parameters);
return { parameters };
});
}
Expand All @@ -110,7 +114,7 @@ export default class Parameters extends React.Component {
this.setState(({ parameters }) => {
const updatedParameter = extend(parameter, updated);
parameters[index] = createParameter(updatedParameter, updatedParameter.parentQueryId);
onParametersEdit();
onParametersEdit(parameters);
return { parameters };
});
});
Expand Down Expand Up @@ -146,15 +150,17 @@ export default class Parameters extends React.Component {

render() {
const { parameters } = this.state;
const { editable } = this.props;
const { sortable, appendSortableToParent } = this.props;
const dirtyParamCount = size(filter(parameters, "hasPendingValue"));

return (
<SortableContainer
disabled={!editable}
disabled={!sortable}
axis="xy"
useDragHandle
lockToContainerEdges
helperClass="parameter-dragged"
helperContainer={containerEl => (appendSortableToParent ? containerEl : document.body)}
updateBeforeSortStart={this.onBeforeSortStart}
onSortEnd={this.moveParameter}
containerProps={{
Expand All @@ -163,8 +169,11 @@ export default class Parameters extends React.Component {
}}>
{parameters.map((param, index) => (
<SortableElement key={param.name} index={index}>
<div className="parameter-block" data-editable={editable || null}>
{editable && <DragHandle data-test={`DragHandle-${param.name}`} />}
<div
className="parameter-block"
data-editable={sortable || null}
data-test={`ParameterBlock-${param.name}`}>
{sortable && <DragHandle data-test={`DragHandle-${param.name}`} />}
{this.renderParameter(param, index)}
</div>
</SortableElement>
Expand Down
2 changes: 2 additions & 0 deletions client/app/components/Parameters.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

&.parameter-dragged {
z-index: 2;
margin: 4px 0 0 4px;
padding: 3px 6px 6px;
box-shadow: 0 4px 9px -3px rgba(102, 136, 153, 0.15);
}
}
Expand Down
1 change: 0 additions & 1 deletion client/app/components/QueryBasedParameterInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export default class QueryBasedParameterInput extends React.Component {
value={this.state.value}
onChange={onSelect}
options={map(options, ({ value, name }) => ({ label: String(name), value }))}
optionFilterProp="children"
showSearch
showArrow
notFoundContent={isEmpty(options) ? "No options available" : null}
Expand Down
11 changes: 9 additions & 2 deletions client/app/components/SelectWithVirtualScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface VirtualScrollLabeledValue extends LabeledValue {
label: string;
}

interface VirtualScrollSelectProps extends SelectProps<string> {
interface VirtualScrollSelectProps extends Omit<SelectProps<string>, "optionFilterProp" | "children"> {
options: Array<VirtualScrollLabeledValue>;
}
function SelectWithVirtualScroll({ options, ...props }: VirtualScrollSelectProps): JSX.Element {
Expand All @@ -32,7 +32,14 @@ function SelectWithVirtualScroll({ options, ...props }: VirtualScrollSelectProps
return false;
}, [options]);

return <AntdSelect<string> dropdownMatchSelectWidth={dropdownMatchSelectWidth} options={options} {...props} />;
return (
<AntdSelect<string>
dropdownMatchSelectWidth={dropdownMatchSelectWidth}
options={options}
optionFilterProp="label" // as this component expects "options" prop
{...props}
/>
);
}

export default SelectWithVirtualScroll;
10 changes: 5 additions & 5 deletions client/app/components/admin/RQStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ CounterCard.defaultProps = {

const queryJobsColumns = [
{ title: "Queue", dataIndex: "origin" },
{ title: "Query ID", dataIndex: "meta.query_id" },
{ title: "Org ID", dataIndex: "meta.org_id" },
{ title: "Data Source ID", dataIndex: "meta.data_source_id" },
{ title: "User ID", dataIndex: "meta.user_id" },
Columns.custom(scheduled => scheduled.toString(), { title: "Scheduled", dataIndex: "meta.scheduled" }),
{ title: "Query ID", dataIndex: ["meta", "query_id"] },
{ title: "Org ID", dataIndex: ["meta", "org_id"] },
{ title: "Data Source ID", dataIndex: ["meta", "data_source_id"] },
{ title: "User ID", dataIndex: ["meta", "user_id"] },
Columns.custom(scheduled => scheduled.toString(), { title: "Scheduled", dataIndex: ["meta", "scheduled"] }),
Columns.timeAgo({ title: "Start Time", dataIndex: "started_at" }),
Columns.timeAgo({ title: "Enqueue Time", dataIndex: "enqueued_at" }),
];
Expand Down
15 changes: 10 additions & 5 deletions client/app/components/dashboards/DashboardGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const DashboardWidget = React.memo(
onRefreshWidget,
onRemoveWidget,
onParameterMappingsChange,
isEditing,
canEdit,
isPublic,
isLoading,
Expand All @@ -57,6 +58,7 @@ const DashboardWidget = React.memo(
widget={widget}
dashboard={dashboard}
filters={filters}
isEditing={isEditing}
canEdit={canEdit}
isPublic={isPublic}
isLoading={isLoading}
Expand All @@ -77,7 +79,8 @@ const DashboardWidget = React.memo(
prevProps.canEdit === nextProps.canEdit &&
prevProps.isPublic === nextProps.isPublic &&
prevProps.isLoading === nextProps.isLoading &&
prevProps.filters === nextProps.filters
prevProps.filters === nextProps.filters &&
prevProps.isEditing === nextProps.isEditing
);

class DashboardGrid extends React.Component {
Expand Down Expand Up @@ -223,7 +226,6 @@ class DashboardGrid extends React.Component {
});

render() {
const className = cx("dashboard-wrapper", this.props.isEditing ? "editing-mode" : "preview-mode");
const {
onLoadWidget,
onRefreshWidget,
Expand All @@ -232,19 +234,21 @@ class DashboardGrid extends React.Component {
filters,
dashboard,
isPublic,
isEditing,
widgets,
} = this.props;
const className = cx("dashboard-wrapper", isEditing ? "editing-mode" : "preview-mode");

return (
<div className={className}>
<ResponsiveGridLayout
draggableCancel="input"
draggableCancel="input,.sortable-container"
className={cx("layout", { "disable-animations": this.state.disableAnimations })}
cols={{ [MULTI]: cfg.columns, [SINGLE]: 1 }}
rowHeight={cfg.rowHeight - cfg.margins}
margin={[cfg.margins, cfg.margins]}
isDraggable={this.props.isEditing}
isResizable={this.props.isEditing}
isDraggable={isEditing}
isResizable={isEditing}
onResizeStart={this.autoHeightCtrl.stop}
onResizeStop={this.onWidgetResize}
layouts={this.state.layouts}
Expand All @@ -266,6 +270,7 @@ class DashboardGrid extends React.Component {
filters={filters}
isPublic={isPublic}
isLoading={widget.loading}
isEditing={isEditing}
canEdit={dashboard.canEdit()}
onLoadWidget={onLoadWidget}
onRefreshWidget={onRefreshWidget}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import { compact, isEmpty, invoke } from "lodash";
import { compact, isEmpty, invoke, map } from "lodash";
import { markdown } from "markdown";
import cx from "classnames";
import Menu from "antd/lib/menu";
Expand Down Expand Up @@ -84,7 +84,14 @@ function RefreshIndicator({ refreshStartedAt }) {
RefreshIndicator.propTypes = { refreshStartedAt: Moment };
RefreshIndicator.defaultProps = { refreshStartedAt: null };

function VisualizationWidgetHeader({ widget, refreshStartedAt, parameters, onParametersUpdate }) {
function VisualizationWidgetHeader({
widget,
refreshStartedAt,
parameters,
isEditing,
onParametersUpdate,
onParametersEdit,
}) {
const canViewQuery = currentUser.hasPermission("view_query");

return (
Expand All @@ -104,7 +111,13 @@ function VisualizationWidgetHeader({ widget, refreshStartedAt, parameters, onPar
</div>
{!isEmpty(parameters) && (
<div className="m-b-10">
<Parameters parameters={parameters} onValuesChange={onParametersUpdate} />
<Parameters
parameters={parameters}
sortable={isEditing}
appendSortableToParent={false}
onValuesChange={onParametersUpdate}
onParametersEdit={onParametersEdit}
/>
</div>
)}
</>
Expand All @@ -115,12 +128,16 @@ VisualizationWidgetHeader.propTypes = {
widget: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
refreshStartedAt: Moment,
parameters: PropTypes.arrayOf(PropTypes.object),
isEditing: PropTypes.bool,
onParametersUpdate: PropTypes.func,
onParametersEdit: PropTypes.func,
};

VisualizationWidgetHeader.defaultProps = {
refreshStartedAt: null,
onParametersUpdate: () => {},
onParametersEdit: () => {},
isEditing: false,
parameters: [],
};

Expand Down Expand Up @@ -190,6 +207,7 @@ class VisualizationWidget extends React.Component {
isPublic: PropTypes.bool,
isLoading: PropTypes.bool,
canEdit: PropTypes.bool,
isEditing: PropTypes.bool,
onLoad: PropTypes.func,
onRefresh: PropTypes.func,
onDelete: PropTypes.func,
Expand All @@ -201,6 +219,7 @@ class VisualizationWidget extends React.Component {
isPublic: false,
isLoading: false,
canEdit: false,
isEditing: false,
onLoad: () => {},
onRefresh: () => {},
onDelete: () => {},
Expand Down Expand Up @@ -284,10 +303,15 @@ class VisualizationWidget extends React.Component {
}

render() {
const { widget, isLoading, isPublic, canEdit, onRefresh } = this.props;
const { widget, isLoading, isPublic, canEdit, isEditing, onRefresh } = this.props;
const { localParameters } = this.state;
const widgetQueryResult = widget.getQueryResult();
const isRefreshing = isLoading && !!(widgetQueryResult && widgetQueryResult.getStatus());
const onParametersEdit = parameters => {
const paramOrder = map(parameters, "name");
widget.options.paramOrder = paramOrder;
widget.save("options", { paramOrder });
};

return (
<Widget
Expand All @@ -303,7 +327,9 @@ class VisualizationWidget extends React.Component {
widget={widget}
refreshStartedAt={isRefreshing ? widget.refreshStartedAt : null}
parameters={localParameters}
isEditing={isEditing}
onParametersUpdate={onRefresh}
onParametersEdit={onParametersEdit}
/>
}
footer={
Expand Down
1 change: 1 addition & 0 deletions client/app/lib/useQueryResultData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function getQueryResultData(queryResult, queryResultStatus = null) {
filters: invoke(queryResult, "getFilters") || [],
updatedAt: invoke(queryResult, "getUpdatedAt") || null,
retrievedAt: get(queryResult, "query_result.retrieved_at", null),
truncated: invoke(queryResult, "getTruncated") || null,
log: invoke(queryResult, "getLog") || [],
error: invoke(queryResult, "getError") || null,
runtime: invoke(queryResult, "getRuntime") || null,
Expand Down
Loading

0 comments on commit 340ef74

Please sign in to comment.