Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge dashboard-september to master #4627

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const costFilterState = reactive({
return sortBy(Object.entries(additionalInfo).map(([k]) => ({
name: `additional_info.${k}`,
label: k,
presetKeys: additionalInfo[k].enums,
})), 'label');
}
return dataSource ? sortBy((dataSource.data?.cost_additional_info_keys ?? [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ const state = reactive({
loading: false,
proxyFilter: useProxyValue('filter', props, emit),
filterItems: computed(() => props.filterItems),
selectedItems: [] as MenuItem[],
selectedItems: [] as any[],
handlerMap: computed(() => {
const handlerMaps = {};
if (props.sourceType === DATA_SOURCE_DOMAIN.COST) {
state.selectedItems.forEach(({ name }) => {
handlerMaps[name] = getCostMenuHandler(name, {}, state.primaryCostStatOptions);
state.selectedItems.forEach(({ name, presetKeys }) => {
handlerMaps[name] = getCostMenuHandler(name, {}, state.primaryCostStatOptions, { presetKeys });
});
} else {
assetFilterState.refinedLabelKeys.forEach((labelInfo) => {
Expand Down Expand Up @@ -193,7 +193,12 @@ const resetFilterByKey = (key: string) => {
state.proxyFilter = { ...state.proxyFilter };
state.selectedItemsMap = { ...state.selectedItemsMap };
};
const getCostMenuHandler = (groupBy: string, listQueryOptions: Partial<Record<ManagedVariableModelKey, any>>, primaryOptions: Record<string, any>): AutocompleteHandler => {
const getCostMenuHandler = (
groupBy: string,
listQueryOptions: Partial<Record<ManagedVariableModelKey, any>>,
primaryOptions: Record<string, any>,
modelOptions?: Record<string, any>,
): AutocompleteHandler => {
try {
let variableModelInfo: VariableModelMenuHandlerInfo;
const _variableOption = GROUP_BY_TO_VAR_MODELS[groupBy];
Expand All @@ -204,7 +209,7 @@ const getCostMenuHandler = (groupBy: string, listQueryOptions: Partial<Record<Ma
};
} else {
const CostVariableModel = new VariableModelFactory({ type: 'MANAGED', managedModelKey: MANAGED_VARIABLE_MODEL_KEY_MAP.cost });
CostVariableModel[groupBy] = CostVariableModel.generateProperty({ key: groupBy });
CostVariableModel[groupBy] = CostVariableModel.generateProperty({ key: groupBy, presetValues: modelOptions?.presetKeys });
variableModelInfo = {
variableModel: CostVariableModel,
dataKey: groupBy,
Expand Down
19 changes: 15 additions & 4 deletions apps/web/src/lib/variable-models/_base/resource-variable-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class ResourceVariableModel<T=any> implements IResourceVariableMo
name: options.name,
isDataKey: _isDataKey,
isFilter: _isFilter,
values: _isDataKey ? this.stat(options.key as string) : undefined,
values: _isDataKey ? this.stat(options.key as string, options.presetValues) : undefined,
};

// TODO: keys method binding
Expand Down Expand Up @@ -114,6 +114,10 @@ export default class ResourceVariableModel<T=any> implements IResourceVariableMo
apiQueryHelper.addFilter({ k: dataKey, v: query.filters, o: '=' });
}

if (query.start !== undefined && query.limit !== undefined) {
apiQueryHelper.setPage(query.start, query.limit);
}

this.#properties?.forEach((key) => {
if (this[key]?.fixedValue) {
apiQueryHelper.addFilter({ k: key, v: this[key].fixedValue, o: '=' });
Expand Down Expand Up @@ -186,7 +190,7 @@ export default class ResourceVariableModel<T=any> implements IResourceVariableMo
}
}

stat(dataKey: string): (query?: ListQuery) => Promise<ListResponse> {
stat(dataKey: string, presetValues?: string[]): (query?: ListQuery) => Promise<ListResponse> {
const _dataKey = dataKey;
return async (query: ListQuery = {}) => {
try {
Expand All @@ -200,10 +204,17 @@ export default class ResourceVariableModel<T=any> implements IResourceVariableMo
if (status === 'succeed') {
let more = false;
if (query.start !== undefined && query.limit !== undefined && response.total_count !== undefined) {
more = (query.start * query.limit) < response.total_count;
more = (query.start - 1 + query.limit) < response.total_count;
}

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 })) ?? []),
];

this.#response = {
results: response.results ? response.results.map((d) => ({ key: d, name: d })) : [],
results: _presetValues ? _resultsWithPreset : (response.results ?? []).map((d) => ({ key: d, name: d })),
more,
};
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/lib/variable-models/_base/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface PropertyOptions<T> {
name?: string;
isDataKey?: boolean;
isFilter?: boolean;
presetValues?: string[];
}
export interface PropertyObject<T> {
key: keyof T;
Expand Down
Loading