Skip to content

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBurgess committed Dec 5, 2024
1 parent a83cdcf commit 3ef25e4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
85 changes: 43 additions & 42 deletions ui/dashboard/src/components/SpiltSnapButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
import React, { useState, useRef } from "react";
import { Menu } from "@headlessui/react";
import { SnapshotDataToExecutionCompleteSchemaMigrator } from "@powerpipe/utils/schema";
import { useNavigate } from "react-router-dom";
import { ChevronDownIcon } from "@heroicons/react/solid";
import NeutralButton from "@powerpipe/components/forms/NeutralButton";
import Icon from "@powerpipe/components/Icon";
import useGroupingFilterConfig from "@powerpipe/hooks/useGroupingFilterConfig";
import useCheckGroupingConfig from "@powerpipe/hooks/useCheckGroupingConfig";
import useFilterConfig from "@powerpipe/hooks/useFilterConfig";
import useGroupingConfig from "@powerpipe/hooks/useGroupingConfig";
import { ChangeEvent, useRef } from "react";
import {
DashboardDataModeCLISnapshot,
DashboardDataModeLive,
DashboardActions,
DashboardSnapshotMetadata,
DashboardDataModeDiff,
} from "@powerpipe/types";
import { EXECUTION_SCHEMA_VERSION_20240607 } from "@powerpipe/constants/versions";
import { EXECUTION_SCHEMA_VERSION_20241125 } from "@powerpipe/constants/versions";
import {
filterToSnapshotMetadata,
groupingToSnapshotMetadata,
stripSnapshotDataForExport,
} from "@powerpipe/utils/snapshot";
import { Menu } from "@headlessui/react";
import { saveAs } from "file-saver";
import { SnapshotDataToExecutionCompleteSchemaMigrator } from "@powerpipe/utils/schema";
import { timestampForFilename } from "@powerpipe/utils/date";
import { useDashboard } from "@powerpipe/hooks/useDashboard";
import { validateFilter } from "@powerpipe/components/dashboards/grouping/CheckFilterEditor";
import { useNavigate } from "react-router-dom";
import { validateFilter } from "@powerpipe/components/dashboards/grouping/FilterEditor";

interface SplitButtonProps {
className?: string;
}

const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
const SplitButton = ({ className }: SplitButtonProps) => {
const { dashboard, dataMode, selectedDashboard, snapshot } = useDashboard();
const filterConfig = useGroupingFilterConfig();
const groupingConfig = useCheckGroupingConfig();
const { allFilters } = useFilterConfig();
const { allGroupings } = useGroupingConfig();
const { dispatch } = useDashboard();
const fileInputRef = useRef<HTMLInputElement | null>(null);
const fileInputRefForDiff = useRef<HTMLInputElement | null>(null);
Expand All @@ -52,26 +51,36 @@ const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
const withMetadata = {
...streamlinedSnapshot,
};
if (!!filterConfig || !!groupingConfig) {

if (
!!Object.keys(allFilters).length ||
!!Object.keys(allGroupings).length
) {
const metadata: DashboardSnapshotMetadata = {
view: {},
};
// If a benchmark
if (
dashboard.artificial &&
!!filterConfig &&
validateFilter(filterConfig)
) {
// @ts-ignore
metadata.view.filter_by = filterToSnapshotMetadata(filterConfig);
if (!!Object.keys(allFilters).length) {
for (const [panel, filter] of Object.entries(allFilters)) {
if (!validateFilter(filter)) {
console.warn("Ignoring invalid filter", { panel, filter });
continue;
}
// @ts-ignore
metadata.view[panel] = metadata.view[panel] || {};
// @ts-ignore
metadata.view[panel].filter_by = filterToSnapshotMetadata(filter);
}
}
if (!!groupingConfig) {
// @ts-ignore
// TODO @mike re-include this
// metadata.view.group_by = groupingToSnapshotMetadata(groupingConfig);
if (!!Object.keys(allGroupings).length) {
for (const [panel, grouping] of Object.entries(allGroupings)) {
// @ts-ignore
metadata.view[panel] = metadata.view[panel] || {};
// @ts-ignore
metadata.view[panel].group_by = groupingToSnapshotMetadata(grouping);
}
}
withMetadata.metadata = metadata;
withMetadata.schema_version = EXECUTION_SCHEMA_VERSION_20240607;
withMetadata.schema_version = EXECUTION_SCHEMA_VERSION_20241125;
}

const blob = new Blob([JSON.stringify(withMetadata)], {
Expand All @@ -80,7 +89,7 @@ const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
saveAs(blob, `${dashboard.name}.${timestampForFilename(Date.now())}.pps`);
};

const handleDiffOpen = (e: React.ChangeEvent<HTMLInputElement>) => {
const handleDiffOpen = (e: ChangeEvent<HTMLInputElement>) => {
const files = e.target.files;
if (!files || files.length === 0) {
return;
Expand Down Expand Up @@ -109,7 +118,7 @@ const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
fr.readAsText(files[0]);
};

const handleFileOpen = (e: React.ChangeEvent<HTMLInputElement>) => {
const handleFileOpen = (e: ChangeEvent<HTMLInputElement>) => {
const files = e.target.files;
if (!files || files.length === 0) {
return;
Expand All @@ -121,7 +130,7 @@ const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
return;
}

e.target.value = ""; // Clear the input for repeated use
e.target.value = "";
try {
const data = JSON.parse(fr.result.toString());
const eventMigrator =
Expand Down Expand Up @@ -154,7 +163,7 @@ const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
} catch (err: any) {
dispatch({
type: DashboardActions.WORKSPACE_ERROR,
error: "Unable to load snapshot: " + err.message,
error: "Unable to load snapshot:" + err.message,
});
}
};
Expand All @@ -174,17 +183,13 @@ const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
<NeutralButton
type="button"
className="inline-flex items-center space-x-2 shadow-none rounded-r-none"
onClick={() => fileInputRef.current?.click()}
>
<Icon
className="inline-block text-foreground-lighter w-5 -mt-0.5"
icon="heroicons-outline:folder-open"
/>
<span
className="hidden lg:block"
onClick={() => fileInputRef.current?.click()}
>
Open
</span>
<span className="hidden lg:block">Open</span>
<input
ref={fileInputRef}
accept="application/json, .pps, .sps"
Expand All @@ -201,17 +206,13 @@ const SplitButton: React.FC<SplitButtonProps> = ({ className }) => {
<NeutralButton
type="button"
className="inline-flex items-center space-x-2 shadow-none rounded-r-none"
onClick={() => fileInputRefForDiff.current?.click()}
>
<Icon
className="inline-block text-foreground-lighter w-5 h-5 -mt-0.5"
icon="difference"
/>
<span
className="hidden lg:block"
onClick={() => fileInputRefForDiff.current?.click()}
>
Diff
</span>
<span className="hidden lg:block">Diff</span>
<input
ref={fileInputRefForDiff}
accept="application/json, .pps, .sps"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<<<<<<<< HEAD:ui/dashboard/src/components/dashboards/grouping/FilterEditor/index.test.ts
import { validateFilter } from "@powerpipe/components/dashboards/grouping/FilterEditor"; // Replace with the actual module path
========
import { validateFilter } from "@powerpipe/components/dashboards/grouping/CheckFilterEditor"; // Replace with the actual module path
>>>>>>>> 982dc29 (Rename check to grouping in dashboard UI):ui/dashboard/src/components/dashboards/grouping/CheckFilterEditor/index.test.ts

interface TestCase {
name: string;
Expand Down

0 comments on commit 3ef25e4

Please sign in to comment.