Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jacovinus committed Dec 1, 2023
2 parents 1055173 + 9543254 commit 65158bb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 39 deletions.
41 changes: 15 additions & 26 deletions packages/main/src/components/QueryItem/QueryItemContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useDispatch, useSelector } from "react-redux";
import { setLeftPanel } from "@ui/store/actions/setLeftPanel";
import { setRightPanel } from "@ui/store/actions/setRightPanel";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
import SyncIcon from "@mui/icons-material/Sync";
import {
CloseQuery,
Expand Down Expand Up @@ -34,13 +33,20 @@ export const StyledTabsCont = (theme: any) => css`
}
`;

const iconButtonStyle = {
fontSize: "15px",
cursor: "pointer",
padding: "3px",
marginLeft: "10px",
};

export function QueryItemContainer(props: any) {
const dispatch: any = useDispatch();
// update panel on id change
const { onTabChange, tabsValue, isTabs, activeTabs } = props;
const { children } = props;
const {
data: { expr, open, id, start, stop, label, pickerOpen, idRef },
data: { expr, id, start, stop, label, pickerOpen, idRef },
isQueryOpen,
} = props;

Expand Down Expand Up @@ -284,8 +290,8 @@ export function QueryItemContainer(props: any) {
/>
{!isTabletOrMobile && (
<SplitViewButton
type="split"
isSplit={isSplit}
open={open}
side={props.name}
/>
)}
Expand All @@ -303,12 +309,7 @@ export function QueryItemContainer(props: any) {

<Tooltip title={"Sync Time Ranges"}>
<SyncIcon
style={{
fontSize: "15px",
cursor: "pointer",
padding: "3px",
marginLeft: "10px",
}}
style={iconButtonStyle}
onClick={onSyncTimeRanges}
/>
</Tooltip>
Expand All @@ -321,30 +322,18 @@ export function QueryItemContainer(props: any) {
label={""}
/>
<AddOutlinedIcon
style={{
fontSize: "15px",
cursor: "pointer",
padding: "3px",
marginLeft: "10px",
}}
style={iconButtonStyle}
onClick={props.onAddQuery}
/>
<DeleteOutlineIcon
style={{
fontSize: "15px",
cursor: "pointer",
padding: "3px",
}}
onClick={props.onDeleteQuery}
<SplitViewButton
type="remove"
onDeleteQuery={props.onDeleteQuery}
side={props.name}
/>
</div>
</div>
)}
</div>

{/* add a flag in here for when we will have tabs */}

{/* here we need the children container // the tabs */}
{children}
</QueryItemContainerStyled>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { setLeftPanel } from "@ui/store/actions/setLeftPanel";
import { setRightPanel } from "@ui/store/actions/setRightPanel";
import { setSplitView } from "./setSplitView";
import { SplitButton } from "./styled";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";

export type props = {
panel?: string;
Expand All @@ -13,7 +14,7 @@ export function closePanel(
[leftOpen, rightOpen]: [leftOpen: boolean, rightOpen: boolean],
panel: "left" | "right",
prev: any,
dispatch: Function
dispatch: any
) {
let data = [...prev];
let next = data?.map((m: any) => ({ ...m, open: false }));
Expand All @@ -28,7 +29,7 @@ export function closePanel(

export function openPanel(
[left, right]: [left: any, right: any],
dispatch: Function
dispatch: any
) {
let leftCopy = [...left];
let rightCopy = [...right];
Expand All @@ -40,19 +41,30 @@ export function openPanel(
dispatch(setRightPanel(openRight));
}

export default function SplitViewButton(props: any) {
type SplitButtonProps = {
type: "remove" | "split";
side?: "left" | "right";
isSplit?: boolean;
onDeleteQuery?: () => void | undefined;
};

const { side, isSplit } = props;
export default function SplitViewButton({
type,
side = "left",
onDeleteQuery,
isSplit,
}: SplitButtonProps) {
const panel = useSelector((store: any) => store[side]);
const left = useSelector((store: any) => store.left);
const right = useSelector((store: any) => store.right);
const dispatch: any = useDispatch();
const usedSide = useSelector((store: any) => store[side]);
const dispatch:any = useDispatch();
const isSplitView = useSelector((store: any) => store.isSplit);

const splitView = (e: any) => {
e.preventDefault();
e.stopPropagation();

if (!isSplit) {
if (!isSplit && !isSplitView) {
openPanel([left, right], dispatch);
dispatch(setSplitView(true));
} else {
Expand All @@ -63,14 +75,33 @@ export default function SplitViewButton(props: any) {
}
};

const handleDeleteAction = (e: any) => {
if (usedSide?.length > 1 && onDeleteQuery !== undefined) {
onDeleteQuery();
} else if (isSplitView) {
splitView(e);
}
};

const setTitle = isSplit ? "Close Split View" : "Split View";
return (
<>
<Tooltip title={setTitle}>
<SplitButton onClick={splitView}>
{isSplit ? "Close" : "Split"}
</SplitButton>
</Tooltip>
{type === "split" ? (
<Tooltip title={setTitle}>
<SplitButton onClick={splitView}>
{isSplit ? "Close" : "Split"}
</SplitButton>
</Tooltip>
) : (
<DeleteOutlineIcon
style={{
fontSize: "15px",
cursor: "pointer",
padding: "3px",
}}
onClick={handleDeleteAction}
/>
)}
</>
);
}
28 changes: 27 additions & 1 deletion packages/main/views/Main/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export async function checkLocalAPI(
datasource: any,
auth?: AuthParams,
isAuth?: boolean
) {
): Promise<boolean> {
let response: any = {};
let conf = getAxiosConf(datasource);
let isReady = false;
Expand Down Expand Up @@ -192,14 +192,40 @@ export async function checkLocalAPI(
}
}
}

return isReady;
}

export function setLocalDataSources(datasources: any) {
// we could check datasources when typed in here
localStorage.setItem("dataSources", JSON.stringify(datasources));
}

export function updateDataSourcesUrl(cb: any, prevData: any, url: any) {
// 1- take datasources
const dsCP = [...prevData];

// 2 - copy as previous
const prevDs = JSON.parse(JSON.stringify(dsCP));

// 3- update datasources value with new source
const newDs = prevDs?.map((m: any) => ({
...m,
url,
}));

// update localstorage datasources
setLocalDataSources(newDs);
// update datasources at store
cb(setDataSources(newDs));
}

export async function updateDataSourcesFromLocalUrl(
dataSources: any,
dispatch: any,
navigate: any
) {
// current location
const location = window.location.origin;
const logsDs = dataSources.find((f: any) => f.type === "logs");
const isBasicAuth = logsDs?.auth?.basicAuth?.value;
Expand Down

0 comments on commit 65158bb

Please sign in to comment.