mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
chore: remove coder/preview dependency from codersdk (#17939)
This commit is contained in:
@ -7,17 +7,121 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/coder/coder/v2/codersdk/wsjson"
|
||||
previewtypes "github.com/coder/preview/types"
|
||||
"github.com/coder/websocket"
|
||||
)
|
||||
|
||||
// FriendlyDiagnostic is included to guarantee it is generated in the output
|
||||
// types. This is used as the type override for `previewtypes.Diagnostic`.
|
||||
type FriendlyDiagnostic = previewtypes.FriendlyDiagnostic
|
||||
type ParameterFormType string
|
||||
|
||||
// NullHCLString is included to guarantee it is generated in the output
|
||||
// types. This is used as the type override for `previewtypes.HCLString`.
|
||||
type NullHCLString = previewtypes.NullHCLString
|
||||
const (
|
||||
ParameterFormTypeDefault ParameterFormType = ""
|
||||
ParameterFormTypeRadio ParameterFormType = "radio"
|
||||
ParameterFormTypeSlider ParameterFormType = "slider"
|
||||
ParameterFormTypeInput ParameterFormType = "input"
|
||||
ParameterFormTypeDropdown ParameterFormType = "dropdown"
|
||||
ParameterFormTypeCheckbox ParameterFormType = "checkbox"
|
||||
ParameterFormTypeSwitch ParameterFormType = "switch"
|
||||
ParameterFormTypeMultiSelect ParameterFormType = "multi-select"
|
||||
ParameterFormTypeTagSelect ParameterFormType = "tag-select"
|
||||
ParameterFormTypeTextArea ParameterFormType = "textarea"
|
||||
ParameterFormTypeError ParameterFormType = "error"
|
||||
)
|
||||
|
||||
type OptionType string
|
||||
|
||||
const (
|
||||
OptionTypeString OptionType = "string"
|
||||
OptionTypeNumber OptionType = "number"
|
||||
OptionTypeBoolean OptionType = "bool"
|
||||
OptionTypeListString OptionType = "list(string)"
|
||||
)
|
||||
|
||||
type DiagnosticSeverityString string
|
||||
|
||||
const (
|
||||
DiagnosticSeverityError DiagnosticSeverityString = "error"
|
||||
DiagnosticSeverityWarning DiagnosticSeverityString = "warning"
|
||||
)
|
||||
|
||||
// FriendlyDiagnostic == previewtypes.FriendlyDiagnostic
|
||||
// Copied to avoid import deps
|
||||
type FriendlyDiagnostic struct {
|
||||
Severity DiagnosticSeverityString `json:"severity"`
|
||||
Summary string `json:"summary"`
|
||||
Detail string `json:"detail"`
|
||||
|
||||
Extra DiagnosticExtra `json:"extra"`
|
||||
}
|
||||
|
||||
type DiagnosticExtra struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
// NullHCLString == `previewtypes.NullHCLString`.
|
||||
type NullHCLString struct {
|
||||
Value string `json:"value"`
|
||||
Valid bool `json:"valid"`
|
||||
}
|
||||
|
||||
type PreviewParameter struct {
|
||||
PreviewParameterData
|
||||
Value NullHCLString `json:"value"`
|
||||
Diagnostics []FriendlyDiagnostic `json:"diagnostics"`
|
||||
}
|
||||
|
||||
type PreviewParameterData struct {
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
Type OptionType `json:"type"`
|
||||
FormType ParameterFormType `json:"form_type"`
|
||||
Styling PreviewParameterStyling `json:"styling"`
|
||||
Mutable bool `json:"mutable"`
|
||||
DefaultValue NullHCLString `json:"default_value"`
|
||||
Icon string `json:"icon"`
|
||||
Options []PreviewParameterOption `json:"options"`
|
||||
Validations []PreviewParameterValidation `json:"validations"`
|
||||
Required bool `json:"required"`
|
||||
// legacy_variable_name was removed (= 14)
|
||||
Order int64 `json:"order"`
|
||||
Ephemeral bool `json:"ephemeral"`
|
||||
}
|
||||
|
||||
type PreviewParameterStyling struct {
|
||||
Placeholder *string `json:"placeholder,omitempty"`
|
||||
Disabled *bool `json:"disabled,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
}
|
||||
|
||||
type PreviewParameterOption struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Value NullHCLString `json:"value"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
|
||||
type PreviewParameterValidation struct {
|
||||
Error string `json:"validation_error"`
|
||||
|
||||
// All validation attributes are optional.
|
||||
Regex *string `json:"validation_regex"`
|
||||
Min *int64 `json:"validation_min"`
|
||||
Max *int64 `json:"validation_max"`
|
||||
Monotonic *string `json:"validation_monotonic"`
|
||||
}
|
||||
|
||||
type DynamicParametersRequest struct {
|
||||
// ID identifies the request. The response contains the same
|
||||
// ID so that the client can match it to the request.
|
||||
ID int `json:"id"`
|
||||
Inputs map[string]string `json:"inputs"`
|
||||
}
|
||||
|
||||
type DynamicParametersResponse struct {
|
||||
ID int `json:"id"`
|
||||
Diagnostics []FriendlyDiagnostic `json:"diagnostics"`
|
||||
Parameters []PreviewParameter `json:"parameters"`
|
||||
// TODO: Workspace tags
|
||||
}
|
||||
|
||||
func (c *Client) TemplateVersionDynamicParameters(ctx context.Context, userID, version uuid.UUID) (*wsjson.Stream[DynamicParametersResponse, DynamicParametersRequest], error) {
|
||||
conn, err := c.Dial(ctx, fmt.Sprintf("/api/v2/users/%s/templateversions/%s/parameters", userID, version), nil)
|
||||
|
Reference in New Issue
Block a user