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 Migrate Query page to React: Query View #4456

Closed
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
48 changes: 25 additions & 23 deletions client/app/pages/queries/QueryView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@ import useVisualizationTabHandler from "./utils/useVisualizationTabHandler";
function QueryView(props) {
const [query, setQuery] = useState(props.query);
const [selectedTab, setSelectedTab] = useVisualizationTabHandler(query.visualizations);
const currentVisualization = useMemo(() => find(query.visualizations, { id: selectedTab }), [query.visualizations, selectedTab])
const currentVisualization = useMemo(() => find(query.visualizations, { id: selectedTab }), [
query.visualizations,
selectedTab,
]);
const parameters = useMemo(() => query.getParametersDefs(), [query]);
const [dataSource, setDataSource] = useState();
const queryResult = useMemo(() => query.getQueryResult(), [query]);
const queryResultData = useQueryResult(queryResult);

const saveDescription = useCallback(
(description) => {
description => {
recordEvent("edit_description", "query", query.id);
updateQuery(query, { description }).then(setQuery);
},
[query],
[query]
);

const openVisualizationEditor = useCallback(
() => {
EditVisualizationDialog.showModal({
query,
visualization: currentVisualization,
queryResult,
}).result.then(visualization => {
setSelectedTab(visualization.id);
// TODO: Properly update state
});
},
[currentVisualization, query, queryResult, setSelectedTab],
);
const openVisualizationEditor = useCallback(() => {
EditVisualizationDialog.showModal({
query,
visualization: currentVisualization,
queryResult,
}).result.then(visualization => {
setSelectedTab(visualization.id);
// TODO: Properly update state
});
}, [currentVisualization, query, queryResult, setSelectedTab]);

useEffect(() => {
document.title = query.name;
Expand Down Expand Up @@ -103,7 +103,8 @@ function QueryView(props) {
)}
<span className="flex-fill" />
<div className="query-property">
<i className="zmdi zmdi-refresh m-r-5" />Refresh Schedule
<i className="zmdi zmdi-refresh m-r-5" />
Refresh Schedule
<a className="clickable m-l-5">
<SchedulePhrase schedule={query.schedule} isNew={false} />
</a>
Expand All @@ -128,11 +129,13 @@ function QueryView(props) {
queryResult={queryResult}
queryExecuting={false} /* TODO: Replace with executing state */
showEmbedDialog={() => EmbedQueryDialog.showEmbedDialog({ query, visualization: currentVisualization })}
openAddToDashboardForm={() => AddToDashboardDialog.showModal({
visualization: currentVisualization,
})}
openAddToDashboardForm={() =>
AddToDashboardDialog.showModal({
visualization: currentVisualization,
})
}
/>
{(queryResult && queryResultData) && (
{queryResult && queryResultData && (
<>
<span className="m-l-10">
<strong>{queryResultData.rows.length}</strong> {pluralize("row", queryResultData.rows.length)}
Expand All @@ -146,8 +149,7 @@ function QueryView(props) {
<span className="flex-fill" />
{queryResult && (
<span className="m-r-10 hidden-xs">
Updated{" "}
<TimeAgo date={queryResult.query_result.retrieved_at} />
Updated <TimeAgo date={queryResult.query_result.retrieved_at} />
</span>
)}
<Button type="primary">Execute</Button>
Expand Down