Skip to content

Commit

Permalink
as is format (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram committed Oct 27, 2021
1 parent 08961e1 commit f6bb9c8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Change history of the project. All the feature updates, bug fixes, breaking chan
- E2E tests placeholder added
- type updates
- bug fixes
- "as-is" data format added for debugging

## [ 0.7.10 ]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grafana-infinity-datasource",
"version": "0.8.0-dev.3",
"version": "0.8.0-dev.4",
"description": "JSON, CSV, XML, GraphQL & HTML datasource for Grafana. Do infinite things with Grafana.",
"main": "dist/module.js",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion src/components/FormatSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ export const FormatSelector = (props: FormatSelectorProps) => {
onChange({ ...query, format });
onRunQuery();
};
const getFormats = () => {
if (query.type === 'json' && query.source === 'inline') {
return SCRAP_QUERY_RESULT_FORMATS;
} else {
return SCRAP_QUERY_RESULT_FORMATS.filter((f) => f.value !== 'as-is');
}
};
return (
<>
<label title={Components.QueryEditor.Format.Label.Title} className={`gf-form-label query-keyword width-4`}>
{Components.QueryEditor.Format.Label.Text}
</label>
<div title={Components.QueryEditor.Format.Dropdown.PlaceHolder.Title} className="select-wrapper">
<Select className="min-width-8 width-8" value={query.format} options={SCRAP_QUERY_RESULT_FORMATS} onChange={(e) => onFormatChange(e.value as InfinityQueryFormat)}></Select>
<Select className="min-width-8 width-8" value={query.format} options={getFormats()} onChange={(e) => onFormatChange(e.value as InfinityQueryFormat)}></Select>
</div>
</>
);
Expand Down
4 changes: 4 additions & 0 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class Datasource extends DataSourceWithBackend<InfinityQuery, InfinityOpt
case 'json':
case 'xml':
case 'graphql':
if (t.format === 'as-is' && t.source === 'inline') {
const data = JSON.parse(t.data || '[]');
resolve(data);
}
new InfinityProvider(t, this).query().then(resolve).catch(reject);
break;
case 'series':
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface SecureField {
export type InfinityQueryType = 'json' | 'csv' | 'tsv' | 'xml' | 'graphql' | 'html' | 'series' | 'global';
export type InfinityQuerySources = 'url' | 'inline' | 'random-walk' | 'expression'; // | 'local-fs';
export type InfinityColumnFormat = 'string' | 'number' | 'timestamp' | 'timestamp_epoch' | 'timestamp_epoch_s';
export type InfinityQueryFormat = 'table' | 'timeseries' | 'dataframe';
export type InfinityQueryFormat = 'table' | 'timeseries' | 'dataframe' | 'as-is';
export type InfinityQueryBase<T extends InfinityQueryType> = { type: T } & DataQuery;
export type InfinityQueryWithSource<S extends InfinityQuerySources> = { source: S } & DataQuery;
export type InfinityQueryWithURLSource<T extends InfinityQueryType> = {
Expand Down Expand Up @@ -233,6 +233,7 @@ export const SCRAP_QUERY_RESULT_FORMATS: Array<SelectableValue<InfinityQueryForm
{ label: 'Table', value: 'table' },
{ label: 'Time Series', value: 'timeseries' },
{ label: 'Data Frame', value: 'dataframe' },
{ label: 'As Is', value: 'as-is' },
];
export const SCRAP_QUERY_SOURCES: ScrapQuerySources[] = [
{ label: 'URL', value: 'url', supported_types: ['csv', 'tsv', 'json', 'html', 'xml', 'graphql'] },
Expand Down

1 comment on commit f6bb9c8

@vercel
Copy link

@vercel vercel bot commented on f6bb9c8 Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.