Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fridgepoet committed Feb 28, 2024
1 parent 3b7ced0 commit 3a27086
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { trackRequest } from 'tracking';

export class DataSource extends DataSourceWithBackend<SheetsQuery, DataSourceOptions> {
authType: string;
defaultSheetID?: string;
constructor(instanceSettings: DataSourceInstanceSettings<DataSourceOptions>) {
super(instanceSettings);
this.authType = instanceSettings.jsonData.authenticationType;
Expand Down Expand Up @@ -43,4 +44,8 @@ export class DataSource extends DataSourceWithBackend<SheetsQuery, DataSourceOpt
: []
);
}

getDefaultQuery(app: CoreApp): Partial<SheetsQuery> {
return { spreadsheet: this.defaultSheetID };
}
}
31 changes: 31 additions & 0 deletions src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export function ConfigEditor(props: Props) {
onChange: onUpdateDatasourceSecureJsonDataOption(props, 'apiKey'),
};

const loadSheetIDs = async () => {
const { options } = props;
try {
const ds = (await getDataSourceSrv().get(options.uid)) as DataSource;
return ds.getSpreadSheets();
} catch {
return [];
}
};

return (
<>
<DataSourceDescription
Expand All @@ -36,6 +46,27 @@ export function ConfigEditor(props: Props) {
hasRequiredFields={false}
/>

<div className="gf-form">
<InlineFormLabel

Check failure on line 50 in src/components/ConfigEditor.tsx

View workflow job for this annotation

GitHub Actions / lint

'InlineFormLabel' is not defined
className="width-10"
tooltip="The id of a default google sheet. The datasource must be saved before this can be set."
>
Default SheetID
</InlineFormLabel>
<SegmentAsync

Check failure on line 56 in src/components/ConfigEditor.tsx

View workflow job for this annotation

GitHub Actions / lint

'SegmentAsync' is not defined
className="width-30"
loadOptions={() => loadSheetIDs()}
placeholder="Select Spreadsheet ID"
value={options.jsonData.defaultSheetID}
allowCustomValue={true}
onChange={onUpdateDatasourceJsonDataOptionSelect(props, 'defaultSheetID')}
disabled={
(props.options.jsonData.authType === googleSheetsAuthTypes && (!secureJsonFields || !secureJsonFields.apiKey)) ||

Check failure on line 64 in src/components/ConfigEditor.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·············`
(jsonData.authType === googleSheetsAuthTypes.JWT && (!secureJsonFields || !secureJsonFields.jwt))
}
/>
</div>

<Divider />

<ConfigurationHelp authenticationType={options.jsonData.authenticationType} />
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DataSourceJsonData } from '@grafana/data';
import { DataQuery } from '@grafana/schema';
import { GoogleAuthType, GOOGLE_AUTH_TYPE_OPTIONS, DataSourceSecureJsonData } from '@grafana/google-sdk';

Expand Down Expand Up @@ -36,3 +37,7 @@ export interface SheetsQuery extends DataQuery {
cacheDurationSeconds?: number;
useTimeFilter?: boolean;
}

export interface SheetsSourceOptions extends DataSourceJsonData {
defaultSheetID?: string;
}

0 comments on commit 3a27086

Please sign in to comment.