Skip to content

Commit

Permalink
Update Partials loading (#358)
Browse files Browse the repository at this point in the history
* partials updated

* Update CHANGELOG.md

* Remove Loading Bar

* Add link color

* Update CHANGELOG.md

---------

Co-authored-by: Mikhail Volkov <mikhail@volkovlabs.io>
  • Loading branch information
vitPinchuk and mikhail-vl authored Sep 12, 2024
1 parent 922306c commit 0178b1e
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 166 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Changelog

## 5.4.0 (IN PROGRESS)
## 5.4.0 (2024-09-12)

### Features / Enhancements

- Updated panel render if first data source does not have data (#353)
- Added wrap button in the code editor (#359)
- Updated Partials loading (#358)
- Updated hyperlinks style (#358)

## 5.3.0 (2024-08-22)

Expand Down
15 changes: 15 additions & 0 deletions src/components/Text/Text.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const getStyles = (theme: GrafanaTheme2) => {
margin-left: ${theme.spacing(2)};
}
a {
color: blue;
}
table {
border-collapse: collapse;
Expand Down Expand Up @@ -60,6 +64,16 @@ export const getStyles = (theme: GrafanaTheme2) => {
}
`;

/**
* Loading Bar
*/
const loadingBar = css`
position: absolute;
top: 0;
left: 0;
width: 100%;
overflow: hidden;
`;
/**
* Highlight
*/
Expand All @@ -68,5 +82,6 @@ export const getStyles = (theme: GrafanaTheme2) => {
return {
frame,
highlight,
loadingBar,
};
};
14 changes: 0 additions & 14 deletions src/components/Text/Text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables: (str: string) => str,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -78,7 +77,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: eventBus as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -113,7 +111,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: eventBus as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -149,7 +146,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: eventBus as any,
htmlContents: [],
};

const { rerender } = await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -191,7 +187,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: eventBus as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -235,7 +230,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -284,7 +278,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -344,7 +337,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -383,7 +375,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -425,7 +416,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables: (str: string) => str,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -456,7 +446,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables: (str: string) => str,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -496,7 +485,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables: (str: string) => str,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -547,7 +535,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables: (str: string) => str,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down Expand Up @@ -610,7 +597,6 @@ describe('Text', () => {
timeZone: '',
replaceVariables: (str: string) => str,
eventBus: {} as any,
htmlContents: [],
};

await act(async () => render(<Text {...props} />));
Expand Down
43 changes: 18 additions & 25 deletions src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
} from '@grafana/data';
import { getAppEvents } from '@grafana/runtime';
import { TimeZone } from '@grafana/schema';
import { Alert, useStyles2, useTheme2 } from '@grafana/ui';
import { Alert, LoadingBar, useStyles2, useTheme2 } from '@grafana/ui';
import React, { useCallback, useEffect, useState } from 'react';

import { TEST_IDS } from '../../constants';
import { PanelOptions, PartialItem, RenderMode, RowItem } from '../../types';
import { PanelOptions, RenderMode, RowItem } from '../../types';
import { generateHtml } from '../../utils';
import { Row } from '../Row';
import { getStyles } from './Text.styles';
Expand Down Expand Up @@ -73,13 +73,6 @@ interface Props {
* @type {PanelData}
*/
data: PanelData;

/**
* HTML contents
*
* @type {PartialItem[]}
*/
htmlContents: PartialItem[];
}

/**
Expand All @@ -93,13 +86,17 @@ export const Text: React.FC<Props> = ({
replaceVariables,
eventBus,
data: panelData,
htmlContents,
}) => {
/**
* Generated rows
*/
const [rows, setRows] = useState<RowItem[]>([]);

/**
* Loading state
*/
const [isLoading, setIsLoading] = useState<boolean>(false);

/**
* Generate html error
*/
Expand Down Expand Up @@ -136,7 +133,8 @@ export const Text: React.FC<Props> = ({
*/
const getHtml = useCallback(
async (htmlData: Record<string, unknown>, content: string) => {
return {
setIsLoading(true);
const result = {
...(await generateHtml({
data: htmlData,
content,
Expand All @@ -151,24 +149,14 @@ export const Text: React.FC<Props> = ({
notifySuccess,
notifyError,
theme,
htmlContents,
partials: options?.contentPartials,
})),
data: htmlData,
};
setIsLoading(false);
return result;
},
[
options,
timeRange,
timeZone,
replaceVariables,
eventBus,
panelData,
frame,
notifySuccess,
notifyError,
theme,
htmlContents,
]
[options, timeRange, timeZone, replaceVariables, eventBus, panelData, frame, notifySuccess, notifyError, theme]
);

useEffect(() => {
Expand Down Expand Up @@ -306,6 +294,11 @@ export const Text: React.FC<Props> = ({

return (
<>
{isLoading && (
<div className={styles.loadingBar}>
<LoadingBar width={250} />
</div>
)}
{rows.map((row, index) => (
<Row
key={index}
Expand Down
5 changes: 1 addition & 4 deletions src/components/TextPanel/TextPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Select, useStyles2, useTheme2 } from '@grafana/ui';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import { TEST_IDS } from '../../constants';
import { useContentPartials, useExternalResources } from '../../hooks';
import { useExternalResources } from '../../hooks';
import { PanelOptions, RenderMode, ResourceType } from '../../types';
import { getFrame } from '../../utils';
import { Text } from '../Text';
Expand Down Expand Up @@ -93,8 +93,6 @@ export const TextPanel: React.FC<Props> = ({
type: ResourceType.STYLES,
});

const htmlContents = useContentPartials(options?.contentPartials);

/**
* Re-render on dashboard refresh
*/
Expand Down Expand Up @@ -145,7 +143,6 @@ export const TextPanel: React.FC<Props> = ({
replaceVariables={replaceVariables}
eventBus={eventBus}
data={data}
htmlContents={htmlContents}
/>
</div>

Expand Down
1 change: 0 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './useContentPartials';
export * from './useExternalResources';
40 changes: 0 additions & 40 deletions src/hooks/useContentPartials.test.ts

This file was deleted.

47 changes: 0 additions & 47 deletions src/hooks/useContentPartials.ts

This file was deleted.

Loading

0 comments on commit 0178b1e

Please sign in to comment.