Skip to content

Commit ebe2d93

Browse files
committed
added new option table type for experiments
1 parent 76c65b1 commit ebe2d93

File tree

14 files changed

+264
-134
lines changed

14 files changed

+264
-134
lines changed

coderd/apidoc/docs.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 113 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/experiments.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ import (
44
"net/http"
55

66
"github.com/coder/coder/v2/coderd/httpapi"
7+
"github.com/coder/coder/v2/codersdk"
78
)
89

910
// @Summary Get experiments
1011
// @ID get-experiments
1112
// @Security CoderSessionToken
1213
// @Produce json
1314
// @Tags General
15+
// @Param include_all query bool false "All available experiments"
1416
// @Success 200 {array} codersdk.Experiment
1517
// @Router /experiments [get]
1618
func (api *API) handleExperimentsGet(rw http.ResponseWriter, r *http.Request) {
1719
ctx := r.Context()
18-
httpapi.Write(ctx, rw, http.StatusOK, api.Experiments)
20+
all := r.URL.Query().Has("include_all")
21+
22+
if !all {
23+
httpapi.Write(ctx, rw, http.StatusOK, api.Experiments)
24+
return
25+
}
26+
27+
httpapi.Write(ctx, rw, http.StatusOK, codersdk.ExperimentsAll)
1928
}

codersdk/deployment.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,26 @@ func (e Experiments) Enabled(ex Experiment) bool {
20282028
return false
20292029
}
20302030

2031-
func (c *Client) Experiments(ctx context.Context) (Experiments, error) {
2032-
res, err := c.Request(ctx, http.MethodGet, "/api/v2/experiments", nil)
2031+
type ExperimentOptions struct {
2032+
// All signifies that all experiments - rather than just those that are enabled -
2033+
// should be returned
2034+
IncludeAll bool `json:"include_all,omitempty"`
2035+
}
2036+
2037+
// asRequestOption returns a function that can be used in (*Client).Request.
2038+
// It modifies the request query parameters.
2039+
func (o ExperimentOptions) asRequestOption() RequestOption {
2040+
return func(r *http.Request) {
2041+
q := r.URL.Query()
2042+
if o.IncludeAll {
2043+
q.Set("include_all", "true")
2044+
}
2045+
r.URL.RawQuery = q.Encode()
2046+
}
2047+
}
2048+
2049+
func (c *Client) Experiments(ctx context.Context, opts ExperimentOptions) (Experiments, error) {
2050+
res, err := c.Request(ctx, http.MethodGet, "/api/v2/experiments", nil, opts.asRequestOption())
20332051
if err != nil {
20342052
return nil, err
20352053
}

docs/api/general.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/api/api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,11 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
852852
}
853853
};
854854

855-
export const getExperiments = async (): Promise<TypesGen.Experiment[]> => {
855+
export const getExperiments = async (
856+
params?: TypesGen.ExperimentOptions,
857+
): Promise<TypesGen.Experiment[]> => {
856858
try {
857-
const response = await axios.get("/api/v2/experiments");
859+
const response = await axios.get("/api/v2/experiments", { params });
858860
return response.data;
859861
} catch (error) {
860862
if (axios.isAxiosError(error) && error.response?.status === 404) {

site/src/api/queries/experiments.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as API from "api/api";
2-
import { Experiments } from "api/typesGenerated";
2+
import { Experiments, ExperimentOptions } from "api/typesGenerated";
33
import { getMetadataAsJSON } from "utils/metadata";
44

55
export const experiments = () => {
@@ -9,3 +9,10 @@ export const experiments = () => {
99
getMetadataAsJSON<Experiments>("experiments") ?? API.getExperiments(),
1010
};
1111
};
12+
13+
export const updatedExperiments = (params?: ExperimentOptions) => {
14+
return {
15+
queryKey: ["experiments"],
16+
queryFn: async () => API.getExperiments(params),
17+
};
18+
};

site/src/api/typesGenerated.ts

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)