mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-10 09:33:15 +00:00
prefill site field on create private resource when filtering sites
This commit is contained in:
@@ -23,19 +23,22 @@ import {
|
||||
isHostname,
|
||||
type InternalResourceFormValues
|
||||
} from "./PrivateResourceForm";
|
||||
import type { Selectedsite } from "./site-selector";
|
||||
|
||||
type CreateInternalResourceDialogProps = {
|
||||
open: boolean;
|
||||
setOpen: (val: boolean) => void;
|
||||
orgId: string;
|
||||
onSuccess?: () => void;
|
||||
initialSites?: Selectedsite[];
|
||||
};
|
||||
|
||||
export default function CreatePrivateResourceDialog({
|
||||
open,
|
||||
setOpen,
|
||||
orgId,
|
||||
onSuccess
|
||||
onSuccess,
|
||||
initialSites
|
||||
}: CreateInternalResourceDialogProps) {
|
||||
const t = useTranslations();
|
||||
const api = createApiClient(useEnvContext());
|
||||
@@ -175,6 +178,7 @@ export default function CreatePrivateResourceDialog({
|
||||
formId="create-internal-resource-form"
|
||||
onSubmit={handleSubmit}
|
||||
onSubmitDisabledChange={setIsHttpModeDisabled}
|
||||
initialSites={initialSites}
|
||||
/>
|
||||
</CredenzaBody>
|
||||
<CredenzaFooter>
|
||||
|
||||
@@ -208,6 +208,7 @@ type InternalResourceFormProps = {
|
||||
formId: string;
|
||||
onSubmit: (values: InternalResourceFormValues) => void | Promise<void>;
|
||||
onSubmitDisabledChange?: (disabled: boolean) => void;
|
||||
initialSites?: Selectedsite[];
|
||||
};
|
||||
|
||||
export function PrivateResourceForm({
|
||||
@@ -218,7 +219,8 @@ export function PrivateResourceForm({
|
||||
siteResourceId,
|
||||
formId,
|
||||
onSubmit,
|
||||
onSubmitDisabledChange
|
||||
onSubmitDisabledChange,
|
||||
initialSites = []
|
||||
}: InternalResourceFormProps) {
|
||||
const t = useTranslations();
|
||||
const { env } = useEnvContext();
|
||||
@@ -609,6 +611,8 @@ export function PrivateResourceForm({
|
||||
authDaemonMode === "remote";
|
||||
const hasInitialized = useRef(false);
|
||||
const previousResourceId = useRef<number | null>(null);
|
||||
const initialSitesRef = useRef(initialSites);
|
||||
initialSitesRef.current = initialSites;
|
||||
|
||||
useEffect(() => {
|
||||
const tcpValue = getPortStringFromMode(tcpPortMode, tcpCustomPorts);
|
||||
@@ -623,9 +627,13 @@ export function PrivateResourceForm({
|
||||
// Reset when create dialog opens
|
||||
useEffect(() => {
|
||||
if (variant === "create" && open) {
|
||||
const prefillSites =
|
||||
initialSitesRef.current.length > 0
|
||||
? initialSitesRef.current
|
||||
: [];
|
||||
form.reset({
|
||||
name: "",
|
||||
siteIds: [],
|
||||
siteIds: prefillSites.map((s) => s.siteId),
|
||||
mode: "host",
|
||||
destination: "",
|
||||
alias: null,
|
||||
@@ -645,7 +653,7 @@ export function PrivateResourceForm({
|
||||
users: [],
|
||||
clients: []
|
||||
});
|
||||
setSelectedSites([]);
|
||||
setSelectedSites(prefillSites);
|
||||
setSshServerMode("native");
|
||||
setTcpPortMode("all");
|
||||
setUdpPortMode("all");
|
||||
|
||||
@@ -187,6 +187,11 @@ export default function PrivateResourcesTable({
|
||||
};
|
||||
}, [initialFilterSite, siteIdQ, siteIdNum, t]);
|
||||
|
||||
const createInitialSites = useMemo(
|
||||
() => (selectedSite ? [selectedSite] : undefined),
|
||||
[selectedSite]
|
||||
);
|
||||
|
||||
const refreshData = () => {
|
||||
startRefreshTransition(() => {
|
||||
try {
|
||||
@@ -686,6 +691,7 @@ export default function PrivateResourcesTable({
|
||||
open={isCreateDialogOpen}
|
||||
setOpen={setIsCreateDialogOpen}
|
||||
orgId={orgId}
|
||||
initialSites={createInitialSites}
|
||||
onSuccess={() => {
|
||||
// Delay refresh to allow modal to close smoothly
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user