Skip to content

Commit

Permalink
fix(variable-model): allow results to be either T[] or string[] in fe…
Browse files Browse the repository at this point in the history
…tcher methods

Signed-off-by: Wanjin Noh <wanjin@megazone.com>
  • Loading branch information
WANZARGEN committed Jan 7, 2025
1 parent 54148a0 commit 3cd07be
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class ResourceVariableModel<T=any> implements IResourceVariableMo

#response: ListResponse<T> = { results: [] };

#fetcher?: ReturnType<typeof getCancellableFetcher<object, { results?: T[]; total_count?: number }>>;
#fetcher?: ReturnType<typeof getCancellableFetcher<object, { results?: T[]|string[]; total_count?: number }>>;

constructor(config: VariableModelConstructorConfig = {}) {
if (config.key) this._meta.key = config.key;
Expand Down Expand Up @@ -77,7 +77,7 @@ export default class ResourceVariableModel<T=any> implements IResourceVariableMo
return [this._meta.idKey, this._meta.nameKey];
}

#getFetcher(dataKey?: string): ReturnType<typeof getCancellableFetcher<object, { results?: T[]; total_count?: number }>>|undefined {
#getFetcher(dataKey?: string): ReturnType<typeof getCancellableFetcher<object, { results?: T[]|string[]; total_count?: number }>>|undefined {
if (!this._meta.resourceType) return undefined;
const apiPath = this._meta.resourceType.split('.').map((d) => camelCase(d));

Expand Down Expand Up @@ -216,7 +216,7 @@ export default class ResourceVariableModel<T=any> implements IResourceVariableMo
const _presetValues = presetValues;
const _resultsWithPreset = [
...(query.start === 1 ? (_presetValues ?? []).map((d) => ({ name: d, key: d })) : []),
...(response.results?.filter((d) => !_presetValues?.includes(d)).map((d) => ({ key: d, name: d })) ?? []),
...((response.results as string[])?.filter((d) => !_presetValues?.includes(d)).map((d) => ({ key: d, name: d })) ?? []),
];

this.#response = {
Expand Down

0 comments on commit 3cd07be

Please sign in to comment.