Skip to content

Commit

Permalink
fix: undo request
Browse files Browse the repository at this point in the history
  • Loading branch information
jacovinus committed Jan 5, 2024
1 parent d87e39b commit 1074c34
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 47 deletions.
67 changes: 35 additions & 32 deletions packages/main/plugins/Cardinality/CardinalityTotals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { css, cx } from "@emotion/css";
import { Tooltip } from "@mui/material";
import ReplayIcon from '@mui/icons-material/Replay';

import {format} from 'date-fns'
import { format } from 'date-fns'


export const TotalRowStyle = css`
Expand Down Expand Up @@ -69,6 +69,7 @@ export function Total(props: MaintainanceItem & MaintainanceActions) {
const {
id,
type,
query,
status,
created_sec,
from_sec,
Expand All @@ -84,17 +85,18 @@ export function Total(props: MaintainanceItem & MaintainanceActions) {
<div className="table-row">
<div className="cell">{status}</div>
<div className="cell"> {type} </div>
<div className="cell">{format(created_sec*1000,"dd-MM-yyyy hh:mm:ss")}</div>
<div className="cell"> {format(from_sec*1000,"dd-MM-yyyy hh:mm:ss") } </div>
<div className="cell"> {format(to_sec*1000,"dd-MM-yyyy hh:mm:ss")}</div>
<div className="cell">{query}</div>
<div className="cell">{format(created_sec * 1000, "dd-MM-yyyy hh:mm:ss")}</div>
<div className="cell"> {format(from_sec * 1000, "dd-MM-yyyy hh:mm:ss")} </div>
<div className="cell"> {format(to_sec * 1000, "dd-MM-yyyy hh:mm:ss")}</div>
<div className="cell"> {series_dropped} </div>
<div className="cell"> {series_created}</div>
<div className="cell"> <code>{JSON.stringify(logs)}</code> </div>
<div className="cell">
<Tooltip title="undo action">
<button onClick={() => undoAction(id, type, status)}>
<ReplayIcon style={{width:'14px', height:'14px'}}/>
</button>
<Tooltip title="undo action">
<button onClick={() => undoAction(id, type, status)}>
<ReplayIcon style={{ width: '14px', height: '14px' }} />
</button>
</Tooltip>
</div>
</div>
Expand All @@ -113,30 +115,31 @@ export default function CardinalityTotals() {
{" "}
<div className={cx(TotalRowStyle)}>
<div className="table">
<div className="table-header">
<div className="cell">Status</div>
<div className="cell">Type</div>
<div className="cell">Created sec</div>
<div className="cell">From sec</div>
<div className="cell">To sec</div>
<div className="cell">Series Dropped</div>
<div className="cell">Series Created</div>
<div className="cell">Logs</div>
<div className="cell">Undo</div>
</div>
<>
{totals?.length ? (
totals?.map((total,key) => (
<Total
undoAction={onUndoAction}
key={key}
{...total}
/>
))
) : (
<> no totals </>
)}
</>
<div className="table-header">
<div className="cell">Status</div>
<div className="cell">Type</div>
<div className="cell">Query</div>
<div className="cell">Created sec</div>
<div className="cell">From sec</div>
<div className="cell">To sec</div>
<div className="cell">Series Dropped</div>
<div className="cell">Series Created</div>
<div className="cell">Logs</div>
<div className="cell">Undo</div>
</div>
<>
{totals?.length ? (
totals?.map((total, key) => (
<Total
undoAction={onUndoAction}
key={key}
{...total}
/>
))
) : (
<> no totals </>
)}
</>
</div>
</div>
</>
Expand Down
72 changes: 65 additions & 7 deletions packages/main/plugins/Cardinality/api/CardinalityRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,70 @@ export const getDeletedFingerprints = async (
}
};

export const undoFingerPrintAction = async (
id,
url,
setIsLoading,
headers,
auth,
setError
) => {
try {
const { u, p } = auth;

const urlUndo = `${url}/api/v1/undo/${id}`;
await fetch(urlUndo, {
method: "POST",

headers: {
...headers,
Authorization: `Basic ${btoa(u + ":" + p)}`,
},
}).then((response) => {
if (
(response && response?.status === 500) ||
response?.status === 400
) {
setError(response.statusText);
setIsLoading(false);
let error = response.text();
store.dispatch(
createAlert({
message: `Deleted fingerprints not undone, ${error}`,
type: "error",
})
);
}

if (
(response && response?.status === 200) ||
response?.status === 200
) {
setIsLoading(false);
setError("");
store.dispatch(
createAlert({
message: `Undone deleted fingerprints`,
type: "success",
})
);
console.log(response);
}
});
} catch (e) {
setError(JSON.stringify(e));
setIsLoading(false);
store.dispatch(
createAlert({
message: `Deleted fingerprints not undone`,
type: "error",
})
);
console.log(e);
setIsLoading(false);
}
};

export const deleteFingerprints = async (
url,
query,
Expand Down Expand Up @@ -181,7 +245,7 @@ const requestCardinality = async (
setIsLoading(true);
// set
//this makes the multiple fetch requests

try {
const { u, p } = auth;
const responses = await Promise.all(
Expand Down Expand Up @@ -276,14 +340,10 @@ export const useCardinalityRequest = (

const { url, headers, user_pass } = useDataSourceData("logs");


// const [isLoading, setIsLoading] = useState(false);
// const [error, setError] = useState("");
// const [tsdbStatus, setTsdbStatus] = useState<any>({});




const handleDelete = async (query, amount) => {
const locale = moment.tz.guess(true);
const mDay = moment.tz(reqDate, locale).add(1, "day");
Expand All @@ -306,7 +366,6 @@ export const useCardinalityRequest = (
};

const handleGetDeletedFingerprints = async () => {

await getDeletedFingerprints(
url,
setError,
Expand All @@ -315,7 +374,6 @@ export const useCardinalityRequest = (
headers,
user_pass
);

};

const handleCardinalityRequest = async (params: any) => {
Expand Down
11 changes: 9 additions & 2 deletions packages/main/plugins/Cardinality/api/mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { MaintainanceItem } from '../api/types'

export const totalsMock = [

export const totalsMock: MaintainanceItem[] = [
{
id: "85331a29-ea2f-4d6c-89ae-fa87349e4d7f",
query: "{a=\"b\"}",
type: "delete",
status: "running",
created_sec: 1704359839,
Expand All @@ -17,6 +20,7 @@ export const totalsMock = [
},
{
id: "85331a29-ea2f-4d6c-89ae-fa87349e4d7f",
query: "{a=\"b\"}",
type: "delete",
status: "running",
created_sec: 1704359839,
Expand All @@ -32,6 +36,7 @@ export const totalsMock = [
},
{
id: "85331a29-ea2f-4d6c-89ae-fa87349e4d7f",
query: "{__name=\"server\",type=\"clickhouse\",level=\"info\"}",
type: "delete",
status: "running",
created_sec: 1704359839,
Expand All @@ -47,6 +52,7 @@ export const totalsMock = [
},
{
id: "85331a29-ea2f-4d6c-89ae-fa87349e4d7f",
query: "{__name=\"server\",type=\"clickhouse\",level=\"debug\"}",
type: "delete",
status: "running",
created_sec: 1704359839,
Expand All @@ -60,4 +66,5 @@ export const totalsMock = [
"INFO backing up data",
],
},
];
];

1 change: 1 addition & 0 deletions packages/main/plugins/Cardinality/api/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface CardinalityRequest {

export interface MaintainanceItem {
id: string;
query: string;
created_sec: number; // ts sec
from_sec: number; // ts sec
to_sec: number; // ts sec
Expand Down
9 changes: 3 additions & 6 deletions packages/main/views/Main/DesktopView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function DesktopView({
const realMinWidth = !isSplit
? widthTotal
: widthTotal / 4 > 370
? widthTotal / 4
: 370;
? widthTotal / 4
: 370;
setMinWidth(realMinWidth);
}, [
setWidthLeft,
Expand Down Expand Up @@ -102,10 +102,7 @@ export function DesktopView({

return (
<ThemeProvider theme={theme}>
<MainContainer>
{panelsRenderer(leftOpen, rightOpen)}
</MainContainer>

<MainContainer>{panelsRenderer(leftOpen, rightOpen)}</MainContainer>
<SettingsDialog open={settingsDialogOpen} />
<QueryHistory />
</ThemeProvider>
Expand Down

0 comments on commit 1074c34

Please sign in to comment.