Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:#394 type url params #395

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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;

Check failure

Code scanning / CodeQL

Remote property injection High

A property name to write to depends on a
user-provided value
.
A property name to write to depends on a
user-provided 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 @@
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
Loading