Skip to content

Commit

Permalink
fix: #454 Misleading delete confirmation request
Browse files Browse the repository at this point in the history
  • Loading branch information
jacovinus committed Jun 27, 2024
1 parent cfb8e04 commit e24d7ef
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/node_modules/*
dist
server
server
.env
*.cookie
4 changes: 3 additions & 1 deletion packages/main/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?
*.env
*.env
.env
*.cookie
32 changes: 23 additions & 9 deletions packages/main/plugins/Cardinality/CardinalityDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import {
DialogCancelButton,
DialogConfirmButton,
Expand Down Expand Up @@ -142,8 +142,18 @@ export default function CardinalityDialog({
}: CardinalityDialogProps) {
const [open, setOpen] = useState(false);
const [confirmRemove, setConfirmRemove] = useState(false);
const [queryMatchText, setQueryMatchText] = useState("")
const theme = useTheme();
const { focusLabel, timeSeriesSelector: match } = useCardinalityStore();

useEffect(()=>{
// this should be only if open
if(open) {
const matchText = queryUpdater[source]({query:label, match})
setQueryMatchText(matchText)
}

},[open])

const handleClickOpen = () => {
setOpen(true);
Expand All @@ -161,15 +171,18 @@ export default function CardinalityDialog({

let queryText = query ?? "";



if (!isCustom) {

queryText = queryUpdater[source]({
query: label,
focusLabel,
match,
});
}

await clearFingerPrints(queryText);
await clearFingerPrints(queryText);

// this should give a response from the server

Expand Down Expand Up @@ -222,27 +235,28 @@ export default function CardinalityDialog({
{query}?
</>
) : (
// this is the one that should match the query
<>
Are you sure you want to clear the{" "}
<span>{value}</span> fingerprints with label{" "}
<span>{label}</span> from{" "}
<span>{source}</span>?
<span>{value}</span> fingerprints with {queryMatchText} request?

</>
)}
</DialogTitle>

<DialogContent>
<DialogContentText id="alert-dialog-description">
<p style={{ marginTop: "10px" }}>
<span style={{ marginTop: "10px" }}>
Click <em>Delete Fingerprints</em> to delete
your fingerprints permanently
</p>
<p style={{ margin: "6px" }}>
</span>
<br/>
<span style={{ margin: "6px" }}>
<em>
Note that you will also be removing all
fingerprints with labels related.
</em>
</p>
</span>

<CheckboxWithLabel
checked={confirmRemove}
Expand Down
19 changes: 11 additions & 8 deletions packages/main/plugins/Cardinality/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const getSeriesArraySelector = (labelsArray: string[]): string => {
};

interface QueryUpdaterArgs {
query: string;
focusLabel: string;
match: string;
query?: string;
focusLabel?: string;
match?: string;
}

export type QueryUpdater = {
Expand All @@ -90,13 +90,16 @@ export const queryUpdater: QueryUpdater = {
seriesCountByFocusLabelValue: ({ query, focusLabel }): string => {
return getSeriesSelector(focusLabel, query);
},
seriesCountByLabelValuePair: ({ query }): string => {
seriesCountByLabelValuePair: ({ query, match }): string => {

let previous_match;

try {
const prev = localStorage.getItem("labelValuePairs");
if (prev) {
previous_match = prev;
} else if(match && match !== ""){
previous_match = match
} else {
previous_match = "";
}
Expand All @@ -109,7 +112,7 @@ export const queryUpdater: QueryUpdater = {
if (previous_match && !previous_match.includes(query)) {
queryStr = `${previous_match} ${query}`;

localStorage.setItem("labelValuePairs", queryStr);
//localStorage.setItem("labelValuePairs", queryStr);
} else if (previous_match && previous_match.includes(query)) {
let prevArray = previous_match.split(" ");

Expand All @@ -119,11 +122,11 @@ export const queryUpdater: QueryUpdater = {

queryStr = joint;

localStorage.setItem("labelValuePairs", joint);
localStorage.setItem("labelValuePairs", joint);
} else if (previous_match === "") {
queryStr = query;

localStorage.setItem("labelValuePairs", queryStr);
localStorage.setItem("labelValuePairs", queryStr);
}

let labelsArray = queryStr.split(" ");
Expand Down
6 changes: 2 additions & 4 deletions packages/main/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
"@ui/services/*": ["services/*"],
"@ui/theme/*": ["theme/*"],
"@ui/qrynui/*": ["qrynui/*"],
"@ui/environment/*":["environment/*"]
"@ui/environment/*":["environment/*"],
"react": ["./node_modules/@types/react"],
}
},
"include": ["src","views"],
"paths": {
"react": ["./node_modules/@types/react"],
},
"references": [{ "path": "./tsconfig.node.json" }]
}

0 comments on commit e24d7ef

Please sign in to comment.