perf: improve the display of user auth providers in user details (#3624)

#### What type of PR is this?

/kind improvement
/area console
/milestone 2.4.x

#### What this PR does / why we need it:

优化用户详情页面中认证方式的显示逻辑。

#### Does this PR introduce a user-facing change?

```release-note
None
```
pull/3617/head^2
Ryan Wang 2023-03-29 21:30:14 +08:00 committed by GitHub
parent 9814053d0e
commit 4c11ccfcd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { Dialog, IconUserSettings, VButton, VTag } from "@halo-dev/components"; import { Dialog, IconUserSettings, VButton, VTag } from "@halo-dev/components";
import type { ComputedRef, Ref } from "vue"; import type { ComputedRef, Ref } from "vue";
import { inject } from "vue"; import { inject, computed } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import type { DetailedUser, ListedAuthProvider } from "@halo-dev/api-client"; import type { DetailedUser, ListedAuthProvider } from "@halo-dev/api-client";
import { rbacAnnotations } from "@/constants/annotations"; import { rbacAnnotations } from "@/constants/annotations";
@ -17,7 +17,7 @@ const isCurrentUser = inject<ComputedRef<boolean>>("isCurrentUser");
const router = useRouter(); const router = useRouter();
const { t } = useI18n(); const { t } = useI18n();
const { data: authProviders } = useQuery<ListedAuthProvider[]>({ const { data: authProviders, isFetching } = useQuery<ListedAuthProvider[]>({
queryKey: ["user-auth-providers"], queryKey: ["user-auth-providers"],
queryFn: async () => { queryFn: async () => {
const { data } = await apiClient.authProvider.listAuthProviders(); const { data } = await apiClient.authProvider.listAuthProviders();
@ -27,6 +27,12 @@ const { data: authProviders } = useQuery<ListedAuthProvider[]>({
enabled: isCurrentUser, enabled: isCurrentUser,
}); });
const availableAuthProviders = computed(() => {
return authProviders.value?.filter(
(authProvider) => authProvider.enabled && authProvider.supportsBinding
);
});
const handleUnbindAuth = (authProvider: ListedAuthProvider) => { const handleUnbindAuth = (authProvider: ListedAuthProvider) => {
Dialog.warning({ Dialog.warning({
title: t("core.user.detail.operations.unbind.title", { title: t("core.user.detail.operations.unbind.title", {
@ -149,7 +155,7 @@ const handleBindAuth = (authProvider: ListedAuthProvider) => {
</dd> </dd>
</div> </div>
<div <div
v-if="isCurrentUser" v-if="!isFetching && isCurrentUser && availableAuthProviders?.length"
class="bg-white py-5 px-2 hover:bg-gray-50 sm:grid sm:grid-cols-6 sm:gap-4" class="bg-white py-5 px-2 hover:bg-gray-50 sm:grid sm:grid-cols-6 sm:gap-4"
> >
<dt class="text-sm font-medium text-gray-900"> <dt class="text-sm font-medium text-gray-900">