Skip to content

Commit

Permalink
Merge pull request #496 from nanasikeai/feat_bkbase_storage
Browse files Browse the repository at this point in the history
fix: 特性开关使用优化 --bug=136100961
  • Loading branch information
0RAJA authored Jan 3, 2025
2 parents 91c26e3 + 829cfe1 commit 33311b5
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 168 deletions.
18 changes: 2 additions & 16 deletions src/frontend/src/components/audit-navigation/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,17 @@
ref,
} from 'vue';

import NoticeService from '@service/notice';

import useEventBus from '@hooks/use-event-bus';
import useFeature from '@hooks/use-feature';

import NoticeComponent from '@blueking/notice-component';

import useRequest from '@/hooks/use-request';

interface Emits{
(e: 'menu-flod', value: boolean):void
}
const emit = defineEmits<Emits>();
const { emit: emits } = useEventBus();
const { feature: showNotice } = useFeature('bknotice');

const apiUrl = `${window.PROJECT_CONFIG.AJAX_URL_PREFIX}/api/v1/bk-notice/announcements/`;
const TOGGLE_CACHE = 'navigation_toggle_status';
Expand Down Expand Up @@ -227,18 +225,6 @@
};
const resizeHandler = _.throttle(init, 100);

const {
data: showNotice,
} = useRequest(NoticeService.fetchNoticeFeature, {
defaultValue: {
enabled: false,
},
defaultParams: {
feature_id: 'bknotice',
},
manual: true,
});

onMounted(() => {
init();
emit('menu-flod', !isSideMenuFixed.value);
Expand Down
21 changes: 0 additions & 21 deletions src/frontend/src/domain/service/collector-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ export default {
return CollectorSource.getSnapShotStatus(params)
.then(({ data }) => data);
},
/**
* @desc 判断资源表格操作列是否显示
*/
fetchResourceFeature() {
return CollectorSource.getResourceFeature()
.then(({ data }) => data);
},
/**
* @desc 清洗字段历史
* @param { String } id
Expand Down Expand Up @@ -280,13 +273,6 @@ export default {
return CollectorSource.updateBcs(params)
.then(({ data }) => data);
},
/**
* @desc 判断API Push是否启用
*/
fetchApiPushFeature(params: {feature_id: string}) {
return CollectorSource.getApiPushFeature(params)
.then(({ data }) => data);
},
/**
* @desc 获取启用状态&上报host (无需单独鉴权)
*/
Expand Down Expand Up @@ -317,11 +303,4 @@ export default {
return CollectorSource.createApiPush(params)
.then(({ data }) => data);
},
/**
* @desc 是否显示:上报方式,计算平台已有数据源
*/
fetchBkbaseFeature(params: {feature_id: string}) {
return CollectorSource.getBkbaseFeature(params)
.then(({ data }) => data);
},
};
8 changes: 8 additions & 0 deletions src/frontend/src/domain/service/meta-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export default {
})
.then(({ data }) => data);
},
/**
* @desc 根据特性id获取特性开关
* @param { String } feature_id
*/
fetchFeature(params: {feature_id: string}) {
return MetaManageSource.getFeature(params)
.then(({ data }) => data);
},
/**
* @desc 获取 Namespace 列表
*/
Expand Down
27 changes: 0 additions & 27 deletions src/frontend/src/domain/service/notice.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/frontend/src/domain/service/statement-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ export default {
})
.then(({ data }) => data);
},
fetchHasBkvision() {
return StatementManageSource.getHasBkvision()
.then(({ data }) => data);
},
};
12 changes: 0 additions & 12 deletions src/frontend/src/domain/source/collector-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ class CollectorManage extends ModuleBase {
params,
});
}
// 判断资源表格操作列是否显示
getResourceFeature() {
return Request.get<Record<'enabled', boolean>>('/api/v1/feature/bkbase_aiops/');
}
// 清洗字段历史
getFieldHistory(params: { id: string}) {
return Request.get<Record<string, string>>(`${this.path}/collectors/${params.id}/etl_field_history/`);
Expand Down Expand Up @@ -203,10 +199,6 @@ class CollectorManage extends ModuleBase {
params,
});
}
// 判断API Push是否启用
getApiPushFeature(params: {feature_id: string}) {
return Request.get<Record<'enabled', boolean>>(`/api/v1/feature/${params.feature_id}/`);
}
// 获取启用状态&上报host (无需单独鉴权)
getApiPushHost(params: {system_id: string}) {
return Request.get<Record<string, any>>(`${this.path}/collectors/api_push_host/`, {
Expand Down Expand Up @@ -238,10 +230,6 @@ class CollectorManage extends ModuleBase {
payload,
});
}
// 判断上报方式,计算平台已有数据源是否显示
getBkbaseFeature(params: {feature_id: string}) {
return Request.get<Record<'enabled', boolean>>(`/api/v1/feature/${params.feature_id}/`);
}
}

export default new CollectorManage();
4 changes: 4 additions & 0 deletions src/frontend/src/domain/source/meta-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class MetaManage extends ModuleBase {
payload,
});
}
// 根据特性id获取特性开关,用于判断是否显示按钮、菜单等
getFeature(params: {feature_id: string}) {
return Request.get<Record<'enabled', boolean>>(`/api/v1/feature/${params.feature_id}/`);
}
// 获取 Namespace 列表
getAllNamespace() {
return Request.get<NamespaceModel>(`${this.module}/namespaces/`);
Expand Down
30 changes: 0 additions & 30 deletions src/frontend/src/domain/source/notice.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/frontend/src/domain/source/statement-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class Statement extends ModuleBase {
payload,
});
}

getHasBkvision() {
return Request.get<{
enabled: boolean
}>('/api/v1/feature/bkvision/');
}
}

export default new Statement();
21 changes: 21 additions & 0 deletions src/frontend/src/hooks/use-feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import MetaManageService from '@service/meta-manage';

import useRequest from '@hooks/use-request';

export default function (featureId: string) {
const {
data,
} = useRequest(MetaManageService.fetchFeature, {
defaultValue: {
enabled: false,
},
defaultParams: {
feature_id: featureId,
},
manual: true,
});

return {
feature: data,
};
}
11 changes: 2 additions & 9 deletions src/frontend/src/layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,11 @@
useRouter,
} from 'vue-router';

import StatementManageService from '@service/statement-manage';

import ConfigModel from '@model/root/config';

import useEventBus from '@hooks/use-event-bus';
import useFeature from '@hooks/use-feature';
import usePlatformConfig from '@hooks/use-platform-config';
import useRequest from '@hooks/use-request';

import AuditMenu from '@components/audit-menu/index.vue';
import AuditMenuItem from '@components/audit-menu/item.vue';
Expand Down Expand Up @@ -247,12 +245,7 @@
const platformConfig = usePlatformConfig();

// 是否展示审计报表导航
const {
data: hasBkvision,
} = useRequest(StatementManageService.fetchHasBkvision, {
manual: true,
defaultValue: { enabled: false },
});
const { feature: hasBkvision } = useFeature('bkvision');
const titleRef = ref<string>('');
const menuData = ref<Array<MenuDataType>>([]);
on('statement-menuData', (data) => {
Expand Down
36 changes: 21 additions & 15 deletions src/frontend/src/views/storage-manage/list/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@

import type StorageModel from '@model/storage/storage';

import useFeature from '@hooks/use-feature';
import useMessage from '@hooks/use-message';
import useRequest from '@hooks/use-request';

Expand All @@ -140,6 +141,7 @@
}
const isSearching = ref(false);
const search = ref('');
const { feature: showStorageEdit } = useFeature('storage_edit');
const tableColumn = [
{
label: () => 'ID',
Expand Down Expand Up @@ -247,23 +249,27 @@
{t('设为默认')}
</auth-button>
</audit-popconfirm>
<auth-button
permission={data.permission.edit_storage}
actionId="edit_storage"
text
theme="primary"
onClick={() => handleEdit(data)}
class="ml8">
{t('编辑')}
</auth-button>
{
showStorageEdit.value.enabled
? <auth-button
permission={data.permission.edit_storage}
actionId="edit_storage"
text
theme="primary"
onClick={() => handleEdit(data)}
className="ml8">
{t('编辑')}
</auth-button>
: ''
}
<audit-popconfirm
title={t('确认删除?')}
content={t('删除后不可恢复')}
class="ml8"
confirmHandler={() => handleRemove(data)}>
title={t('确认删除?')}
content={t('删除后不可恢复')}
class="ml8"
confirmHandler={() => handleRemove(data)}>
<auth-button
permission={data.permission.delete_storage}
actionId="delete_storage"
permission={data.permission.delete_storage}
actionId="delete_storage"
text
disabled={data.isDefault}
theme="primary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
ref,
} from 'vue';

import useFeature from '@hooks/use-feature';

let formData = reactive({
// 计算平台数据
bk_data_id: '',
Expand Down Expand Up @@ -298,6 +300,7 @@
searchParams,
removeSearchParam,
} = useUrlSearch();
const { feature: showBkbase } = useFeature('bkbase_data_source');
const comMap = {
physics: RenderPhysics,
container: RenderContainer,
Expand Down Expand Up @@ -518,19 +521,6 @@
});
}

const {
data: showBkbase,
} = useRequest(CollectorManageService.fetchBkbaseFeature, {
defaultValue: {
enabled: false,
},
defaultParams: {
feature_id: 'bkbase_data_source',
},
manual: true,
});


const {
run: fecthDetail,
} = useRequest(DataIdManageService.fecthDetail, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@
*/
const checkPermission = async () => {
const { access_global_setting: accessGlobalSetting = false } = await IamManageService.check({ action_ids: 'access_global_setting' });
const { enabled = false } = await CollectorManageService.fetchResourceFeature();
const { enabled = false } = await MetaManageService.fetchFeature({
feature_id: 'bkbase_aiops',
});
controlsPermission.value = accessGlobalSetting && enabled;
};

Expand Down
Loading

0 comments on commit 33311b5

Please sign in to comment.