Skip to content

Commit

Permalink
fix: minor EMUI changes (#2232)
Browse files Browse the repository at this point in the history
## Description:
This PR includes:
* fix the EMUI support for pasted github links to support repositories
with a default branch not named 'main'
* Remove the navigation blocker on the enclave logs
* Name ports `service:port` when shown in the enclave list


![image](https://github.com/kurtosis-tech/kurtosis/assets/4419574/62c7db37-91d0-4117-84cd-f124c560affb)


## Is this change user facing?
YES

## References (if applicable):
-
https://sageroomworkspace.slack.com/archives/C05DZ4UABDZ/p1708702184444319
thread on issue parsing github url
-
https://sageroomworkspace.slack.com/archives/C05DZ4UABDZ/p1708618735521189?thread_ts=1708616085.847449&cid=C05DZ4UABDZ
request for port name change
  • Loading branch information
Dartoxian authored Feb 28, 2024
1 parent 7020183 commit 9e719d6
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 121 deletions.
1 change: 0 additions & 1 deletion enclave-manager/web/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Cypress.Commands.add("createAndGoToEnclave", (enclaveName: string) => {

// Go to the enclave overview
cy.contains("Go to Enclave Overview").click();
cy.contains("[role='dialog'] button", "Continue").click();
cy.url().should("match", /enclave\/[^/]+/);
});

Expand Down
58 changes: 27 additions & 31 deletions enclave-manager/web/packages/app/src/emui/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
Button,
FormControl,
FormLabel,
Input,
InputGroup,
InputRightElement,
Expand All @@ -12,7 +10,6 @@ import {
ModalFooter,
ModalHeader,
ModalOverlay,
Switch,
Text,
} from "@chakra-ui/react";
import { CopyButton, NavButton, Navigation, NavigationDivider } from "kurtosis-ui-components";
Expand All @@ -24,10 +21,9 @@ import { PiLinkSimpleBold } from "react-icons/pi";
import { Link, useLocation } from "react-router-dom";
import { KURTOSIS_CLOUD_CONNECT_URL } from "../client/constants";
import { useKurtosisClient } from "../client/enclaveManager/KurtosisClientContext";
import { settingKeys, useSettings } from "./settings";

export const Navbar = () => {
const { updateSetting, settings } = useSettings();
//const { updateSetting, settings } = useSettings();
const location = useLocation();
const kurtosisClient = useKurtosisClient();
const [showAboutDialog, setShowAboutDialog] = useState(false);
Expand Down Expand Up @@ -83,32 +79,32 @@ export const Navbar = () => {
/>
</InputRightElement>
</InputGroup>
<Text
as={"h2"}
fontSize={"lg"}
m={"16px 0"}
pt={"16px"}
borderTopWidth={"1px"}
borderTopColor={"gray.60"}
fontWeight={"semibold"}
>
Settings:
</Text>
<FormControl display="flex" alignItems="center">
<FormLabel htmlFor="experimental-build" mb="0">
Enable experimental enclave builder interface?
</FormLabel>
<Switch
id="experimental-build"
onChange={() =>
updateSetting(
settingKeys.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE,
!settings.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE,
)
}
isChecked={settings.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE}
/>
</FormControl>
{/*<Text*/}
{/* as={"h2"}*/}
{/* fontSize={"lg"}*/}
{/* m={"16px 0"}*/}
{/* pt={"16px"}*/}
{/* borderTopWidth={"1px"}*/}
{/* borderTopColor={"gray.60"}*/}
{/* fontWeight={"semibold"}*/}
{/*>*/}
{/* Settings:*/}
{/*</Text>*/}
{/*<FormControl display="flex" alignItems="center">*/}
{/* <FormLabel htmlFor="experimental-build" mb="0">*/}
{/* Enable experimental enclave builder interface?*/}
{/* </FormLabel>*/}
{/* <Switch*/}
{/* id="experimental-build"*/}
{/* onChange={() =>*/}
{/* updateSetting(*/}
{/* settingKeys.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE,*/}
{/* !settings.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE,*/}
{/* )*/}
{/* }*/}
{/* isChecked={settings.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE}*/}
{/* />*/}
{/*</FormControl>*/}
</ModalBody>

<ModalFooter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { isDefined } from "kurtosis-ui-components";
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { useSettings } from "../../settings";
import { KURTOSIS_BUILD_ENCLAVE_URL_ARG } from "./configuration/drawer/constants";
import { EnclaveBuilderDrawer } from "./enclaveBuilder/EnclaveBuilderDrawer";

export const BuildEnclave = () => {
const { settings } = useSettings();
const navigate = useNavigate();
const location = useLocation();

Expand All @@ -23,9 +21,5 @@ export const BuildEnclave = () => {
}
};

if (!settings.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE) {
return null;
}

return <EnclaveBuilderDrawer isOpen={buildEnclaveOpen} onClose={handleCloseBuildEnclave} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { KurtosisPackage } from "kurtosis-cloud-indexer-sdk";
import { isDefined } from "kurtosis-ui-components";
import { useState } from "react";
import { FiEdit2 } from "react-icons/fi";
import { useSettings } from "../../settings";
import { EnclaveFullInfo } from "../types";
import { CreateOrConfigureEnclaveDrawer } from "./configuration/drawer/CreateOrConfigureEnclaveDrawer";
import { EnclaveBuilderDrawer } from "./enclaveBuilder/EnclaveBuilderDrawer";
Expand All @@ -15,8 +14,6 @@ type EditEnclaveButtonProps = ButtonProps & {
};

export const EditEnclaveButton = ({ enclave, ...buttonProps }: EditEnclaveButtonProps) => {
const { settings } = useSettings();

if (!isDefined(enclave.starlarkRun)) {
return (
<Button isLoading={true} colorScheme={"blue"} leftIcon={<FiEdit2 />} size={"sm"} {...buttonProps}>
Expand All @@ -35,10 +32,7 @@ export const EditEnclaveButton = ({ enclave, ...buttonProps }: EditEnclaveButton
);
}

if (
settings.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE &&
starlarkScriptContainsEMUIBuildState(enclave.starlarkRun.value.serializedScript)
) {
if (starlarkScriptContainsEMUIBuildState(enclave.starlarkRun.value.serializedScript)) {
return <EditFromScriptButton enclave={enclave} {...buttonProps} />;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const enclaveToRow = (enclave: EnclaveFullInfo, catalog?: Result<GetPackagesResp
service.privatePorts,
service.maybePublicPorts,
service.maybePublicIpAddr,
service.name,
),
)
: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const getPortTableRows = (
privatePorts: Record<string, Port>,
publicPorts: Record<string, Port>,
publicIp: string,
serviceName?: string,
): PortsTableRow[] => {
return Object.entries(privatePorts).map(([name, port]) => {
let link;
Expand All @@ -45,7 +46,7 @@ export const getPortTableRows = (
transportProtocol: transportProtocolToString(port.transportProtocol),
privatePort: port.number,
publicPort: publicPorts[name].number,
name,
name: isDefined(serviceName) ? `${serviceName}:${name}` : name,
},
link: link,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { Button, ButtonGroup, Tooltip } from "@chakra-ui/react";
import { FiPlus, FiTool } from "react-icons/fi";
import { useNavigate } from "react-router-dom";
import { useSettings } from "../../../settings";
import { KURTOSIS_BUILD_ENCLAVE_URL_ARG, KURTOSIS_CREATE_ENCLAVE_URL_ARG } from "../configuration/drawer/constants";

export const CreateEnclaveButton = () => {
const { settings } = useSettings();
const navigate = useNavigate();
return (
<ButtonGroup>
{settings.ENABLE_EXPERIMENTAL_BUILD_ENCLAVE && (
<Tooltip label={"Build a new enclave"} openDelay={1000}>
<Button
colorScheme={"blue"}
leftIcon={<FiTool />}
size={"sm"}
onClick={() => navigate(`#${KURTOSIS_BUILD_ENCLAVE_URL_ARG}`)}
>
Build Enclave
</Button>
</Tooltip>
)}
<Tooltip label={"Build a new enclave"} openDelay={1000}>
<Button
colorScheme={"blue"}
leftIcon={<FiTool />}
size={"sm"}
onClick={() => navigate(`#${KURTOSIS_BUILD_ENCLAVE_URL_ARG}`)}
>
Build Enclave
</Button>
</Tooltip>
<Tooltip label={"Create a new enclave"} openDelay={1000}>
<Button
colorScheme={"green"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import {
} from "kurtosis-ui-components";
import { useEffect, useMemo, useState } from "react";
import { FiCheck, FiSettings, FiX } from "react-icons/fi";
import { Location, useBlocker, useLocation, useNavigate } from "react-router-dom";
import { Location, useLocation, useNavigate } from "react-router-dom";
import { EditEnclaveButton } from "../../components/EditEnclaveButton";
import { LogNavigationWarningModal } from "../../components/modals/LogNavigationWarningModal";
import { ServicesTable } from "../../components/tables/ServicesTable";
import { DeleteEnclavesButton } from "../../components/widgets/DeleteEnclavesButton";
import { useEnclavesContext } from "../../EnclavesContext";
Expand Down Expand Up @@ -90,8 +89,6 @@ export const EnclaveLogs = () => {
);
}, [rawLogLines, shouldUseDescriptionField]);

const blocker = useBlocker(({ currentLocation, nextLocation }) => currentLocation.pathname !== nextLocation.pathname);

useEffect(() => {
let cancelled = false;
(async () => {
Expand Down Expand Up @@ -223,19 +220,6 @@ export const EnclaveLogs = () => {
/>
</TitledBox>
)}
<LogNavigationWarningModal
isOpen={blocker.state === "blocked"}
onCancel={() => {
if (blocker.state === "blocked") {
blocker.reset();
}
}}
onConfirm={() => {
if (blocker.state === "blocked") {
blocker.proceed();
}
}}
/>
</>
</AppPageLayout>
);
Expand Down
4 changes: 1 addition & 3 deletions enclave-manager/web/packages/app/src/emui/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { isDefined, maybeParse } from "kurtosis-ui-components";
import { createContext, PropsWithChildren, useCallback, useContext, useEffect, useState } from "react";

type Settings = {
ENABLE_EXPERIMENTAL_BUILD_ENCLAVE: boolean;
SAVED_PACKAGES: string[];
};

export const settingKeys: { [k in keyof Settings]: k } = {
ENABLE_EXPERIMENTAL_BUILD_ENCLAVE: "ENABLE_EXPERIMENTAL_BUILD_ENCLAVE",
SAVED_PACKAGES: "SAVED_PACKAGES",
} as const;

const defaultSettings: Settings = { ENABLE_EXPERIMENTAL_BUILD_ENCLAVE: false, SAVED_PACKAGES: [] };
const defaultSettings: Settings = { SAVED_PACKAGES: [] };

const SETTINGS_LOCAL_STORAGE_KEY = "kurtosis-settings";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
export function parsePackageUrl(packageUrl: string) {
const components = packageUrl
.replace(/https?:\/\//, "")
.replace(/(?<=github\.com\/([^/])+\/([^/])+)\/tree\/main/, "")
.replace(/(?<=github\.com\/[^/]+\/[^/]+)\/tree\/([^/]+)/, "")
.split("/");
if (components.length < 3) {
throw Error(`Illegal url, invalid number of components: ${packageUrl}`);
}
if (components[1].length < 1 || components[2].length < 1) {
throw Error(`Illegal url, empty components: ${packageUrl}`);
}

const branchMatches = packageUrl.match(/(?<=github\.com\/[^/]+\/[^/]+)\/tree\/([^/]+)/);
const defaultBranch = branchMatches ? branchMatches[1] : undefined;

return {
baseUrl: "github.com",
owner: components[1],
name: components[2],
rootPath: components.filter((v, i) => i > 2 && v.length > 0).join("/") + "/",
defaultBranch,
};
}

0 comments on commit 9e719d6

Please sign in to comment.