-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate query source to React: Set of updates (#4457)
- Loading branch information
1 parent
f165631
commit 192ad22
Showing
13 changed files
with
160 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { clone, extend } from "lodash"; | ||
import React, { useMemo, useState, useCallback } from "react"; | ||
import PropTypes from "prop-types"; | ||
import Modal from "antd/lib/modal"; | ||
import Input from "antd/lib/input"; | ||
import Button from "antd/lib/button"; | ||
import { wrap as wrapDialog, DialogPropType } from "@/components/DialogWrapper"; | ||
import CodeBlock from "@/components/CodeBlock"; | ||
import { $http } from "@/services/ng"; | ||
import { clientConfig } from "@/services/auth"; | ||
import notification from "@/services/notification"; | ||
|
||
import "./index.less"; | ||
|
||
function ApiKeyDialog({ dialog, ...props }) { | ||
const [query, setQuery] = useState(props.query); | ||
const [updatingApiKey, setUpdatingApiKey] = useState(false); | ||
|
||
const regenerateQueryApiKey = useCallback(() => { | ||
setUpdatingApiKey(true); | ||
$http | ||
.post(`api/queries/${query.id}/regenerate_api_key`) | ||
.success(data => { | ||
setUpdatingApiKey(false); | ||
setQuery(extend(clone(query), { api_key: data.api_key })); | ||
}) | ||
.error(() => { | ||
setUpdatingApiKey(false); | ||
notification.error("Failed to update API key"); | ||
}); | ||
}, [query]); | ||
|
||
const { csvUrl, jsonUrl } = useMemo( | ||
() => ({ | ||
csvUrl: `${clientConfig.basePath}api/queries/${query.id}/results.csv?api_key=${query.api_key}`, | ||
jsonUrl: `${clientConfig.basePath}api/queries/${query.id}/results.json?api_key=${query.api_key}`, | ||
}), | ||
[query.id, query.api_key] | ||
); | ||
|
||
return ( | ||
<Modal {...dialog.props} width={600} footer={<Button onClick={() => dialog.close(query)}>Close</Button>}> | ||
<div className="query-api-key-dialog-wrapper"> | ||
<h5>API Key</h5> | ||
<div className="m-b-20"> | ||
<Input.Group compact> | ||
<Input readOnly value={query.api_key} /> | ||
{query.can_edit && ( | ||
<Button disabled={updatingApiKey} loading={updatingApiKey} onClick={regenerateQueryApiKey}> | ||
Regenerate | ||
</Button> | ||
)} | ||
</Input.Group> | ||
</div> | ||
|
||
<h5>Example API Calls:</h5> | ||
<div className="m-b-10"> | ||
<label>Results in CSV format:</label> | ||
<CodeBlock copyable>{csvUrl}</CodeBlock> | ||
</div> | ||
<div> | ||
<label>Results in JSON format:</label> | ||
<CodeBlock copyable>{jsonUrl}</CodeBlock> | ||
</div> | ||
</div> | ||
</Modal> | ||
); | ||
} | ||
|
||
ApiKeyDialog.propTypes = { | ||
dialog: DialogPropType.isRequired, | ||
query: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
api_key: PropTypes.string, | ||
can_edit: PropTypes.bool, | ||
}).isRequired, | ||
}; | ||
|
||
export default wrapDialog(ApiKeyDialog); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.query-api-key-dialog-wrapper { | ||
.ant-input-group.ant-input-group-compact { | ||
display: flex; | ||
flex-wrap: nowrap; | ||
|
||
.ant-input { | ||
flex-grow: 1; | ||
flex-shrink: 1; | ||
} | ||
|
||
.ant-btn { | ||
flex-grow: 0; | ||
flex-shrink: 0; | ||
height: auto; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
import saveQuery from "./saveQuery"; | ||
import updateQuery from "./updateQuery"; | ||
import archiveQuery from "./archiveQuery"; | ||
import duplicateQuery from "./duplicateQuery"; | ||
import { clientConfig } from "@/services/auth"; | ||
import recordEvent from "@/services/recordEvent"; | ||
|
||
export { saveQuery, archiveQuery, duplicateQuery }; | ||
function publishQuery(query) { | ||
recordEvent("toggle_published", "query", query.id); | ||
return updateQuery(query, { is_draft: false }); | ||
} | ||
|
||
function unpublishQuery(query) { | ||
recordEvent("toggle_published", "query", query.id); | ||
return updateQuery(query, { is_draft: true }); | ||
} | ||
|
||
function renameQuery(query, name) { | ||
recordEvent("edit_name", "query", query.id); | ||
const changes = { name }; | ||
const options = {}; | ||
|
||
if (query.is_draft && clientConfig.autoPublishNamedQueries && query.name !== "New Query") { | ||
changes.is_draft = false; | ||
options.successMessage = "Query saved and published"; | ||
} | ||
|
||
return updateQuery(query, changes, options); | ||
} | ||
|
||
export { updateQuery, archiveQuery, duplicateQuery, publishQuery, unpublishQuery, renameQuery }; |
File renamed without changes.
Oops, something went wrong.