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

ISSUE-178 - added instant exports to explore tab #181

Merged
merged 5 commits into from
Jan 19, 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
17 changes: 15 additions & 2 deletions src/components/Header/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ import { Select } from '@mantine/core';

type DropdownProps = {
data: string[];
placeholder?: string;
searchable?: boolean;
value?: string | null;
onChange: (value: string) => void;
};

const Dropdown: FC<DropdownProps> = (props) => {
const { data, onChange } = props;
const { data, onChange, placeholder = "Export", searchable = false, value = null } = props;

return <Select placeholder="Column" data={data} w={140} searchable onChange={onChange} allowDeselect={false} />;
return (
<Select
placeholder={placeholder}
data={data}
w={140}
searchable={searchable}
onChange={onChange}
allowDeselect={false}
value={value}
/>
);
};

export default Dropdown;
8 changes: 7 additions & 1 deletion src/components/Header/LiveTailFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ const LiveTailFilter: FC = () => {
<Box className={liveTailFilterContainer}>
{schemaData.length > 0 && (
<>
<Dropdown data={schemaData.map((item) => item.name)} onChange={handleDropdownValue} />
<Dropdown
data={schemaData.map((item) => item.name)}
searchable
onChange={handleDropdownValue}
placeholder="Column"
value={searchField}
/>
<TextInput
className={searchInput}
value={searchValue}
Expand Down
32 changes: 0 additions & 32 deletions src/components/Header/SecondaryHeader.tsx

This file was deleted.

170 changes: 110 additions & 60 deletions src/components/Header/SubHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box } from '@mantine/core';
import { Box, Header as MantineHeader } from '@mantine/core';
import type { FC } from 'react';
import HeaderBreadcrumbs from './HeaderBreadcrumbs';
import RefreshInterval from './RefreshInterval';
Expand All @@ -10,25 +10,48 @@ import ReloadUser from './ReloadUser';
import DocsUser from './UserDocs';
import StreamingButton from './StreamingButton';
import LiveTailFilter from './LiveTailFilter';
import Dropdown from './Dropdown';
import { useHeaderStyles } from './styles';
import { HEADER_HEIGHT } from '@/constants/theme';
import { downloadDataAsCSV, downloadDataAsJson } from '@/utils/exportHelpers';
import { useLogsPageContext } from '@/pages/Logs/Context';
import { useHeaderContext } from '@/layouts/MainLayout/Context';

type HeaderLayoutProps = {
children: React.ReactNode;
};

const HeaderLayout: FC<HeaderLayoutProps> = (props) => {
const { classes } = useHeaderStyles();
const { container, navContainer } = classes;

return (
<MantineHeader {...props} className={container} height={HEADER_HEIGHT} p={0} withBorder zIndex={100}>
<Box className={navContainer}>{props.children}</Box>
</MantineHeader>
);
};

export const StatsHeader: FC = () => {
const { classes } = useLogQueryStyles();
const { container, innerContainer } = classes;

return (
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Stats']} />
<HeaderLayout>
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Stats']} />
</Box>
</Box>
</Box>

<Box>
<Box className={innerContainer}>
<RefreshNow />
<Box>
<Box className={innerContainer}>
<RefreshNow />
</Box>
</Box>
</Box>
</Box>
</HeaderLayout>
);
};

Expand All @@ -37,20 +60,22 @@ export const QueryHeader: FC = () => {
const { container, innerContainer } = classes;

return (
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Query']} />
<HeaderLayout>
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Query']} />
</Box>
</Box>
</Box>

<Box>
<Box className={innerContainer}>
<TimeRange />
<RefreshInterval />
<Box>
<Box className={innerContainer}>
<TimeRange />
<RefreshInterval />
</Box>
</Box>
</Box>
</Box>
</HeaderLayout>
);
};

Expand All @@ -59,48 +84,69 @@ export const LiveTailHeader: FC = () => {
const { container, innerContainer } = classes;

return (
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Live tail']} />
<HeaderLayout>
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Live tail']} />
</Box>
</Box>
</Box>

<Box>
<Box className={innerContainer}>
<LiveTailFilter />
<StreamingButton />
{/* <TimeRange /> */}
{/* <RefreshInterval /> */}
<Box>
<Box className={innerContainer}>
<LiveTailFilter />
<StreamingButton />
{/* <TimeRange /> */}
{/* <RefreshInterval /> */}
</Box>
</Box>
</Box>
</Box>
</HeaderLayout>
);
};

export const LogsHeader: FC = () => {
const { classes } = useLogQueryStyles();
const { container, innerContainer } = classes;
const {
methods: { makeExportData },
} = useLogsPageContext();
const {
state: { subLogQuery },
} = useHeaderContext();

const exportHandler = (fileType: string) => {
const query = subLogQuery.get();
const filename = `${query.streamName}-logs`;
if (fileType === 'CSV') {
downloadDataAsCSV(makeExportData('CSV'), filename)
} else if (fileType === 'JSON') {
downloadDataAsJson(makeExportData('JSON'), filename)
}
};

return (
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Logs']} />
<HeaderLayout>
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['Streams', 'streamName', 'Logs']} />
</Box>
</Box>
</Box>

<Box>
<Box className={innerContainer}>
<Search />
<RefreshNow />
{/* <LimitLog /> */}
<Box>
<Box className={innerContainer}>
<Search />
<RefreshNow />
{/* <LimitLog /> */}

<TimeRange />
<RefreshInterval />
<TimeRange />
<RefreshInterval />
<Dropdown data={['JSON', 'CSV']} onChange={exportHandler} />
</Box>
</Box>
</Box>
</Box>
</HeaderLayout>
);
};

Expand All @@ -124,19 +170,21 @@ export const UsersManagementHeader: FC = () => {
const { container, innerContainer } = classes;

return (
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['User Management']} />
<HeaderLayout>
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={['User Management']} />
</Box>
</Box>
</Box>
<Box>
<Box className={innerContainer}>
<ReloadUser />
<DocsUser />
<Box>
<Box className={innerContainer}>
<ReloadUser />
<DocsUser />
</Box>
</Box>
</Box>
</Box>
</HeaderLayout>
);
};

