Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ class ApiMethods {
return response.data;
};

getToken = async (tokenName: string): Promise<TypesGen.APIKey> => {
const response = await this.axios.get<TypesGen.APIKey>(
`/api/v2/users/me/keys/tokens/${tokenName}`,
);

return response.data;
};

deleteToken = async (keyId: string): Promise<void> => {
await this.axios.delete(`/api/v2/users/me/keys/${keyId}`);
};
Expand All @@ -546,6 +554,18 @@ class ApiMethods {
return response.data;
};

updateToken = async (
tokenName: string,
params: TypesGen.UpdateTokenRequest,
): Promise<TypesGen.APIKey> => {
const response = await this.axios.patch<TypesGen.APIKey>(
`/api/v2/users/me/keys/tokens/${tokenName}`,
params,
);

return response.data;
};

getTokenConfig = async (): Promise<TypesGen.TokenConfig> => {
const response = await this.axios.get(
"/api/v2/users/me/keys/tokens/tokenconfig",
Expand All @@ -554,6 +574,14 @@ class ApiMethods {
return response.data;
};

getScopeCatalog = async (): Promise<TypesGen.ScopeCatalog> => {
const response = await this.axios.get<TypesGen.ScopeCatalog>(
"/api/v2/auth/scopes",
);

return response.data;
};

getUsers = async (
options: TypesGen.UsersRequest,
signal?: AbortSignal,
Expand Down
10 changes: 10 additions & 0 deletions site/src/api/queries/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { API } from "api/api";
import type { APIKeyWithOwner, TokensFilter } from "api/typesGenerated";
import type { QueryOptions } from "react-query";

export const tokens = (filter: TokensFilter) => {
return {
queryKey: ["tokens", filter.include_all],
queryFn: () => API.getTokens(filter),
} satisfies QueryOptions<APIKeyWithOwner[]>;
};
41 changes: 35 additions & 6 deletions site/src/components/MultiSelectCombobox/MultiSelectCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ interface MultiSelectComboboxProps {
"data-testid"?: string;
}

interface MultiSelectComboboxRef {
export interface MultiSelectComboboxRef {
selectedValue: Option[];
input: HTMLInputElement;
focus: () => void;
reset: () => void;
setInputValue: (
value: string,
options?: { focus?: boolean; open?: boolean },
) => void;
}

function transitionToGroupOption(options: Option[], groupBy?: string) {
Expand Down Expand Up @@ -224,9 +228,28 @@ export const MultiSelectCombobox = forwardRef<
const [options, setOptions] = useState<GroupOption>(
transitionToGroupOption(arrayDefaultOptions, groupBy),
);
const [inputValue, setInputValue] = useState("");
const [inputValue, setInputValueState] = useState("");
const debouncedSearchTerm = useDebouncedValue(inputValue, delay || 500);

const setComboboxInputValue = useCallback(
(value: string, options?: { focus?: boolean; open?: boolean }) => {
setInputValueState(value);
if (options?.open === true) {
setOpen(true);
} else if (options?.open === false) {
setOpen(false);
} else if (value !== "" && !open) {
setOpen(true);
}
if (options?.focus) {
setTimeout(() => {
inputRef.current?.focus();
}, 0);
}
},
[open],
);

const [previousValue, setPreviousValue] = useState<Option[]>(value || []);
if (value && value !== previousValue) {
setPreviousValue(value);
Expand All @@ -240,8 +263,14 @@ export const MultiSelectCombobox = forwardRef<
input: inputRef.current as HTMLInputElement,
focus: () => inputRef?.current?.focus(),
reset: () => setSelected([]),
setInputValue: (
value: string,
options?: { focus?: boolean; open?: boolean },
) => {
setComboboxInputValue(value, options);
},
}),
[selected],
[selected, setComboboxInputValue],
);

const handleUnselect = useCallback(
Expand Down Expand Up @@ -398,7 +427,7 @@ export const MultiSelectCombobox = forwardRef<
onMaxSelected?.(selected.length);
return;
}
setInputValue("");
setComboboxInputValue("");
const newOptions = [...selected, { value, label: value }];
setSelected(newOptions);
onChange?.(newOptions);
Expand Down Expand Up @@ -554,7 +583,7 @@ export const MultiSelectCombobox = forwardRef<
value={inputValue}
disabled={disabled}
onValueChange={(value) => {
setInputValue(value);
setInputValueState(value);
inputProps?.onValueChange?.(value);
}}
onBlur={(event) => {
Expand Down Expand Up @@ -663,7 +692,7 @@ export const MultiSelectCombobox = forwardRef<
onMaxSelected?.(selected.length);
return;
}
setInputValue("");
setComboboxInputValue("");
const newOptions = [...selected, option];
setSelected(newOptions);
onChange?.(newOptions);
Expand Down
Loading
Loading