diff --git a/packages/main/plugins/Raggix/worktest.ts b/packages/main/plugins/Raggix/worktest.ts deleted file mode 100644 index be4aceb8..00000000 --- a/packages/main/plugins/Raggix/worktest.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* eslint-disable no-restricted-globals */ - -self.onmessage = (e: MessageEvent) => { - const data = e - self.postMessage(JSON.stringify(data)); - -} - -export {}; \ No newline at end of file diff --git a/packages/main/plugins/queryhistory/components/AlertDialog.tsx b/packages/main/plugins/queryhistory/components/AlertDialog.tsx index b6654c54..f29fe1e3 100644 --- a/packages/main/plugins/queryhistory/components/AlertDialog.tsx +++ b/packages/main/plugins/queryhistory/components/AlertDialog.tsx @@ -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 { @@ -78,6 +78,7 @@ export default function AlertDialog({ clearHistory, dialogType }: any) { Cancel diff --git a/packages/main/plugins/queryhistory/index.tsx b/packages/main/plugins/queryhistory/index.tsx index d3496c43..da32a1c8 100644 --- a/packages/main/plugins/queryhistory/index.tsx +++ b/packages/main/plugins/queryhistory/index.tsx @@ -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 = diff --git a/packages/main/plugins/settingsmenu/CopyButton/CopyButton.tsx b/packages/main/plugins/settingsmenu/CopyButton/CopyButton.tsx index 53686ebb..25e41d97 100644 --- a/packages/main/plugins/settingsmenu/CopyButton/CopyButton.tsx +++ b/packages/main/plugins/settingsmenu/CopyButton/CopyButton.tsx @@ -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)); @@ -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)); @@ -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); diff --git a/packages/main/services/localUrl.ts b/packages/main/services/localUrl.ts index 68589168..1ecf32de 100644 --- a/packages/main/services/localUrl.ts +++ b/packages/main/services/localUrl.ts @@ -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(); @@ -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, @@ -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); diff --git a/packages/main/src/components/LabelBrowser/components/QueryBar/QueryBar.tsx b/packages/main/src/components/LabelBrowser/components/QueryBar/QueryBar.tsx index e6bbd881..184c21ae 100644 --- a/packages/main/src/components/LabelBrowser/components/QueryBar/QueryBar.tsx +++ b/packages/main/src/components/LabelBrowser/components/QueryBar/QueryBar.tsx @@ -110,7 +110,7 @@ const QueryBar: React.FC = (props) => { const { getLocalQueryItem, getLocalDataSources, setLocalQueryData } = QueryLocalService; - + const { hash } = useLocation(); const dispatch: any = useDispatch(); const saveUrl = localUrl(); @@ -685,6 +685,7 @@ const QueryBar: React.FC = (props) => { const updateLinksHistory = () => { const ds = dataSources.find((f: any) => f.id === dataSourceId); const storedUrl = saveUrl.add( + hash, { data: { href: window.location.href, diff --git a/packages/main/src/components/StatusBar/components/copylinkbutton/CopyLinkButton.tsx b/packages/main/src/components/StatusBar/components/copylinkbutton/CopyLinkButton.tsx deleted file mode 100644 index 24054045..00000000 --- a/packages/main/src/components/StatusBar/components/copylinkbutton/CopyLinkButton.tsx +++ /dev/null @@ -1,197 +0,0 @@ -import { createAlert } from "@ui/store/actions/createAlert"; -import { useDispatch, useSelector } from "react-redux"; -import setLinksHistory from "@ui/store/actions/setLinksHistory"; -import { setIsSubmit } from "@ui/store/actions/setIsSubmit"; -import { DatePickerButton, UrlCopyButton } from "../../styled"; -import ContentCopyIcon from "@mui/icons-material/ContentCopy"; -import KeyboardArrowDownOutlinedIcon from "@mui/icons-material/KeyboardArrowDownOutlined"; -import { - Checkbox, - FormControlLabel, - FormGroup, - MenuItem, - Tooltip, - Typography, -} from "@mui/material"; - -import { CustomMenu } from "../daterangepicker"; -import { useState } from "react"; -import { useLocation } from "react-router-dom"; -import { storedUrl } from "."; -import useTheme from "@ui/theme/useTheme"; - -export default function CopyLinkButton() { - const LINK_COPIED = "Link Copied To Clipboard"; - const theme = useTheme(); - const dispatch: any = useDispatch(); - const [anchorEl, setAnchorEl] = useState(null); - const open = Boolean(anchorEl); - const [isRelative, setIsRelative] = useState(false); - - const label = useSelector(({ label }: any) => label); - function alertSuccess() { - dispatch( - createAlert({ - type: "success", - message: LINK_COPIED, - }) - ); - } - - function storeHistory() { - dispatch(setLinksHistory(storedUrl())); - } - function shareDefaultLink(copyText: any) { - navigator.clipboard.writeText(copyText).then( - function () { - storeHistory(); - alertSuccess(); - }, - function (err) { - console.log("error on copy", err); - } - ); - } - function setSubmitted() { - dispatch(setIsSubmit(true)); - } - function shareDomLink(copyText: any) { - let textArea: any = document.createElement("textarea"); - textArea.value = copyText; - textArea.style = { - position: "fixed", - left: "-999999px", - top: "-999999px", - }; - - document.body.appendChild(textArea); - textArea.focus(); - textArea.select(); - - return new Promise((res: any, rej: any) => { - storeHistory(); - - alertSuccess(); - document.execCommand("copy") ? res() : rej(); - textArea.remove(); - }); - } - const setTitle = "Copy Link"; - - const setActive = true; - - const { hash } = useLocation(); - function copyLink(e: any) { - e.preventDefault(); - setSubmitted(); - const params = new URLSearchParams(hash.replace(/#/, "")); - params.set("label", label); - const locationWithLabel = new URL(window.location.href); - locationWithLabel.hash = `#${params.toString()}`; - const copyText = - isRelative && label ? locationWithLabel : window.location.href; - setTimeout(() => { - if (navigator?.clipboard && window.isSecureContext) { - shareDefaultLink(copyText); - } else { - shareDomLink(copyText); - } - }, 200); - } - const handleClick = (event: any) => { - setAnchorEl(event.currentTarget); - setIsRelative(isRelative && label); - }; - const handleClose = (e: any, direction: any, option: any) => { - setAnchorEl(null); - }; - - const handleChange = (event: any) => { - setIsRelative(event.target.checked); - }; - - return ( - <> - - <> - - - - {"Copy Link"} - - - - - - - - - } - label={ - - Relative time - - } - /> - - - - - - - ); -} diff --git a/packages/main/src/components/StatusBar/components/copylinkbutton/components/CopyButton.tsx b/packages/main/src/components/StatusBar/components/copylinkbutton/components/CopyButton.tsx deleted file mode 100644 index 609b5651..00000000 --- a/packages/main/src/components/StatusBar/components/copylinkbutton/components/CopyButton.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { UrlCopyButton } from "../../../styled"; -import ContentCopyIcon from "@mui/icons-material/ContentCopy"; - -export const CopyButton = (props: any) => { - const { onClick } = props; - return ( - - - {"Copy Link"} - - ); -}; diff --git a/packages/main/src/components/StatusBar/components/copylinkbutton/components/RelativeTimeMenu.tsx b/packages/main/src/components/StatusBar/components/copylinkbutton/components/RelativeTimeMenu.tsx deleted file mode 100644 index 060070ff..00000000 --- a/packages/main/src/components/StatusBar/components/copylinkbutton/components/RelativeTimeMenu.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { - Checkbox, - FormControlLabel, - FormGroup, - MenuItem, - Typography, -} from "@mui/material"; -import { CustomMenu } from "../../daterangepicker"; -import { formControlLabelStyle, menuItemStyle, typoStyle } from "../styles"; - -export const RelativeTimeMenu = (props: any) => { - const { - anchorEl, - open, - handleClose, - handleChange, - label, - isRelative, - qrynTheme, - } = props; - - const checkBoxRender = () => ( - - ); - const typoRender = () => ( - Relative time - ); - - return ( - - - - - - - - ); -}; diff --git a/packages/main/src/components/StatusBar/components/copylinkbutton/hooks/index.tsx b/packages/main/src/components/StatusBar/components/copylinkbutton/hooks/index.tsx deleted file mode 100644 index 118ada25..00000000 --- a/packages/main/src/components/StatusBar/components/copylinkbutton/hooks/index.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { useSelector } from "react-redux"; - -export function useTimeLabel() { - return useSelector((store: any) => store.label); -} diff --git a/packages/main/src/components/StatusBar/components/copylinkbutton/index.ts b/packages/main/src/components/StatusBar/components/copylinkbutton/index.ts deleted file mode 100644 index fa832e6f..00000000 --- a/packages/main/src/components/StatusBar/components/copylinkbutton/index.ts +++ /dev/null @@ -1,110 +0,0 @@ -import localUrl from "@ui/services/localUrl"; - -export function storedUrl() { - return localUrl().add( - { - data: window.location.href, - description: "From Shared URL", - }, - 10 - ); -} -interface HTMLGhostTextArea extends HTMLTextAreaElement { - style: any; -} -export const handleShareDomLink = ( - copyText: any, - storeHistory: any, - alertSuccess: any -) => { - let textArea: HTMLGhostTextArea = document.createElement("textarea"); - textArea.value = copyText; - textArea.style = { - position: "fixed", - left: "-999999px", - top: "-999999px", - }; - - document.body.appendChild(textArea); - textArea.focus(); - textArea.select(); - - return new Promise((resolve: any, reject: any) => { - storeHistory(); - - alertSuccess(); - document.execCommand("copy") ? resolve() : reject(); - textArea.remove(); - }); -}; - -export const handleCopyLink = ( - e: any, - setSubmitted: any, - hash: any, - label: any, - isRelative: any, - shareDefaultLink: any, - shareDomLink: any -) => { - e.preventDefault(); - setSubmitted(); - const params = new URLSearchParams(hash.replace(/#/, "")); - params.set("label", label); - const locationWithLabel = new URL(window.location.href); - locationWithLabel.hash = `#${params.toString()}`; - - const copyText = setCopyText(isRelative, label, locationWithLabel); - - setTimeout(() => { - shareLinkAction(shareDefaultLink, shareDomLink, copyText); - }, 200); -}; - -export const handleAlertSuccess = (dispatch: any, createAlert: any) => { - dispatch( - createAlert({ - type: "success", - message: "Link Copied To Clipboard", - }) - ); -}; - -export const handleShareDefaultLink = ( - storeHistory: any, - alertSuccess: any, - copyText: any -) => { - navigator.clipboard.writeText(copyText).then( - function () { - storeHistory(); - alertSuccess(); - }, - function (err) { - console.log("error on copy", err); - } - ); -}; - -export const setCopyText = ( - isRelative: any, - label: any, - locationWithLabel: any -) => { - if (isRelative && label) { - return locationWithLabel; - } - return window.location.href; -}; - -export const shareLinkAction = ( - shareDefaultLink: any, - shareDomLink: any, - copyText: any -) => { - if (navigator?.clipboard && window.isSecureContext) { - shareDefaultLink(copyText); - } else { - shareDomLink(copyText); - } -}; diff --git a/packages/main/src/components/StatusBar/components/copylinkbutton/styles/index.tsx b/packages/main/src/components/StatusBar/components/copylinkbutton/styles/index.tsx deleted file mode 100644 index 8259a04e..00000000 --- a/packages/main/src/components/StatusBar/components/copylinkbutton/styles/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -export const menuItemStyle = { padding: "0 14px" }; - -export const typoStyle = (theme:any) => ({ - fontSize: "12px", - color: theme.contrast, -}); - -export const formControlLabelStyle = (label:boolean) => ({ - padding: "0", - marginRight: 0, - cursor: !label ? "not-allowed" : "default", -}); diff --git a/packages/main/src/components/StatusBar/components/statusbarselectors/StatusBarSelectors.tsx b/packages/main/src/components/StatusBar/components/statusbarselectors/StatusBarSelectors.tsx deleted file mode 100644 index d82a2ff3..00000000 --- a/packages/main/src/components/StatusBar/components/statusbarselectors/StatusBarSelectors.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import CopyLinkButton from "../copylinkbutton/CopyLinkButton"; -import { ThemeProvider } from "@emotion/react"; -import useTheme from "@ui/theme/useTheme" -import { css, cx } from "@emotion/css"; - -const StatusOptions = css` - display: flex; - align-items: center; -`; - -const StatusSelectors = css` - display: flex; - align-items: center; - .selector { - margin-left: 10px; - .label { - flex: 1; - color: #bfbfbf; - white-space: nowrap; - text-transform: uppercase; - border-radius: 3px; - font-size: 12px; - } - } - & div { - display: flex; - align-items: center; - } -`; - -export function StatusBarSelectors() { - const theme = useTheme(); - - return ( - -
-
- -
-
-
- ); -}