mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 00:58:32 +02:00
Add prompt() plugin API (#121)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@yaakapp/api",
|
"name": "@yaakapp/api",
|
||||||
"version": "0.2.7",
|
"version": "0.2.11",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"typings": "./lib/index.d.ts",
|
"typings": "./lib/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { TemplateRenderRequest, TemplateRenderResponse } from '@yaakapp-internal/plugin';
|
import {
|
||||||
|
ShowPromptRequest,
|
||||||
|
ShowPromptResponse,
|
||||||
|
TemplateRenderRequest,
|
||||||
|
TemplateRenderResponse,
|
||||||
|
} from '@yaakapp-internal/plugin';
|
||||||
import {
|
import {
|
||||||
FindHttpResponsesRequest,
|
FindHttpResponsesRequest,
|
||||||
FindHttpResponsesResponse,
|
FindHttpResponsesResponse,
|
||||||
@@ -18,6 +23,9 @@ export type Context = {
|
|||||||
toast: {
|
toast: {
|
||||||
show(args: ShowToastRequest): void;
|
show(args: ShowToastRequest): void;
|
||||||
};
|
};
|
||||||
|
prompt: {
|
||||||
|
show(args: ShowPromptRequest): Promise<ShowPromptResponse['value']>;
|
||||||
|
};
|
||||||
httpRequest: {
|
httpRequest: {
|
||||||
send(args: SendHttpRequestRequest): Promise<SendHttpRequestResponse['httpResponse']>;
|
send(args: SendHttpRequestRequest): Promise<SendHttpRequestResponse['httpResponse']>;
|
||||||
getById(args: GetHttpRequestByIdRequest): Promise<GetHttpRequestByIdResponse['httpRequest']>;
|
getById(args: GetHttpRequestByIdRequest): Promise<GetHttpRequestByIdResponse['httpRequest']>;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
InternalEvent,
|
InternalEvent,
|
||||||
InternalEventPayload,
|
InternalEventPayload,
|
||||||
SendHttpRequestResponse,
|
SendHttpRequestResponse,
|
||||||
|
ShowPromptResponse,
|
||||||
TemplateFunction,
|
TemplateFunction,
|
||||||
} from '@yaakapp/api';
|
} from '@yaakapp/api';
|
||||||
import { HttpRequestActionPlugin } from '@yaakapp/api/lib/plugins/HttpRequestActionPlugin';
|
import { HttpRequestActionPlugin } from '@yaakapp/api/lib/plugins/HttpRequestActionPlugin';
|
||||||
@@ -138,6 +139,15 @@ async function initialize() {
|
|||||||
await sendAndWaitForReply(event.windowContext, { type: 'show_toast_request', ...args });
|
await sendAndWaitForReply(event.windowContext, { type: 'show_toast_request', ...args });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
prompt: {
|
||||||
|
async show(args) {
|
||||||
|
const reply: ShowPromptResponse = await sendAndWaitForReply(event.windowContext, {
|
||||||
|
type: 'show_prompt_request',
|
||||||
|
...args,
|
||||||
|
});
|
||||||
|
return reply.value;
|
||||||
|
},
|
||||||
|
},
|
||||||
httpResponse: {
|
httpResponse: {
|
||||||
async find(args) {
|
async find(args) {
|
||||||
const payload = { type: 'find_http_responses_request', ...args } as const;
|
const payload = { type: 'find_http_responses_request', ...args } as const;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use fern::colors::ColoredLevelConfig;
|
|||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use serde::Serialize;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use tauri::TitleBarStyle;
|
use tauri::TitleBarStyle;
|
||||||
@@ -62,7 +63,8 @@ use yaak_plugin_runtime::events::{
|
|||||||
BootResponse, CallHttpRequestActionRequest, FilterResponse, FindHttpResponsesResponse,
|
BootResponse, CallHttpRequestActionRequest, FilterResponse, FindHttpResponsesResponse,
|
||||||
GetHttpRequestActionsResponse, GetHttpRequestByIdResponse, GetTemplateFunctionsResponse, Icon,
|
GetHttpRequestActionsResponse, GetHttpRequestByIdResponse, GetTemplateFunctionsResponse, Icon,
|
||||||
InternalEvent, InternalEventPayload, RenderHttpRequestResponse, RenderPurpose,
|
InternalEvent, InternalEventPayload, RenderHttpRequestResponse, RenderPurpose,
|
||||||
SendHttpRequestResponse, ShowToastRequest, TemplateRenderResponse, WindowContext,
|
SendHttpRequestResponse, ShowPromptResponse, ShowToastRequest, TemplateRenderResponse,
|
||||||
|
WindowContext,
|
||||||
};
|
};
|
||||||
use yaak_plugin_runtime::plugin_handle::PluginHandle;
|
use yaak_plugin_runtime::plugin_handle::PluginHandle;
|
||||||
use yaak_templates::{Parser, Tokens};
|
use yaak_templates::{Parser, Tokens};
|
||||||
@@ -2158,6 +2160,40 @@ fn monitor_plugin_events<R: Runtime>(app_handle: &AppHandle<R>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct FrontendCall<T: Serialize + Clone> {
|
||||||
|
args: T,
|
||||||
|
reply_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn call_frontend<T: Serialize + Clone, R: Runtime>(
|
||||||
|
window: WebviewWindow<R>,
|
||||||
|
event_name: &str,
|
||||||
|
args: T,
|
||||||
|
) -> ShowPromptResponse {
|
||||||
|
let reply_id = format!("{event_name}_reply");
|
||||||
|
let payload = FrontendCall {
|
||||||
|
args,
|
||||||
|
reply_id: reply_id.clone(),
|
||||||
|
};
|
||||||
|
window.emit_to(window.label(), event_name, payload).unwrap();
|
||||||
|
let (tx, mut rx) = tokio::sync::watch::channel(ShowPromptResponse::default());
|
||||||
|
|
||||||
|
let event_id = window.clone().listen(reply_id, move |ev| {
|
||||||
|
println!("GOT REPLY {ev:?}");
|
||||||
|
let resp: ShowPromptResponse = serde_json::from_str(ev.payload()).unwrap();
|
||||||
|
_ = tx.send(resp);
|
||||||
|
});
|
||||||
|
|
||||||
|
// When reply shows up, unlisten to events and return
|
||||||
|
_ = rx.changed().await;
|
||||||
|
window.unlisten(event_id);
|
||||||
|
|
||||||
|
let foo = rx.borrow();
|
||||||
|
foo.clone()
|
||||||
|
}
|
||||||
|
|
||||||
async fn handle_plugin_event<R: Runtime>(
|
async fn handle_plugin_event<R: Runtime>(
|
||||||
app_handle: &AppHandle<R>,
|
app_handle: &AppHandle<R>,
|
||||||
event: &InternalEvent,
|
event: &InternalEvent,
|
||||||
@@ -2184,6 +2220,12 @@ async fn handle_plugin_event<R: Runtime>(
|
|||||||
};
|
};
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
InternalEventPayload::ShowPromptRequest(req) => {
|
||||||
|
let window = get_window_from_window_context(app_handle, &window_context)
|
||||||
|
.expect("Failed to find window for render");
|
||||||
|
let resp = call_frontend(window, "show_prompt", req).await;
|
||||||
|
Some(InternalEventPayload::ShowPromptResponse(resp))
|
||||||
|
}
|
||||||
InternalEventPayload::FindHttpResponsesRequest(req) => {
|
InternalEventPayload::FindHttpResponsesRequest(req) => {
|
||||||
let http_responses = list_http_responses(
|
let http_responses = list_http_responses(
|
||||||
app_handle,
|
app_handle,
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ impl TemplateCallback for PluginTemplateCallback {
|
|||||||
TemplateFunctionArg::Text(a) => a.base,
|
TemplateFunctionArg::Text(a) => a.base,
|
||||||
TemplateFunctionArg::Select(a) => a.base,
|
TemplateFunctionArg::Select(a) => a.base,
|
||||||
TemplateFunctionArg::Checkbox(a) => a.base,
|
TemplateFunctionArg::Checkbox(a) => a.base,
|
||||||
|
TemplateFunctionArg::File(a) => a.base,
|
||||||
TemplateFunctionArg::HttpRequest(a) => a.base,
|
TemplateFunctionArg::HttpRequest(a) => a.base,
|
||||||
};
|
};
|
||||||
if let None = args_with_defaults.get(base.name.as_str()) {
|
if let None = args_with_defaults.get(base.name.as_str()) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export type FilterRequest = { content: string, filter: string, };
|
|||||||
|
|
||||||
export type FilterResponse = { content: string, };
|
export type FilterResponse = { content: string, };
|
||||||
|
|
||||||
export type FindHttpResponsesRequest = { requestId: string, limit: number | null, };
|
export type FindHttpResponsesRequest = { requestId: string, limit?: number, };
|
||||||
|
|
||||||
export type FindHttpResponsesResponse = { httpResponses: Array<HttpResponse>, };
|
export type FindHttpResponsesResponse = { httpResponses: Array<HttpResponse>, };
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ export type GetHttpRequestByIdResponse = { httpRequest: HttpRequest | null, };
|
|||||||
|
|
||||||
export type GetTemplateFunctionsResponse = { functions: Array<TemplateFunction>, pluginRefId: string, };
|
export type GetTemplateFunctionsResponse = { functions: Array<TemplateFunction>, pluginRefId: string, };
|
||||||
|
|
||||||
export type HttpRequestAction = { key: string, label: string, icon: string | null, };
|
export type HttpRequestAction = { key: string, label: string, icon?: Icon, };
|
||||||
|
|
||||||
export type Icon = "copy" | "info" | "check_circle" | "alert_triangle";
|
export type Icon = "copy" | "info" | "check_circle" | "alert_triangle" | "_unknown";
|
||||||
|
|
||||||
export type ImportRequest = { content: string, };
|
export type ImportRequest = { content: string, };
|
||||||
|
|
||||||
@@ -59,7 +59,9 @@ export type ImportResponse = { resources: ImportResources, };
|
|||||||
|
|
||||||
export type InternalEvent = { id: string, pluginRefId: string, replyId: string | null, payload: InternalEventPayload, windowContext: WindowContext, };
|
export type InternalEvent = { id: string, pluginRefId: string, replyId: string | null, payload: InternalEventPayload, windowContext: WindowContext, };
|
||||||
|
|
||||||
export type InternalEventPayload = { "type": "boot_request" } & BootRequest | { "type": "boot_response" } & BootResponse | { "type": "reload_request" } | { "type": "reload_response" } | { "type": "terminate_request" } | { "type": "terminate_response" } | { "type": "import_request" } & ImportRequest | { "type": "import_response" } & ImportResponse | { "type": "filter_request" } & FilterRequest | { "type": "filter_response" } & FilterResponse | { "type": "export_http_request_request" } & ExportHttpRequestRequest | { "type": "export_http_request_response" } & ExportHttpRequestResponse | { "type": "send_http_request_request" } & SendHttpRequestRequest | { "type": "send_http_request_response" } & SendHttpRequestResponse | { "type": "get_http_request_actions_request" } & GetHttpRequestActionsRequest | { "type": "get_http_request_actions_response" } & GetHttpRequestActionsResponse | { "type": "call_http_request_action_request" } & CallHttpRequestActionRequest | { "type": "get_template_functions_request" } | { "type": "get_template_functions_response" } & GetTemplateFunctionsResponse | { "type": "call_template_function_request" } & CallTemplateFunctionRequest | { "type": "call_template_function_response" } & CallTemplateFunctionResponse | { "type": "copy_text_request" } & CopyTextRequest | { "type": "render_http_request_request" } & RenderHttpRequestRequest | { "type": "render_http_request_response" } & RenderHttpRequestResponse | { "type": "template_render_request" } & TemplateRenderRequest | { "type": "template_render_response" } & TemplateRenderResponse | { "type": "show_toast_request" } & ShowToastRequest | { "type": "get_http_request_by_id_request" } & GetHttpRequestByIdRequest | { "type": "get_http_request_by_id_response" } & GetHttpRequestByIdResponse | { "type": "find_http_responses_request" } & FindHttpResponsesRequest | { "type": "find_http_responses_response" } & FindHttpResponsesResponse | { "type": "empty_response" };
|
export type InternalEventPayload = { "type": "boot_request" } & BootRequest | { "type": "boot_response" } & BootResponse | { "type": "reload_request" } | { "type": "reload_response" } | { "type": "terminate_request" } | { "type": "terminate_response" } | { "type": "import_request" } & ImportRequest | { "type": "import_response" } & ImportResponse | { "type": "filter_request" } & FilterRequest | { "type": "filter_response" } & FilterResponse | { "type": "export_http_request_request" } & ExportHttpRequestRequest | { "type": "export_http_request_response" } & ExportHttpRequestResponse | { "type": "send_http_request_request" } & SendHttpRequestRequest | { "type": "send_http_request_response" } & SendHttpRequestResponse | { "type": "get_http_request_actions_request" } & GetHttpRequestActionsRequest | { "type": "get_http_request_actions_response" } & GetHttpRequestActionsResponse | { "type": "call_http_request_action_request" } & CallHttpRequestActionRequest | { "type": "get_template_functions_request" } | { "type": "get_template_functions_response" } & GetTemplateFunctionsResponse | { "type": "call_template_function_request" } & CallTemplateFunctionRequest | { "type": "call_template_function_response" } & CallTemplateFunctionResponse | { "type": "copy_text_request" } & CopyTextRequest | { "type": "render_http_request_request" } & RenderHttpRequestRequest | { "type": "render_http_request_response" } & RenderHttpRequestResponse | { "type": "template_render_request" } & TemplateRenderRequest | { "type": "template_render_response" } & TemplateRenderResponse | { "type": "show_toast_request" } & ShowToastRequest | { "type": "show_prompt_request" } & ShowPromptRequest | { "type": "show_prompt_response" } & ShowPromptResponse | { "type": "get_http_request_by_id_request" } & GetHttpRequestByIdRequest | { "type": "get_http_request_by_id_response" } & GetHttpRequestByIdResponse | { "type": "find_http_responses_request" } & FindHttpResponsesRequest | { "type": "find_http_responses_response" } & FindHttpResponsesResponse | { "type": "empty_response" };
|
||||||
|
|
||||||
|
export type OpenFileFilter = { name: string, extensions: Array<string>, };
|
||||||
|
|
||||||
export type RenderHttpRequestRequest = { httpRequest: HttpRequest, purpose: RenderPurpose, };
|
export type RenderHttpRequestRequest = { httpRequest: HttpRequest, purpose: RenderPurpose, };
|
||||||
|
|
||||||
@@ -71,23 +73,41 @@ export type SendHttpRequestRequest = { httpRequest: HttpRequest, };
|
|||||||
|
|
||||||
export type SendHttpRequestResponse = { httpResponse: HttpResponse, };
|
export type SendHttpRequestResponse = { httpResponse: HttpResponse, };
|
||||||
|
|
||||||
export type ShowToastRequest = { message: string, color?: Color | null, icon?: Icon | null, };
|
export type ShowPromptRequest = { id: string, title: string, label: string, description?: string, defaultValue?: string, placeholder?: string,
|
||||||
|
/**
|
||||||
|
* Text to add to the confirmation button
|
||||||
|
*/
|
||||||
|
confirmText?: string,
|
||||||
|
/**
|
||||||
|
* Text to add to the cancel button
|
||||||
|
*/
|
||||||
|
cancelText?: string,
|
||||||
|
/**
|
||||||
|
* Require the user to enter a non-empty value
|
||||||
|
*/
|
||||||
|
require?: boolean, };
|
||||||
|
|
||||||
export type TemplateFunction = { name: string, aliases: Array<string>, args: Array<TemplateFunctionArg>, };
|
export type ShowPromptResponse = { value: string, };
|
||||||
|
|
||||||
export type TemplateFunctionArg = { "type": "text" } & TemplateFunctionTextArg | { "type": "select" } & TemplateFunctionSelectArg | { "type": "checkbox" } & TemplateFunctionCheckboxArg | { "type": "http_request" } & TemplateFunctionHttpRequestArg;
|
export type ShowToastRequest = { message: string, color?: Color, icon?: Icon, };
|
||||||
|
|
||||||
export type TemplateFunctionBaseArg = { name: string, optional?: boolean | null, label?: string | null, defaultValue?: string | null, };
|
export type TemplateFunction = { name: string, aliases?: Array<string>, args: Array<TemplateFunctionArg>, };
|
||||||
|
|
||||||
export type TemplateFunctionCheckboxArg = { name: string, optional?: boolean | null, label?: string | null, defaultValue?: string | null, };
|
export type TemplateFunctionArg = { "type": "text" } & TemplateFunctionTextArg | { "type": "select" } & TemplateFunctionSelectArg | { "type": "checkbox" } & TemplateFunctionCheckboxArg | { "type": "http_request" } & TemplateFunctionHttpRequestArg | { "type": "file" } & TemplateFunctionFileArg;
|
||||||
|
|
||||||
export type TemplateFunctionHttpRequestArg = { name: string, optional?: boolean | null, label?: string | null, defaultValue?: string | null, };
|
export type TemplateFunctionBaseArg = { name: string, optional?: boolean, label?: string, defaultValue?: string, };
|
||||||
|
|
||||||
export type TemplateFunctionSelectArg = { options: Array<TemplateFunctionSelectOption>, name: string, optional?: boolean | null, label?: string | null, defaultValue?: string | null, };
|
export type TemplateFunctionCheckboxArg = { name: string, optional?: boolean, label?: string, defaultValue?: string, };
|
||||||
|
|
||||||
|
export type TemplateFunctionFileArg = { title: string, multiple?: boolean, directory?: boolean, defaultPath?: string, filters?: Array<OpenFileFilter>, name: string, optional?: boolean, label?: string, defaultValue?: string, };
|
||||||
|
|
||||||
|
export type TemplateFunctionHttpRequestArg = { name: string, optional?: boolean, label?: string, defaultValue?: string, };
|
||||||
|
|
||||||
|
export type TemplateFunctionSelectArg = { options: Array<TemplateFunctionSelectOption>, name: string, optional?: boolean, label?: string, defaultValue?: string, };
|
||||||
|
|
||||||
export type TemplateFunctionSelectOption = { name: string, value: string, };
|
export type TemplateFunctionSelectOption = { name: string, value: string, };
|
||||||
|
|
||||||
export type TemplateFunctionTextArg = { placeholder?: string | null, name: string, optional?: boolean | null, label?: string | null, defaultValue?: string | null, };
|
export type TemplateFunctionTextArg = { placeholder?: string, name: string, optional?: boolean, label?: string, defaultValue?: string, };
|
||||||
|
|
||||||
export type TemplateRenderRequest = { data: JsonValue, purpose: RenderPurpose, };
|
export type TemplateRenderRequest = { data: JsonValue, purpose: RenderPurpose, };
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ pub enum InternalEventPayload {
|
|||||||
|
|
||||||
ShowToastRequest(ShowToastRequest),
|
ShowToastRequest(ShowToastRequest),
|
||||||
|
|
||||||
|
ShowPromptRequest(ShowPromptRequest),
|
||||||
|
ShowPromptResponse(ShowPromptResponse),
|
||||||
|
|
||||||
GetHttpRequestByIdRequest(GetHttpRequestByIdRequest),
|
GetHttpRequestByIdRequest(GetHttpRequestByIdRequest),
|
||||||
GetHttpRequestByIdResponse(GetHttpRequestByIdResponse),
|
GetHttpRequestByIdResponse(GetHttpRequestByIdResponse),
|
||||||
|
|
||||||
@@ -203,12 +206,46 @@ pub struct TemplateRenderResponse {
|
|||||||
#[ts(export, export_to = "events.ts")]
|
#[ts(export, export_to = "events.ts")]
|
||||||
pub struct ShowToastRequest {
|
pub struct ShowToastRequest {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
#[ts(optional = nullable)]
|
#[ts(optional)]
|
||||||
pub color: Option<Color>,
|
pub color: Option<Color>,
|
||||||
#[ts(optional = nullable)]
|
#[ts(optional)]
|
||||||
pub icon: Option<Icon>,
|
pub icon: Option<Icon>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
|
#[serde(default, rename_all = "camelCase")]
|
||||||
|
#[ts(export, export_to = "events.ts")]
|
||||||
|
pub struct ShowPromptRequest {
|
||||||
|
// A unique ID to identify the prompt (eg. "enter-password")
|
||||||
|
pub id: String,
|
||||||
|
// Title to show on the prompt dialog
|
||||||
|
pub title: String,
|
||||||
|
// Text to show on the label above the input
|
||||||
|
pub label: String,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub description: Option<String>,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub default_value: Option<String>,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub placeholder: Option<String>,
|
||||||
|
/// Text to add to the confirmation button
|
||||||
|
#[ts(optional)]
|
||||||
|
pub confirm_text: Option<String>,
|
||||||
|
/// Text to add to the cancel button
|
||||||
|
#[ts(optional)]
|
||||||
|
pub cancel_text: Option<String>,
|
||||||
|
/// Require the user to enter a non-empty value
|
||||||
|
#[ts(optional)]
|
||||||
|
pub require: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
|
#[serde(default, rename_all = "camelCase")]
|
||||||
|
#[ts(export, export_to = "events.ts")]
|
||||||
|
pub struct ShowPromptResponse {
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[ts(export, export_to = "events.ts")]
|
#[ts(export, export_to = "events.ts")]
|
||||||
@@ -238,6 +275,10 @@ pub enum Icon {
|
|||||||
Info,
|
Info,
|
||||||
CheckCircle,
|
CheckCircle,
|
||||||
AlertTriangle,
|
AlertTriangle,
|
||||||
|
|
||||||
|
#[serde(untagged)]
|
||||||
|
#[ts(type = "\"_unknown\"")]
|
||||||
|
_Unknown(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
@@ -253,7 +294,8 @@ pub struct GetTemplateFunctionsResponse {
|
|||||||
#[ts(export, export_to = "events.ts")]
|
#[ts(export, export_to = "events.ts")]
|
||||||
pub struct TemplateFunction {
|
pub struct TemplateFunction {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub aliases: Vec<String>,
|
#[ts(optional)]
|
||||||
|
pub aliases: Option<Vec<String>>,
|
||||||
pub args: Vec<TemplateFunctionArg>,
|
pub args: Vec<TemplateFunctionArg>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,6 +307,7 @@ pub enum TemplateFunctionArg {
|
|||||||
Select(TemplateFunctionSelectArg),
|
Select(TemplateFunctionSelectArg),
|
||||||
Checkbox(TemplateFunctionCheckboxArg),
|
Checkbox(TemplateFunctionCheckboxArg),
|
||||||
HttpRequest(TemplateFunctionHttpRequestArg),
|
HttpRequest(TemplateFunctionHttpRequestArg),
|
||||||
|
File(TemplateFunctionFileArg),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
@@ -272,11 +315,11 @@ pub enum TemplateFunctionArg {
|
|||||||
#[ts(export, export_to = "events.ts")]
|
#[ts(export, export_to = "events.ts")]
|
||||||
pub struct TemplateFunctionBaseArg {
|
pub struct TemplateFunctionBaseArg {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[ts(optional = nullable)]
|
#[ts(optional)]
|
||||||
pub optional: Option<bool>,
|
pub optional: Option<bool>,
|
||||||
#[ts(optional = nullable)]
|
#[ts(optional)]
|
||||||
pub label: Option<String>,
|
pub label: Option<String>,
|
||||||
#[ts(optional = nullable)]
|
#[ts(optional)]
|
||||||
pub default_value: Option<String>,
|
pub default_value: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +329,7 @@ pub struct TemplateFunctionBaseArg {
|
|||||||
pub struct TemplateFunctionTextArg {
|
pub struct TemplateFunctionTextArg {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub base: TemplateFunctionBaseArg,
|
pub base: TemplateFunctionBaseArg,
|
||||||
#[ts(optional = nullable)]
|
#[ts(optional)]
|
||||||
pub placeholder: Option<String>,
|
pub placeholder: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,6 +341,31 @@ pub struct TemplateFunctionHttpRequestArg {
|
|||||||
pub base: TemplateFunctionBaseArg,
|
pub base: TemplateFunctionBaseArg,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
|
#[serde(default, rename_all = "camelCase")]
|
||||||
|
#[ts(export, export_to = "events.ts")]
|
||||||
|
pub struct TemplateFunctionFileArg {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub base: TemplateFunctionBaseArg,
|
||||||
|
pub title: String,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub multiple: Option<bool>,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub directory: Option<bool>,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub default_path: Option<String>,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub filters: Option<Vec<OpenFileFilter>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
|
#[serde(default, rename_all = "camelCase")]
|
||||||
|
#[ts(export, export_to = "events.ts")]
|
||||||
|
pub struct OpenFileFilter {
|
||||||
|
pub name: String,
|
||||||
|
pub extensions: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
#[serde(default, rename_all = "camelCase")]
|
#[serde(default, rename_all = "camelCase")]
|
||||||
#[ts(export, export_to = "events.ts")]
|
#[ts(export, export_to = "events.ts")]
|
||||||
@@ -379,7 +447,8 @@ pub struct GetHttpRequestActionsResponse {
|
|||||||
pub struct HttpRequestAction {
|
pub struct HttpRequestAction {
|
||||||
pub key: String,
|
pub key: String,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub icon: Option<String>,
|
#[ts(optional)]
|
||||||
|
pub icon: Option<Icon>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
@@ -417,6 +486,7 @@ pub struct GetHttpRequestByIdResponse {
|
|||||||
#[ts(export, export_to = "events.ts")]
|
#[ts(export, export_to = "events.ts")]
|
||||||
pub struct FindHttpResponsesRequest {
|
pub struct FindHttpResponsesRequest {
|
||||||
pub request_id: String,
|
pub request_id: String,
|
||||||
|
#[ts(optional)]
|
||||||
pub limit: Option<i32>,
|
pub limit: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ impl PluginManager {
|
|||||||
};
|
};
|
||||||
let plugin_handle = PluginHandle::new(dir, tx.clone());
|
let plugin_handle = PluginHandle::new(dir, tx.clone());
|
||||||
|
|
||||||
// Add the new plugin
|
// Add the new plugin
|
||||||
self.plugins.lock().await.push(plugin_handle.clone());
|
self.plugins.lock().await.push(plugin_handle.clone());
|
||||||
|
|
||||||
// Boot the plugin
|
// Boot the plugin
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ export function CookieDropdown() {
|
|||||||
Enter a new name for <InlineCode>{activeCookieJar?.name}</InlineCode>
|
Enter a new name for <InlineCode>{activeCookieJar?.name}</InlineCode>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
name: 'name',
|
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
|
confirmText: 'Save',
|
||||||
placeholder: 'New name',
|
placeholder: 'New name',
|
||||||
defaultValue: activeCookieJar?.name,
|
defaultValue: activeCookieJar?.name,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -274,8 +274,8 @@ function SidebarButton({
|
|||||||
Enter a new name for <InlineCode>{environment.name}</InlineCode>
|
Enter a new name for <InlineCode>{environment.name}</InlineCode>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
name: 'name',
|
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
|
confirmText: 'Save',
|
||||||
placeholder: 'New Name',
|
placeholder: 'New Name',
|
||||||
defaultValue: environment.name,
|
defaultValue: environment.name,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { emit } from '@tauri-apps/api/event';
|
||||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||||
import type { AnyModel } from '@yaakapp-internal/models';
|
import type { AnyModel } from '@yaakapp-internal/models';
|
||||||
|
import type { ShowPromptRequest, ShowPromptResponse } from '@yaakapp-internal/plugin';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useEnsureActiveCookieJar, useMigrateActiveCookieJarId } from '../hooks/useActiveCookieJar';
|
import { useEnsureActiveCookieJar, useMigrateActiveCookieJarId } from '../hooks/useActiveCookieJar';
|
||||||
@@ -19,6 +21,7 @@ import { keyValueQueryKey } from '../hooks/useKeyValue';
|
|||||||
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
||||||
import { useNotificationToast } from '../hooks/useNotificationToast';
|
import { useNotificationToast } from '../hooks/useNotificationToast';
|
||||||
import { pluginsAtom } from '../hooks/usePlugins';
|
import { pluginsAtom } from '../hooks/usePlugins';
|
||||||
|
import { usePrompt } from '../hooks/usePrompt';
|
||||||
import { useRecentCookieJars } from '../hooks/useRecentCookieJars';
|
import { useRecentCookieJars } from '../hooks/useRecentCookieJars';
|
||||||
import { useRecentEnvironments } from '../hooks/useRecentEnvironments';
|
import { useRecentEnvironments } from '../hooks/useRecentEnvironments';
|
||||||
import { useRecentRequests } from '../hooks/useRecentRequests';
|
import { useRecentRequests } from '../hooks/useRecentRequests';
|
||||||
@@ -176,6 +179,16 @@ export function GlobalHooks() {
|
|||||||
useHotKey('app.zoom_reset', zoom.zoomReset);
|
useHotKey('app.zoom_reset', zoom.zoomReset);
|
||||||
useListenToTauriEvent('zoom_reset', zoom.zoomReset);
|
useListenToTauriEvent('zoom_reset', zoom.zoomReset);
|
||||||
|
|
||||||
|
const prompt = usePrompt();
|
||||||
|
useListenToTauriEvent<{ replyId: string; args: ShowPromptRequest }>(
|
||||||
|
'show_prompt',
|
||||||
|
async (event) => {
|
||||||
|
const value = await prompt(event.payload.args);
|
||||||
|
const result: ShowPromptResponse = { value };
|
||||||
|
await emit(event.payload.replyId, result);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const copy = useCopy();
|
const copy = useCopy();
|
||||||
useListenToTauriEvent('generate_theme_css', () => {
|
useListenToTauriEvent('generate_theme_css', () => {
|
||||||
const themesCss = [
|
const themesCss = [
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ export const RequestMethodDropdown = memo(function RequestMethodDropdown({
|
|||||||
const newMethod = await prompt({
|
const newMethod = await prompt({
|
||||||
id: 'custom-method',
|
id: 'custom-method',
|
||||||
label: 'Http Method',
|
label: 'Http Method',
|
||||||
name: 'httpMethod',
|
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
title: 'Custom Method',
|
title: 'Custom Method',
|
||||||
|
confirmText: 'Save',
|
||||||
description: 'Enter a custom method name',
|
description: 'Enter a custom method name',
|
||||||
placeholder: 'CUSTOM',
|
placeholder: 'CUSTOM',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -762,7 +762,7 @@ function SidebarItem({
|
|||||||
Enter a new name for <InlineCode>{itemName}</InlineCode>
|
Enter a new name for <InlineCode>{itemName}</InlineCode>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
name: 'name',
|
confirmText: 'Save',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
placeholder: 'New Name',
|
placeholder: 'New Name',
|
||||||
defaultValue: itemName,
|
defaultValue: itemName,
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ export function TemplateFunctionDialog({ templateFunction, hide, initialTokens,
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack className="pb-3" space={4}>
|
<VStack className="pb-3" space={4}>
|
||||||
|
<h1 className="font-mono !text-base">{templateFunction.name}(…)</h1>
|
||||||
<VStack space={2}>
|
<VStack space={2}>
|
||||||
{templateFunction.args.map((a: TemplateFunctionArg, i: number) => {
|
{templateFunction.args.map((a: TemplateFunctionArg, i: number) => {
|
||||||
switch (a.type) {
|
switch (a.type) {
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
|
|||||||
Enter a new name for <InlineCode>{activeWorkspace?.name}</InlineCode>
|
Enter a new name for <InlineCode>{activeWorkspace?.name}</InlineCode>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
name: 'name',
|
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
placeholder: 'New Name',
|
placeholder: 'New Name',
|
||||||
defaultValue: activeWorkspace?.name,
|
defaultValue: activeWorkspace?.name,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export type TwigCompletionOptionNamespace = {
|
|||||||
|
|
||||||
export type TwigCompletionOptionFunction = {
|
export type TwigCompletionOptionFunction = {
|
||||||
args: { name: string }[];
|
args: { name: string }[];
|
||||||
aliases: string[];
|
aliases?: string[];
|
||||||
type: 'function';
|
type: 'function';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ export function twigCompletion({ options }: TwigCompletionConfig) {
|
|||||||
if (matchSegments.length < optionSegments.length) {
|
if (matchSegments.length < optionSegments.length) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: optionSegments.slice(0, matchSegments.length).join('.'),
|
label: optionSegments.slice(0, matchSegments.length).join('.') + '…',
|
||||||
apply: optionSegments.slice(0, matchSegments.length).join('.'),
|
apply: optionSegments.slice(0, matchSegments.length).join('.'),
|
||||||
type: 'namespace',
|
type: 'namespace',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export type InputProps = Omit<
|
|||||||
| 'onKeyDown'
|
| 'onKeyDown'
|
||||||
| 'readOnly'
|
| 'readOnly'
|
||||||
> & {
|
> & {
|
||||||
name: string;
|
name?: string;
|
||||||
type?: 'text' | 'password';
|
type?: 'text' | 'password';
|
||||||
label: string;
|
label: string;
|
||||||
hideLabel?: boolean;
|
hideLabel?: boolean;
|
||||||
@@ -41,7 +41,7 @@ export type InputProps = Omit<
|
|||||||
rightSlot?: ReactNode;
|
rightSlot?: ReactNode;
|
||||||
size?: 'xs' | 'sm' | 'md' | 'auto';
|
size?: 'xs' | 'sm' | 'md' | 'auto';
|
||||||
className?: string;
|
className?: string;
|
||||||
placeholder: string;
|
placeholder?: string;
|
||||||
validate?: boolean | ((v: string) => boolean);
|
validate?: boolean | ((v: string) => boolean);
|
||||||
require?: boolean;
|
require?: boolean;
|
||||||
wrapLines?: boolean;
|
wrapLines?: boolean;
|
||||||
|
|||||||
@@ -519,8 +519,7 @@ function PairEditorRow({
|
|||||||
label: 'Content-Type',
|
label: 'Content-Type',
|
||||||
placeholder: 'text/plain',
|
placeholder: 'text/plain',
|
||||||
defaultValue: pairContainer.pair.contentType ?? '',
|
defaultValue: pairContainer.pair.contentType ?? '',
|
||||||
name: 'content-type',
|
confirmText: 'Set',
|
||||||
confirmLabel: 'Set',
|
|
||||||
description: 'Leave blank to auto-detect',
|
description: 'Leave blank to auto-detect',
|
||||||
});
|
});
|
||||||
handleChangeValueContentType(v);
|
handleChangeValueContentType(v);
|
||||||
|
|||||||
@@ -1,30 +1,25 @@
|
|||||||
import type { FormEvent } from 'react';
|
import type { ShowPromptRequest } from '@yaakapp-internal/plugin';
|
||||||
|
import type { FormEvent, ReactNode } from 'react';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { Button } from '../components/core/Button';
|
import { Button } from '../components/core/Button';
|
||||||
import type { InputProps } from '../components/core/Input';
|
|
||||||
import { PlainInput } from '../components/core/PlainInput';
|
import { PlainInput } from '../components/core/PlainInput';
|
||||||
import { HStack } from '../components/core/Stacks';
|
import { HStack } from '../components/core/Stacks';
|
||||||
|
|
||||||
export interface PromptProps {
|
export type PromptProps = Omit<ShowPromptRequest, 'id' | 'title' | 'description'> & {
|
||||||
|
description?: ReactNode;
|
||||||
onHide: () => void;
|
onHide: () => void;
|
||||||
onResult: (value: string) => void;
|
onResult: (value: string) => void;
|
||||||
label: InputProps['label'];
|
};
|
||||||
name: InputProps['name'];
|
|
||||||
defaultValue: InputProps['defaultValue'];
|
|
||||||
placeholder: InputProps['placeholder'];
|
|
||||||
require?: InputProps['require'];
|
|
||||||
confirmLabel?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Prompt({
|
export function Prompt({
|
||||||
onHide,
|
onHide,
|
||||||
label,
|
label,
|
||||||
name,
|
|
||||||
defaultValue,
|
defaultValue,
|
||||||
placeholder,
|
placeholder,
|
||||||
onResult,
|
onResult,
|
||||||
require = true,
|
require,
|
||||||
confirmLabel = 'Save',
|
confirmText,
|
||||||
|
cancelText,
|
||||||
}: PromptProps) {
|
}: PromptProps) {
|
||||||
const [value, setValue] = useState<string>(defaultValue ?? '');
|
const [value, setValue] = useState<string>(defaultValue ?? '');
|
||||||
const handleSubmit = useCallback(
|
const handleSubmit = useCallback(
|
||||||
@@ -45,18 +40,17 @@ export function Prompt({
|
|||||||
hideLabel
|
hideLabel
|
||||||
autoSelect
|
autoSelect
|
||||||
require={require}
|
require={require}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder ?? 'Enter text'}
|
||||||
label={label}
|
label={label}
|
||||||
name={name}
|
|
||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
onChange={setValue}
|
onChange={setValue}
|
||||||
/>
|
/>
|
||||||
<HStack space={2} justifyContent="end">
|
<HStack space={2} justifyContent="end">
|
||||||
<Button onClick={onHide} variant="border" color="secondary">
|
<Button onClick={onHide} variant="border" color="secondary">
|
||||||
Cancel
|
{cancelText || 'Cancel'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" color="primary">
|
<Button type="submit" color="primary">
|
||||||
{confirmLabel}
|
{confirmText || 'Done'}
|
||||||
</Button>
|
</Button>
|
||||||
</HStack>
|
</HStack>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ export function useCreateCookieJar() {
|
|||||||
}
|
}
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
id: 'new-cookie-jar',
|
id: 'new-cookie-jar',
|
||||||
name: 'name',
|
|
||||||
title: 'New CookieJar',
|
title: 'New CookieJar',
|
||||||
placeholder: 'My Jar',
|
placeholder: 'My Jar',
|
||||||
|
confirmText: 'Create',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
defaultValue: 'My Jar',
|
defaultValue: 'My Jar',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ export function useCreateEnvironment() {
|
|||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
id: 'new-environment',
|
id: 'new-environment',
|
||||||
name: 'name',
|
|
||||||
title: 'New Environment',
|
title: 'New Environment',
|
||||||
description: 'Create multiple environments with different sets of variables',
|
description: 'Create multiple environments with different sets of variables',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
placeholder: 'My Environment',
|
placeholder: 'My Environment',
|
||||||
defaultValue: 'My Environment',
|
defaultValue: 'My Environment',
|
||||||
|
confirmText: 'Create',
|
||||||
});
|
});
|
||||||
return invokeCmd('cmd_create_environment', {
|
return invokeCmd('cmd_create_environment', {
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -19,11 +19,10 @@ export function useCreateFolder() {
|
|||||||
patch.name ||
|
patch.name ||
|
||||||
(await prompt({
|
(await prompt({
|
||||||
id: 'new-folder',
|
id: 'new-folder',
|
||||||
name: 'name',
|
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
defaultValue: 'Folder',
|
defaultValue: 'Folder',
|
||||||
title: 'New Folder',
|
title: 'New Folder',
|
||||||
confirmLabel: 'Create',
|
confirmText: 'Create',
|
||||||
placeholder: 'Name',
|
placeholder: 'Name',
|
||||||
}));
|
}));
|
||||||
patch.sortPriority = patch.sortPriority || -Date.now();
|
patch.sortPriority = patch.sortPriority || -Date.now();
|
||||||
|
|||||||
@@ -12,12 +12,11 @@ export function useCreateWorkspace() {
|
|||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
id: 'new-workspace',
|
id: 'new-workspace',
|
||||||
name: 'name',
|
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
defaultValue: 'My Workspace',
|
defaultValue: 'My Workspace',
|
||||||
title: 'New Workspace',
|
title: 'New Workspace',
|
||||||
confirmLabel: 'Create',
|
|
||||||
placeholder: 'My Workspace',
|
placeholder: 'My Workspace',
|
||||||
|
confirmText: 'Create',
|
||||||
});
|
});
|
||||||
return invokeCmd('cmd_create_workspace', { name });
|
return invokeCmd('cmd_create_workspace', { name });
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export function useHttpRequestActions() {
|
|||||||
const responses = (await invokeCmd(
|
const responses = (await invokeCmd(
|
||||||
'cmd_http_request_actions',
|
'cmd_http_request_actions',
|
||||||
)) as GetHttpRequestActionsResponse[];
|
)) as GetHttpRequestActionsResponse[];
|
||||||
|
console.log('REQUEST ACTIONS', responses);
|
||||||
return responses;
|
return responses;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,20 +3,12 @@ import { useDialog } from '../components/DialogContext';
|
|||||||
import type { PromptProps } from './Prompt';
|
import type { PromptProps } from './Prompt';
|
||||||
import { Prompt } from './Prompt';
|
import { Prompt } from './Prompt';
|
||||||
|
|
||||||
|
type Props = Pick<DialogProps, 'title' | 'description'> &
|
||||||
|
Omit<PromptProps, 'onResult' | 'onHide'> & { id: string };
|
||||||
|
|
||||||
export function usePrompt() {
|
export function usePrompt() {
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
return ({
|
return ({ id, title, description, ...props }: Props) =>
|
||||||
id,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
name,
|
|
||||||
label,
|
|
||||||
defaultValue,
|
|
||||||
placeholder,
|
|
||||||
confirmLabel,
|
|
||||||
require,
|
|
||||||
}: Pick<DialogProps, 'title' | 'description'> &
|
|
||||||
Omit<PromptProps, 'onResult' | 'onHide'> & { id: string }) =>
|
|
||||||
new Promise((onResult: PromptProps['onResult']) => {
|
new Promise((onResult: PromptProps['onResult']) => {
|
||||||
dialog.show({
|
dialog.show({
|
||||||
id,
|
id,
|
||||||
@@ -24,17 +16,7 @@ export function usePrompt() {
|
|||||||
description,
|
description,
|
||||||
hideX: true,
|
hideX: true,
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
render: ({ hide }) =>
|
render: ({ hide: onHide }) => Prompt({ onHide, onResult, ...props }),
|
||||||
Prompt({
|
|
||||||
onHide: hide,
|
|
||||||
onResult,
|
|
||||||
name,
|
|
||||||
label,
|
|
||||||
defaultValue,
|
|
||||||
placeholder,
|
|
||||||
confirmLabel,
|
|
||||||
require,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ export function useRenameRequest(requestId: string | null) {
|
|||||||
Enter a new name for <InlineCode>{request.name}</InlineCode>
|
Enter a new name for <InlineCode>{request.name}</InlineCode>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
name: 'name',
|
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
placeholder: 'New Name',
|
placeholder: 'New Name',
|
||||||
defaultValue: request.name,
|
defaultValue: request.name,
|
||||||
|
confirmText: 'Save',
|
||||||
});
|
});
|
||||||
if (request.model === 'http_request') {
|
if (request.model === 'http_request') {
|
||||||
updateHttpRequest.mutate({ id: request.id, update: (r: HttpRequest) => ({ ...r, name }) });
|
updateHttpRequest.mutate({ id: request.id, update: (r: HttpRequest) => ({ ...r, name }) });
|
||||||
|
|||||||
Reference in New Issue
Block a user