-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add JSON result type component (#260)
If a column is payload or contains _payload it will be assumed it has JSON data in it, then we will show the truncated JSON in the result column with a button to show the full-screen formatted JSON using our full-screen code viewer. We also do the same if the column is the `json` postgres data type.
- Loading branch information
1 parent
3e5f679
commit 5776aa7
Showing
8 changed files
with
109 additions
and
1 deletion.
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
9 changes: 9 additions & 0 deletions
9
assets/javascripts/discourse/components/result-types/json.hbs
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,9 @@ | ||
<div class="result-json"> | ||
<div class="result-json-value">{{@ctx.value}}</div> | ||
<DButton | ||
class="result-json-button" | ||
@action={{action "viewJson"}} | ||
@icon="ellipsis-h" | ||
@title="explorer.view_json" | ||
/> | ||
</div> |
31 changes: 31 additions & 0 deletions
31
assets/javascripts/discourse/components/result-types/json.js
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,31 @@ | ||
import Component from "@glimmer/component"; | ||
import FullscreenCodeModal from "discourse/components/modal/fullscreen-code"; | ||
import { inject as service } from "@ember/service"; | ||
import { action } from "@ember/object"; | ||
import { cached } from "@glimmer/tracking"; | ||
|
||
export default class Json extends Component { | ||
@service dialog; | ||
@service modal; | ||
|
||
@cached | ||
get parsedJson() { | ||
try { | ||
return JSON.parse(this.args.ctx.value); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
@action | ||
viewJson() { | ||
this.modal.show(FullscreenCodeModal, { | ||
model: { | ||
code: this.parsedJson | ||
? JSON.stringify(this.parsedJson, null, 2) | ||
: this.args.ctx.value, | ||
codeClasses: "", | ||
}, | ||
}); | ||
} | ||
} |
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
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