Skip to content

Commit

Permalink
Merge pull request #395 from metrico/fix/type_url_params
Browse files Browse the repository at this point in the history
Fix:#394 type url params
  • Loading branch information
jacovinus authored Jan 17, 2024
2 parents 814720c + cc90576 commit 290c553
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 451 deletions.
9 changes: 0 additions & 9 deletions packages/main/plugins/Raggix/worktest.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { ThemeProvider } from "@mui/styles";
import styled from "@emotion/styled";
import { DialogStyles } from "../../settingsdialog/SettingsDialog";
import useTheme from "@ui/theme/useTheme"
import useTheme from "@ui/theme/useTheme";
const AlertCont = styled.div`
background: ${({ theme }: any) => theme.shadow};
#alert-dialog-title {
Expand Down Expand Up @@ -78,6 +78,7 @@ export default function AlertDialog({ clearHistory, dialogType }: any) {
Cancel
</DialogCancelButton>
<DialogConfirmButton
active={true}
onClick={handleClearHistory}
autoFocus
>
Expand Down
1 change: 0 additions & 1 deletion packages/main/plugins/queryhistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,6 @@ const QueryHistory = () => {
const url = new URL(item);
const { hash } = url;
const params = new URLSearchParams(hash.replace(/#/, ""));
params.set("label", label);
const locationWithLabel = new URL(window.location.href);
locationWithLabel.hash = `#${params.toString()}`;
const copyText =
Expand Down
8 changes: 5 additions & 3 deletions packages/main/plugins/settingsmenu/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import localUrl from "../../../services/localUrl";
import setLinksHistory from "@ui/store/actions/setLinksHistory";
import { MenuItem } from "@mui/material";
import { notificationTypes } from "@ui/qrynui/notifications/consts";
import { useLocation } from "react-router-dom";

export default function CopyButton(props:any) {
const{c} = props
const dispatch: any = useDispatch();
const saveUrl = localUrl();
const {hash} = useLocation()
const LINK_COPIED = "Link Copied To Clipboard";
function shareLink() {
dispatch(setIsSubmit(true));
Expand All @@ -18,8 +20,8 @@ export default function CopyButton(props:any) {
navigator?.clipboard?.writeText(window.location.href).then(
function () {

const storedUrl = saveUrl.add({
data: window.location.href,
const storedUrl = saveUrl.add(hash, {
data: {href:window.location.href},
description: "From Shared URL",
}, 10);
dispatch(setLinksHistory(storedUrl));
Expand Down Expand Up @@ -49,7 +51,7 @@ export default function CopyButton(props:any) {

return new Promise((res:any, rej:any) => {

const storedUrl = saveUrl.add({
const storedUrl = saveUrl.add(hash,{
data: window.location.href,
description: "From Shared URL",
}, 10);
Expand Down
79 changes: 73 additions & 6 deletions packages/main/services/localUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,69 @@ import { _URL_ITEM } from "./consts";
import localService from "./localService";
import { format } from "date-fns";

export type PanelData = {
id: string;
idRef: string;
lastIdx: number;
panel: string;
queryType: string;
dataSourceType: string;
dataSourceURL: string;
dataSourceId: string;
limit: number;
step: number;
tableView: boolean;
chartView: boolean;
isShowTs: boolean;
isBuilder: boolean;
isLogsVolume: boolean;
browserOpen: boolean;
expr: string;
labels: any[];
values: any[];
response: Response;
open: boolean;
start: string;
time: string;
stop: string;
label: string;
pickerOpen: boolean;
};

type UrlParamsData = {
autoTheme?: string;
isEmbed?: string;
isSplit?: string;
isSubmit?: string;
left?: string;
right?: string;
step?: string;
start?: string;
stop?: string;
theme?: string;
time?: string;
};

type ItemData = {
href?: string;
url?: string;
type?: string;
start?: string;
stop?: string;
queryInput?: string;
queryType?: string;
limit?: number;
panel?: string;
id?: string;
};

export type UrlItem = {
id?: string;
data: ItemData;
description: string;
timestamp?: number;
};

const localUrl = () => {
const { l_set, l_get, j_parse, j_string } = localService();

Expand Down Expand Up @@ -38,27 +101,31 @@ const localUrl = () => {
}
};

const add = (item: any, maxLength = Infinity) => {
const add = (hash: string, item: any, maxLength = Infinity) => {
// we should pass the paeams here istead of parsing inside
let previousData = get() || [];
const { href, url, type, queryInput, queryType, limit, panel } =
item.data;

const { hash } = window.location;
const origin = window.location.origin;
const urlParams = new URLSearchParams(hash.replace(/#/, ""));
let paramsData: any = {};

let paramsData = {} as UrlParamsData;
urlParams.set("isSubmit", "true");

for (let [key, value] of urlParams) {
paramsData[key] = value;
}

const fromDate = format(
parseInt(paramsData.start) / 1000000,
parseInt(paramsData?.start) / 1000000,
"yyyy-MM-dd HH:mm:ss"
);
const toDate = format(
parseInt(paramsData.stop) / 1000000,
"yyyy-MM-dd HH:mm:ss"
);

try {
const newItem = {
url,
Expand All @@ -72,10 +139,10 @@ const localUrl = () => {
timestamp: item.timestamp || Date.now(),
starred: false,
description: item.description || "",
params: paramsData || {},
params: (paramsData as UrlParamsData) || {},
fromDate,
toDate,
data: `${origin}/#${urlParams.toString()}` || "",
data: `${origin}/#/search/#${urlParams.toString()}` || "",
};
let newStorage = [newItem].concat(previousData).slice(0, maxLength);
set(newStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const QueryBar: React.FC<QueryBarProps> = (props) => {

const { getLocalQueryItem, getLocalDataSources, setLocalQueryData } =
QueryLocalService;

const { hash } = useLocation();
const dispatch: any = useDispatch();
const saveUrl = localUrl();
Expand Down Expand Up @@ -685,6 +685,7 @@ const QueryBar: React.FC<QueryBarProps> = (props) => {
const updateLinksHistory = () => {
const ds = dataSources.find((f: any) => f.id === dataSourceId);
const storedUrl = saveUrl.add(
hash,
{
data: {
href: window.location.href,
Expand Down
Loading

0 comments on commit 290c553

Please sign in to comment.