mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki Context UI: Do not disable last label (#62866)
* improved text * prevent all labels removed * use `structuredClone` instead of lodash * update test * get `structuredClone` in test? * fix using structuredClone
This commit is contained in:
parent
f0333ac41f
commit
00edc1c6b1
@ -5998,6 +5998,11 @@ exports[`better eslint`] = {
|
|||||||
"public/app/plugins/datasource/loki/LiveStreams.ts:5381": [
|
"public/app/plugins/datasource/loki/LiveStreams.ts:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
],
|
],
|
||||||
|
"public/app/plugins/datasource/loki/components/LokiContextUi.test.tsx:5381": [
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
|
||||||
|
],
|
||||||
"public/app/plugins/datasource/loki/components/LokiLabelBrowser.tsx:5381": [
|
"public/app/plugins/datasource/loki/components/LokiLabelBrowser.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "1"]
|
[0, 0, 0, "Do not use any type assertions.", "1"]
|
||||||
|
@ -15,6 +15,20 @@ jest.mock('@grafana/runtime', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('LokiContextUi', () => {
|
describe('LokiContextUi', () => {
|
||||||
|
const savedGlobal = global;
|
||||||
|
beforeAll(() => {
|
||||||
|
// TODO: `structuredClone` is not yet in jsdom https://github.com/jsdom/jsdom/issues/3363
|
||||||
|
if (!(global as any).structuredClone) {
|
||||||
|
(global as any).structuredClone = function structuredClone(objectToClone: any) {
|
||||||
|
const stringified = JSON.stringify(objectToClone);
|
||||||
|
const parsed = JSON.parse(stringified);
|
||||||
|
return parsed;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
afterAll(() => {
|
||||||
|
global = savedGlobal;
|
||||||
|
});
|
||||||
const setupProps = (): LokiContextUiProps => {
|
const setupProps = (): LokiContextUiProps => {
|
||||||
const mockLanguageProvider = {
|
const mockLanguageProvider = {
|
||||||
start: jest.fn().mockImplementation(() => Promise.resolve()),
|
start: jest.fn().mockImplementation(() => Promise.resolve()),
|
||||||
@ -66,7 +80,7 @@ describe('LokiContextUi', () => {
|
|||||||
render(<LokiContextUi {...props} />);
|
render(<LokiContextUi {...props} />);
|
||||||
|
|
||||||
// Initial set of labels is available and not selected
|
// Initial set of labels is available and not selected
|
||||||
expect(await screen.findByText(/Select labels to include in the context query/)).toBeInTheDocument();
|
expect(await screen.findByText(/Select labels to be included in the context query/)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('starts the languageProvider', async () => {
|
it('starts the languageProvider', async () => {
|
||||||
|
@ -49,9 +49,11 @@ export function LokiContextUi(props: LokiContextUiProps) {
|
|||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
|
|
||||||
const [contextFilters, setContextFilters] = useState<ContextFilter[]>([]);
|
const [contextFilters, setContextFilters] = useState<ContextFilter[]>([]);
|
||||||
|
|
||||||
const [initialized, setInitialized] = useState(false);
|
const [initialized, setInitialized] = useState(false);
|
||||||
const timerHandle = React.useRef<number>();
|
const timerHandle = React.useRef<number>();
|
||||||
const previousInitialized = React.useRef<boolean>(false);
|
const previousInitialized = React.useRef<boolean>(false);
|
||||||
|
const previousContextFilters = React.useRef<ContextFilter[]>([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
@ -63,6 +65,13 @@ export function LokiContextUi(props: LokiContextUiProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contextFilters.filter(({ enabled, fromParser }) => enabled && !fromParser).length === 0) {
|
||||||
|
setContextFilters(previousContextFilters.current);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
previousContextFilters.current = structuredClone(contextFilters);
|
||||||
|
|
||||||
if (timerHandle.current) {
|
if (timerHandle.current) {
|
||||||
clearTimeout(timerHandle.current);
|
clearTimeout(timerHandle.current);
|
||||||
}
|
}
|
||||||
@ -143,7 +152,7 @@ export function LokiContextUi(props: LokiContextUiProps) {
|
|||||||
colorIndex={1}
|
colorIndex={1}
|
||||||
/>
|
/>
|
||||||
</Tooltip>{' '}
|
</Tooltip>{' '}
|
||||||
Select labels to include in the context query:
|
Select labels to be included in the context query:
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
|
Loading…
Reference in New Issue
Block a user