Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Separate visualizations into their own package #4838

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions client/app/components/ApplicationArea/Router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import url from "@/services/url";
import ErrorMessage from "./ErrorMessage";

function generateRouteKey() {
return Math.random()
.toString(32)
.substr(2);
return Math.random().toString(32).substr(2);
}

export function stripBase(href) {
Expand Down Expand Up @@ -73,15 +71,15 @@ export default function Router({ routes, onRouteChange }) {

router
.resolve({ pathname })
.then(route => {
.then((route) => {
if (!isAbandoned && currentPathRef.current === pathname) {
setCurrentRoute({ ...route, key: generateRouteKey() });
}
})
.catch(error => {
.catch((error) => {
if (!isAbandoned && currentPathRef.current === pathname) {
setCurrentRoute({
render: currentRoute => <ErrorMessage {...currentRoute.routeParams} />,
render: (currentRoute) => <ErrorMessage {...currentRoute.routeParams} />,
routeParams: { error },
});
}
Expand All @@ -108,7 +106,7 @@ export default function Router({ routes, onRouteChange }) {
}

return (
<ErrorBoundary ref={errorHandlerRef} renderError={error => <ErrorMessage error={error} />}>
<ErrorBoundary ref={errorHandlerRef} renderError={(error) => <ErrorMessage error={error} />}>
{currentRoute.render(currentRoute)}
</ErrorBoundary>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ApiKeySessionWrapper.defaultProps = {
export default function routeWithApiKeySession({ render, getApiKey, ...rest }) {
return {
...rest,
render: currentRoute => (
render: (currentRoute) => (
<ApiKeySessionWrapper apiKey={getApiKey(currentRoute)} currentRoute={currentRoute} renderChildren={render} />
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function UserSessionWrapper({ bodyClass, currentRoute, renderChildren }) {
<React.Fragment>
<ApplicationHeader />
<React.Fragment key={currentRoute.key}>
<ErrorBoundary renderError={error => <ErrorMessage error={error} />}>
<ErrorBoundary renderError={(error) => <ErrorMessage error={error} />}>
<ErrorBoundaryContext.Consumer>
{({ handleError }) =>
renderChildren({ ...currentRoute.routeParams, pageTitle: currentRoute.title, onError: handleError })
Expand All @@ -75,7 +75,7 @@ UserSessionWrapper.defaultProps = {
export default function routeWithUserSession({ render, bodyClass, ...rest }) {
return {
...rest,
render: currentRoute => (
render: (currentRoute) => (
<UserSessionWrapper bodyClass={bodyClass} currentRoute={currentRoute} renderChildren={render} />
),
};
Expand Down
12 changes: 6 additions & 6 deletions client/app/components/Parameters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "./Parameters.less";

function updateUrl(parameters) {
const params = extend({}, location.search);
parameters.forEach(param => {
parameters.forEach((param) => {
extend(params, param.toUrlParams());
});
location.setSearch(params, true);
Expand Down Expand Up @@ -47,7 +47,7 @@ export default class Parameters extends React.Component {
}
}

componentDidUpdate = prevProps => {
componentDidUpdate = (prevProps) => {
const { parameters, disableUrlUpdate } = this.props;
const parametersChanged = prevProps.parameters !== parameters;
const disableUrlUpdateChanged = prevProps.disableUrlUpdate !== disableUrlUpdate;
Expand All @@ -59,7 +59,7 @@ export default class Parameters extends React.Component {
}
};

handleKeyDown = e => {
handleKeyDown = (e) => {
// Cmd/Ctrl/Alt + Enter
if (e.keyCode === 13 && (e.ctrlKey || e.metaKey || e.altKey)) {
e.stopPropagation();
Expand Down Expand Up @@ -94,8 +94,8 @@ export default class Parameters extends React.Component {
applyChanges = () => {
const { onValuesChange, disableUrlUpdate } = this.props;
this.setState(({ parameters }) => {
const parametersWithPendingValues = parameters.filter(p => p.hasPendingValue);
forEach(parameters, p => p.applyPendingValue());
const parametersWithPendingValues = parameters.filter((p) => p.hasPendingValue);
forEach(parameters, (p) => p.applyPendingValue());
if (!disableUrlUpdate) {
updateUrl(parameters);
}
Expand All @@ -106,7 +106,7 @@ export default class Parameters extends React.Component {

showParameterSettings = (parameter, index) => {
const { onParametersEdit } = this.props;
EditParameterSettingsDialog.showModal({ parameter }).onClose(updated => {
EditParameterSettingsDialog.showModal({ parameter }).onClose((updated) => {
this.setState(({ parameters }) => {
const updatedParameter = extend(parameter, updated);
parameters[index] = createParameter(updatedParameter, updatedParameter.parentQueryId);
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/dashboards/TextboxDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function TextboxDialog({ dialog, isNew, ...props }) {
}, 200);

const handleInputChange = useCallback(
event => {
(event) => {
setText(event.target.value);
updatePreview();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function TextboxWidget(props) {
const editTextBox = () => {
TextboxDialog.showModal({
text: widget.text,
}).onClose(newText => {
}).onClose((newText) => {
widget.text = newText;
setText(newText);
return widget.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function visualizationWidgetMenuOptions({ widget, canEditDashboard, onParameters
const widgetQueryResult = widget.getQueryResult();
const isQueryResultEmpty = !widgetQueryResult || !widgetQueryResult.isEmpty || widgetQueryResult.isEmpty();

const downloadLink = fileType => widgetQueryResult.getLink(widget.getQuery().id, fileType);
const downloadName = fileType => widgetQueryResult.getName(widget.getQuery().name, fileType);
const downloadLink = (fileType) => widgetQueryResult.getLink(widget.getQuery().id, fileType);
const downloadName = (fileType) => widgetQueryResult.getName(widget.getQuery().name, fileType);
return compact([
<Menu.Item key="download_csv" disabled={isQueryResultEmpty}>
{!isQueryResultEmpty ? (
Expand Down Expand Up @@ -128,7 +128,7 @@ function VisualizationWidgetFooter({ widget, isPublic, onRefresh, onExpand }) {
const updatedAt = invoke(widgetQueryResult, "getUpdatedAt");
const [refreshClickButtonId, setRefreshClickButtonId] = useState();

const refreshWidget = buttonId => {
const refreshWidget = (buttonId) => {
if (!refreshClickButtonId) {
setRefreshClickButtonId(buttonId);
onRefresh().finally(() => setRefreshClickButtonId(null));
Expand Down Expand Up @@ -227,7 +227,7 @@ class VisualizationWidget extends React.Component {
EditParameterMappingsDialog.showModal({
dashboard,
widget,
}).onClose(valuesChanged => {
}).onClose((valuesChanged) => {
// refresh widget if any parameter value has been updated
if (valuesChanged) {
onRefresh();
Expand Down
14 changes: 7 additions & 7 deletions client/app/components/visualizations/EditVisualizationDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Renderer, Editor } from "@/components/visualizations/visualizationCompo
import "./EditVisualizationDialog.less";

function updateQueryVisualizations(query, visualization) {
const index = findIndex(query.visualizations, v => v.id === visualization.id);
const index = findIndex(query.visualizations, (v) => v.id === visualization.id);
if (index > -1) {
query.visualizations[index] = visualization;
} else {
Expand All @@ -39,11 +39,11 @@ function saveVisualization(visualization) {
}

return Visualization.save(visualization)
.then(result => {
.then((result) => {
notification.success("Visualization saved");
return result;
})
.catch(error => {
.catch((error) => {
notification.error("Visualization could not be saved");
return Promise.reject(error);
});
Expand Down Expand Up @@ -139,7 +139,7 @@ function EditVisualizationDialog({ dialog, visualization, query, queryResult })
options: visualizationOptions,
query_id: query.id,
});
saveVisualization(visualizationData).then(savedVisualization => {
saveVisualization(visualizationData).then((savedVisualization) => {
updateQueryVisualizations(query, savedVisualization);
dialog.close(savedVisualization);
});
Expand All @@ -153,7 +153,7 @@ function EditVisualizationDialog({ dialog, visualization, query, queryResult })
// When editing existing visualization chart type selector is disabled, so add only existing visualization's
// descriptor there (to properly render the component). For new visualizations show all types except of deprecated
const availableVisualizations = isNew
? filter(sortBy(registeredVisualizations, ["name"]), vis => !vis.isDeprecated)
? filter(sortBy(registeredVisualizations, ["name"]), (vis) => !vis.isDeprecated)
: pick(registeredVisualizations, [type]);

return (
Expand All @@ -180,7 +180,7 @@ function EditVisualizationDialog({ dialog, visualization, query, queryResult })
disabled={!isNew}
value={type}
onChange={onTypeChanged}>
{map(availableVisualizations, vis => (
{map(availableVisualizations, (vis) => (
<Select.Option key={vis.type} data-test={"VisualizationType." + vis.type}>
{vis.name}
</Select.Option>
Expand All @@ -194,7 +194,7 @@ function EditVisualizationDialog({ dialog, visualization, query, queryResult })
id="visualization-name"
className="w-100"
value={name}
onChange={event => onNameChanged(event.target.value)}
onChange={(event) => onNameChanged(event.target.value)}
/>
</div>
<div data-test="VisualizationEditor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function combineFilters(localFilters, globalFilters) {
return localFilters;
}

return map(localFilters, localFilter => {
const globalFilter = find(globalFilters, f => f.name === localFilter.name);
return map(localFilters, (localFilter) => {
const globalFilter = find(globalFilters, (f) => f.name === localFilter.name);
if (globalFilter) {
return {
...localFilter,
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function VisualizationRenderer(props) {
}, [props.filters]);

const cleanColumnNames = useMemo(
() => map(data.columns, col => ({ ...col, name: getColumnCleanName(col.friendly_name) })),
() => map(data.columns, (col) => ({ ...col, name: getColumnCleanName(col.friendly_name) })),
[data.columns]
);

Expand Down
6 changes: 3 additions & 3 deletions client/app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ function registerExtensions() {
const modules = context
.keys()
.map(context)
.map(module => module.default);
.map((module) => module.default);

return modules
.filter(isFunction)
.filter(f => f.init)
.map(f => f());
.filter((f) => f.init)
.map((f) => f());
}

requireImages();
Expand Down
12 changes: 6 additions & 6 deletions client/app/pages/queries/VisualizationEmbed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ function VisualizationEmbed({ queryId, visualizationId, apiKey, onError }) {
useEffect(() => {
let isCancelled = false;
Query.get({ id: queryId })
.then(result => {
.then((result) => {
if (!isCancelled) {
setQuery(result);
}
})
.catch(error => onErrorRef.current(error));
.catch((error) => onErrorRef.current(error));

return () => {
isCancelled = true;
Expand All @@ -177,10 +177,10 @@ function VisualizationEmbed({ queryId, visualizationId, apiKey, onError }) {
setRefreshStartedAt(moment());
query
.getQueryResultPromise()
.then(result => {
.then((result) => {
setQueryResults(result);
})
.catch(err => {
.catch((err) => {
setError(err.getError());
})
.finally(() => setRefreshStartedAt(null));
Expand All @@ -203,7 +203,7 @@ function VisualizationEmbed({ queryId, visualizationId, apiKey, onError }) {

const showQueryDescription = has(location.search, "showDescription");
visualizationId = parseInt(visualizationId, 10);
const visualization = find(query.visualizations, vis => vis.id === visualizationId);
const visualization = find(query.visualizations, (vis) => vis.id === visualizationId);

if (!visualization) {
// call error handler async, otherwise it will destroy the component on render phase
Expand Down Expand Up @@ -266,6 +266,6 @@ VisualizationEmbed.defaultProps = {

export default routeWithApiKeySession({
path: "/embed/query/:queryId/visualization/:visualizationId",
render: pageProps => <VisualizationEmbed {...pageProps} />,
render: (pageProps) => <VisualizationEmbed {...pageProps} />,
getApiKey: () => location.search.api_key,
});
16 changes: 8 additions & 8 deletions client/app/services/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ class Widget {

this.queryResult
.toPromise()
.then(result => {
.then((result) => {
this.loading = false;
this.data = result;
return result;
})
.catch(error => {
.catch((error) => {
this.loading = false;
this.data = error;
return error;
Expand All @@ -173,7 +173,7 @@ class Widget {
url = `${url}/${this.id}`;
}

return axios.post(url, data).then(data => {
return axios.post(url, data).then((data) => {
each(data, (v, k) => {
this[k] = v;
});
Expand Down Expand Up @@ -202,8 +202,8 @@ class Widget {

const localTypes = [Widget.MappingType.WidgetLevel, Widget.MappingType.StaticValue];
return map(
filter(params, param => localTypes.indexOf(mappings[param.name].type) >= 0),
param => {
filter(params, (param) => localTypes.indexOf(mappings[param.name].type) >= 0),
(param) => {
const mapping = mappings[param.name];
const result = cloneParameter(param);
result.title = mapping.title || param.title;
Expand All @@ -227,7 +227,7 @@ class Widget {
const existingParams = {};
// textboxes does not have query
const params = this.getQuery() ? this.getQuery().getParametersDefs(false) : [];
each(params, param => {
each(params, (param) => {
existingParams[param.name] = true;
if (!isObject(this.options.parameterMappings[param.name])) {
// "migration" for old dashboards: parameters with `global` flag
Expand All @@ -244,15 +244,15 @@ class Widget {

// Remove mappings for parameters that do not exists anymore
const removedParams = difference(keys(this.options.parameterMappings), keys(existingParams));
each(removedParams, name => {
each(removedParams, (name) => {
delete this.options.parameterMappings[name];
});

return this.options.parameterMappings;
}

getLocalParameters() {
return filter(this.getParametersDefs(), param => !this.isStaticParam(param));
return filter(this.getParametersDefs(), (param) => !this.isStaticParam(param));
}
}

Expand Down