Expand All @@ -145,12 +193,14 @@ export const AllRouteHeader: FC = () => {
const { container, innerContainer } = classes;

return (
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={[]} />
<HeaderLayout>
<Box className={container}>
<Box>
<Box className={innerContainer}>
<HeaderBreadcrumbs crumbs={[]} />
</Box>
</Box>
</Box>
</Box>
</HeaderLayout>
);
};
2 changes: 0 additions & 2 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import PrimaryHeader from "./PrimaryHeader";
import SecondaryHeader from "./SecondaryHeader";

export {
PrimaryHeader,
SecondaryHeader
}
11 changes: 9 additions & 2 deletions src/hooks/useQueryLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getQueryLogs } from '@/api/query';
import { StatusCodes } from 'http-status-codes';
import useMountedState from './useMountedState';
import { useCallback, useEffect, useMemo, useRef, useTransition } from 'react';
import { LOG_QUERY_LIMITS } from '@/pages/Logs/Context';
import { LOG_QUERY_LIMITS, useLogsPageContext } from '@/pages/Logs/Context';
import { parseLogData } from '@/utils';

type QueryLogs = {
Expand Down Expand Up @@ -32,11 +32,14 @@ export const useQueryLogs = () => {
},
});
const [isPending, startTransition] = useTransition();
const {
state: { subLogQueryData },
} = useLogsPageContext();

const data: Log[] | null = useMemo(() => {
if (_dataRef.current) {
const logs = _dataRef.current;
const temp = [];
const temp: Log[] = [];
const { search, filters, sort } = querySearch;
const searchText = search.trim().toLowerCase();
const filteredKeys = Object.keys(filters);
Expand Down Expand Up @@ -78,6 +81,10 @@ export const useQueryLogs = () => {
return res * order;
});

subLogQueryData.set((state) => {
state.filteredData = temp;
state.rawData = logs;
});
return temp;
}

Expand Down
3 changes: 1 addition & 2 deletions src/layouts/MainLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrimaryHeader, SecondaryHeader } from '@/components/Header';
import { PrimaryHeader } from '@/components/Header';
import Navbar from '@/components/Navbar';
import { NAVBAR_WIDTH } from '@/constants/theme';
import { Box } from '@mantine/core';
Expand All @@ -21,7 +21,6 @@ const MainLayout: FC = () => {
display: 'flex',
flexDirection: 'column',
}}>
<SecondaryHeader />
<Outlet />
</Box>
</Box>
Expand Down
Loading