Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added new option table type for experiments
  • Loading branch information
Kira-Pilot committed Oct 15, 2023
commit ebe2d93e6eea222cedc65630f4132a706303eb8d
8 changes: 8 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

226 changes: 113 additions & 113 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion coderd/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ import (
"net/http"

"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/codersdk"
)

// @Summary Get experiments
// @ID get-experiments
// @Security CoderSessionToken
// @Produce json
// @Tags General
// @Param include_all query bool false "All available experiments"
// @Success 200 {array} codersdk.Experiment
// @Router /experiments [get]
func (api *API) handleExperimentsGet(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
httpapi.Write(ctx, rw, http.StatusOK, api.Experiments)
all := r.URL.Query().Has("include_all")

if !all {
httpapi.Write(ctx, rw, http.StatusOK, api.Experiments)
return
}

httpapi.Write(ctx, rw, http.StatusOK, codersdk.ExperimentsAll)
}
22 changes: 20 additions & 2 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2028,8 +2028,26 @@ func (e Experiments) Enabled(ex Experiment) bool {
return false
}

func (c *Client) Experiments(ctx context.Context) (Experiments, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/experiments", nil)
type ExperimentOptions struct {
// All signifies that all experiments - rather than just those that are enabled -
// should be returned
IncludeAll bool `json:"include_all,omitempty"`
}

// asRequestOption returns a function that can be used in (*Client).Request.
// It modifies the request query parameters.
func (o ExperimentOptions) asRequestOption() RequestOption {
return func(r *http.Request) {
q := r.URL.Query()
if o.IncludeAll {
q.Set("include_all", "true")
}
r.URL.RawQuery = q.Encode()
}
}

func (c *Client) Experiments(ctx context.Context, opts ExperimentOptions) (Experiments, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/experiments", nil, opts.asRequestOption())
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions docs/api/general.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,11 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
}
};

export const getExperiments = async (): Promise<TypesGen.Experiment[]> => {
export const getExperiments = async (
params?: TypesGen.ExperimentOptions,
): Promise<TypesGen.Experiment[]> => {
try {
const response = await axios.get("/api/v2/experiments");
const response = await axios.get("/api/v2/experiments", { params });
return response.data;
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 404) {
Expand Down
9 changes: 8 additions & 1 deletion site/src/api/queries/experiments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as API from "api/api";
import { Experiments } from "api/typesGenerated";
import { Experiments, ExperimentOptions } from "api/typesGenerated";
import { getMetadataAsJSON } from "utils/metadata";

export const experiments = () => {
Expand All @@ -9,3 +9,10 @@ export const experiments = () => {
getMetadataAsJSON<Experiments>("experiments") ?? API.getExperiments(),
};
};

export const updatedExperiments = (params?: ExperimentOptions) => {
return {
queryKey: ["experiments"],
queryFn: async () => API.getExperiments(params),
};
};
5 changes: 5 additions & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading