mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* add SQL migrations * dashboard previews from sql: poc * added todos * refactor: use the same enums where possible * use useEffect, always return json * added todo * refactor + delete files after use * refactor + fix manual thumbnail upload * refactor: move all interactions with sqlStore to thumbnail repo * refactor: remove file operations in thumb crawler/service * refactor: fix dashboard_thumbs sql store * refactor: extracted thumbnail fetching/updating to a hook * refactor: store thumbnails in redux store * refactor: store thumbnails in redux store * refactor: private'd repo methods * removed redux storage, saving images as blobs * allow for configurable rendering timeouts * added 1) query for dashboards with stale thumbnails, 2) command for marking thumbnails as stale * use sql-based queue in crawler * ui for marking thumbnails as stale * replaced `stale` boolean prop with `state` enum * introduce rendering session * compilation errors * fix crawler stop button * rename thumbnail state frozen to locked * #44449: fix merge conflicts * #44449: remove thumb methods from `Store` interface * #44449: clean filepath, defer file closing * #44449: fix rendering.Theme cyclic import * #44449: linting * #44449: linting * #44449: mutex'd crawlerStatus access * #44449: added integration tests for `sqlstore.dashboard_thumbs` * #44449: added comments to explain the `ThumbnailState` enum * #44449: use os.ReadFile rather then os.Open * #44449: always enable dashboardPreviews feature during integration tests * #44449: remove sleep time, adjust number of threads * #44449: review fix: add `orgId` to `DashboardThumbnailMeta` * #44449: review fix: automatic parsing of thumbnailState * #44449: lint fixes * #44449: review fix: prefer `WithDbSession` over `WithTransactionalDbSession` * #44449: review fix: add a comment explaining source of the filepath * #44449: review fix: added filepath validation * #44449: review fixes https://github.com/grafana/grafana/pull/45063/files @fzambia Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Alexander Emelin <frvzmb@gmail.com>
102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { Button, CollapsableSection, FileUpload } from '@grafana/ui';
|
|
import { getThumbnailURL } from 'app/features/search/components/SearchCard';
|
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
interface Props {
|
|
uid: string;
|
|
}
|
|
|
|
interface State {}
|
|
|
|
export class PreviewSettings extends PureComponent<Props, State> {
|
|
state: State = {};
|
|
|
|
doUpload = (evt: EventTarget & HTMLInputElement, isLight?: boolean) => {
|
|
const file = evt?.files && evt.files[0];
|
|
if (!file) {
|
|
console.log('NOPE!', evt);
|
|
return;
|
|
}
|
|
|
|
const url = getThumbnailURL(this.props.uid, isLight);
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
body: formData,
|
|
})
|
|
.then((response) => response.json())
|
|
.then((result) => {
|
|
console.log('Success:', result);
|
|
location.reload(); //HACK
|
|
})
|
|
.catch((error) => {
|
|
console.error('Error:', error);
|
|
});
|
|
};
|
|
|
|
markAsStale = (isLight: boolean) => async () => {
|
|
return getBackendSrv().put(getThumbnailURL(this.props.uid, isLight), { state: 'stale' });
|
|
};
|
|
|
|
render() {
|
|
const { uid } = this.props;
|
|
const imgstyle = { maxWidth: 300, maxHeight: 300 };
|
|
return (
|
|
<CollapsableSection label="Preview settings" isOpen={true}>
|
|
<div>DUMMY UI just so we have an upload button!</div>
|
|
<table cellSpacing="4">
|
|
<thead>
|
|
<tr>
|
|
<td>[DARK]</td>
|
|
<td>[LIGHT]</td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>
|
|
<Button type="button" variant="primary" onClick={this.markAsStale(false)} fill="outline">
|
|
Mark as stale
|
|
</Button>
|
|
</td>
|
|
<td>
|
|
<Button type="button" variant="primary" onClick={this.markAsStale(true)} fill="outline">
|
|
Mark as stale
|
|
</Button>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<img src={getThumbnailURL(uid, false)} style={imgstyle} />
|
|
</td>
|
|
<td>
|
|
<img src={getThumbnailURL(uid, true)} style={imgstyle} />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<FileUpload
|
|
accept="image/png, image/webp"
|
|
onFileUpload={({ currentTarget }) => this.doUpload(currentTarget, false)}
|
|
>
|
|
Upload dark
|
|
</FileUpload>
|
|
</td>
|
|
<td>
|
|
<FileUpload
|
|
accept="image/png, image/webp"
|
|
onFileUpload={({ currentTarget }) => this.doUpload(currentTarget, true)}
|
|
>
|
|
Upload light
|
|
</FileUpload>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</CollapsableSection>
|
|
);
|
|
}
|
|
}
|