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