Skip to content

Commit

Permalink
feat: add select all
Browse files Browse the repository at this point in the history
  • Loading branch information
tea-artist committed Dec 19, 2024
1 parent bc49f97 commit a68fd12
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 34 deletions.
7 changes: 1 addition & 6 deletions apps/nestjs-backend/src/features/base/base.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,12 @@ export class BaseController {
return await this.baseService.getBaseById(baseId);
}

@Permissions('base|read_all')
@Get('access/all')
async getAllBase(): Promise<IGetBaseAllVo> {
return this.baseService.getAllBaseList();
}

@Permissions('base|read_all')
@Get('access/list')
async getAccessBase(): Promise<{ id: string; name: string }[]> {
return this.baseService.getAccessBaseList();
}

@Delete(':baseId')
@Permissions('base|delete')
@EmitControllerEvent(Events.BASE_DELETE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const AccessSelect = (props: IFormAccess) => {
?.map(({ id, name }) => (
<CommandGroup
key={id}
heading={<div className="truncate text-sm">{name}</div>}
heading={<div className="truncate text-sm font-bold">{name}</div>}
title={name}
>
<CommandItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { actionPrefixMap } from '@teable/core';
import type { ActionPrefix, Action } from '@teable/core';
import { usePermissionActionsStatic } from '@teable/sdk/hooks';
import { Checkbox, Label } from '@teable/ui-lib/shadcn';
import { Checkbox, Label, Button } from '@teable/ui-lib/shadcn';
import { useTranslation } from 'next-i18next';
import { useMemo, useState } from 'react';

interface IScopesSelectProps {
Expand All @@ -12,6 +13,7 @@ interface IScopesSelectProps {

export const ScopesSelect = (props: IScopesSelectProps) => {
const { onChange, initValue, actionsPrefixes } = props;
const { t } = useTranslation('token');
const [value, setValue] = useState<Record<Action, boolean>>(() => {
if (initValue) {
return initValue.reduce(
Expand All @@ -34,6 +36,16 @@ export const ScopesSelect = (props: IScopesSelectProps) => {
onChange?.(actions);
};

const handleSelectAll = (prefix: ActionPrefix, shouldSelect: boolean) => {
const actionMap = { ...value };
actionPrefixMap[prefix].forEach((action) => {
actionMap[action] = shouldSelect;
});
setValue(actionMap);
const actions = Object.keys(actionMap).filter((key) => actionMap[key as Action]);
onChange?.(actions);
};

const actionsPrefix = useMemo(() => {
if (actionsPrefixes) {
return Object.keys(actionPrefixStaticMap).filter((key) =>
Expand All @@ -47,9 +59,19 @@ export const ScopesSelect = (props: IScopesSelectProps) => {
<div className="space-y-3 pl-2">
{actionsPrefix.map((actionPrefix) => {
const actions = actionPrefixMap[actionPrefix];
const isAllSelected = actions.every((action) => value[action]);
return (
<div key={actionPrefix} className="space-y-1">
<Label>{actionPrefixStaticMap[actionPrefix].title}</Label>
<div key={actionPrefix} className="group space-y-1">
<div className="flex items-center">
<Label>{actionPrefixStaticMap[actionPrefix].title}</Label>
<Button
variant="link"
className="invisible h-6 px-2 text-xs text-muted-foreground group-hover:visible"
onClick={() => handleSelectAll(actionPrefix, !isAllSelected)}
>
{isAllSelected ? t('edit.cancelSelectAll') : t('edit.selectAll')}
</Button>
</div>
<div className="flex gap-3">
{actions.map((action) => (
<div className="flex items-center gap-1 text-sm" key={action}>
Expand Down
2 changes: 1 addition & 1 deletion packages/common-i18n/src/locales/en/sdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"automationDelete": "Delete automation",
"automationRead": "Read automation",
"automationUpdate": "Update automation",
"userRead": "Read current user",
"userProfileRead": "Read current user profile",
"userEmailRead": "Read current user email",
"recordHistoryRead": "Read record history",
"baseQuery": "Query base",
Expand Down
6 changes: 4 additions & 2 deletions packages/common-i18n/src/locales/en/token.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"new": {
"headerTitle": "Create new token",
"title": "Personal access tokens are required to use the Teable API.",
"description": "This token will grant access to the data in the selected spaces and bases. This token will also allow usage of other, non-space/base API endpoints. Only use this token for your own development. Don’t share it with third-party services and applications.",
"description": "This token will grant access to the data in the selected spaces and bases. And other, non-space/base API endpoints. Please only use this token for your own development. Please be cautious when sharing it with third-party services and applications.",
"button": "Create new token",
"success": {
"title": "Token successfully generated",
Expand All @@ -31,7 +31,9 @@
"edit": {
"title": "Edit token",
"name": "Name",
"scopes": "Scopes"
"scopes": "Scopes",
"selectAll": "Select all",
"cancelSelectAll": "Cancel select all"
},
"refresh": {
"title": "Regenerate personal access token",
Expand Down
2 changes: 1 addition & 1 deletion packages/common-i18n/src/locales/fr/sdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
"automationDelete": "Supprimer une automatisation",
"automationRead": "Lire une automatisation",
"automationUpdate": "Mettre à jour une automatisation",
"userRead": "Lire un utilisateur",
"userProfileRead": "Lire le profil de l'utilisateur",
"userEmailRead": "Lire l'email de l'utilisateur",
"recordHistoryRead": "Lire l'historique des enregistrements",
"baseQuery": "Interroger la base",
Expand Down
6 changes: 4 additions & 2 deletions packages/common-i18n/src/locales/fr/token.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"new": {
"headerTitle": "Créer un nouveau jeton",
"title": "Les jetons d'accès personnel sont nécessaires pour utiliser l'API Teable.",
"description": "Ce jeton permettra d'accéder aux données dans les espaces et bases sélectionnés. Ce jeton permettra également d'utiliser d'autres points de terminaison d'API non liés aux espaces/bases. Utilisez ce jeton uniquement pour votre propre développement. Ne le partagez pas avec des services et applications tiers.",
"description": "Ce jeton permettra d'accéder aux données dans les espaces et bases sélectionnés. Et d'autres, non liés aux espaces/bases, points de terminaison d'API. Utilisez ce jeton uniquement pour votre propre développement. Soyez prudent lors de son partage avec des services et applications tiers.",
"button": "Créer un nouveau jeton",
"success": {
"title": "Jeton généré avec succès",
Expand All @@ -31,7 +31,9 @@
"edit": {
"title": "Modifier le jeton",
"name": "Nom",
"scopes": "Périmètres"
"scopes": "Périmètres",
"selectAll": "Sélectionner tout",
"cancelSelectAll": "Annuler la sélection de tout"
},
"refresh": {
"title": "Régénérer le jeton d'accès personnel",
Expand Down
2 changes: 1 addition & 1 deletion packages/common-i18n/src/locales/ja/sdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
"automationDelete": "オートメーションの削除",
"automationRead": "オートメーションの読み取り",
"automationUpdate": "オートメーションの更新",
"userRead": "ユーザーの読み取り",
"userProfileRead": "ユーザーのプロフィールの読み取り",
"userEmailRead": "ユーザーメールの読み取り",
"recordHistoryRead": "レコード履歴の読み取り",
"baseQuery": "クエリベース",
Expand Down
6 changes: 4 additions & 2 deletions packages/common-i18n/src/locales/ja/token.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"new": {
"headerTitle": "新しいトークンの作成",
"title": "Teable APIを使用するには、個人アクセストークンが必要です。",
"description": "このトークンは、選択したスペースとベースのデータへのアクセスを許可します。このトークンは、スペース/ベース以外の他のAPIエンドポイントの使用も許可します。このトークンは独自の開発にのみ使用してください。サードパーティのサービスやアプリケーションと共有しないでください。",
"description": "このトークンは、選択したスペースとベースのデータへのアクセスを許可します。その他、スペース/ベース以外のAPIエンドポイントも使用できます。このトークンは独自の開発にのみ使用してください。サードパーティのサービスやアプリケーションと共有しないでください。",
"button": "新しいトークンを作成",
"success": {
"title": "トークンが正常に生成されました",
Expand All @@ -31,7 +31,9 @@
"edit": {
"title": "トークンを編集",
"name": "名前",
"scopes": "スコープ"
"scopes": "スコープ",
"selectAll": "全選択",
"cancelSelectAll": "全選択解除"
},
"refresh": {
"title": "個人アクセストークンを再生成する",
Expand Down
2 changes: 1 addition & 1 deletion packages/common-i18n/src/locales/ru/sdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
"automationDelete": "Удалить автоматизацию",
"automationRead": "Читать автоматизацию",
"automationUpdate": "Обновить автоматизацию",
"userRead": "Читать пользователя",
"userProfileRead": "Читать профиль пользователя",
"userEmailRead": "Читать электронную почту пользователя",
"recordHistoryRead": "Читать историю записей",
"baseQuery": "Запрос базы",
Expand Down
6 changes: 4 additions & 2 deletions packages/common-i18n/src/locales/ru/token.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"new": {
"headerTitle": "Создать новый токен",
"title": "Персональные токены доступа необходимы для использования API Teable.",
"description": "Этот токен предоставит доступ к данным в выбранных пространствах и базах. Этот токен также позволит использовать другие конечные точки API, не связанные с пространствами/базами. Используйте этот токен только для собственного развития. Не делитесь им с третьими сторонами и приложениями.",
"description": "Этот токен предоставит доступ к данным в выбранных пространствах и базах. И другие, не связанные с пространствами/базами, конечные точки API. Используйте этот токен только для собственного развития. Будьте осторожны при его использовании с третьими сторонами и приложениями.",
"button": "Создать новый токен",
"success": {
"title": "Токен успешно создан",
Expand All @@ -31,7 +31,9 @@
"edit": {
"title": "Редактировать токен",
"name": "Имя",
"scopes": "Области применения"
"scopes": "Области применения",
"selectAll": "Выбрать все",
"cancelSelectAll": "Отменить выбор всех"
},
"refresh": {
"title": "Восстановить персональный токен доступа",
Expand Down
2 changes: 1 addition & 1 deletion packages/common-i18n/src/locales/zh/sdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"automationDelete": "删除自动化",
"automationRead": "读取自动化",
"automationUpdate": "更新自动化",
"userRead": "查看当前用户",
"userProfileRead": "查看当前用户",
"userEmailRead": "查看当前用户电子邮件",
"recordHistoryRead": "查看记录历史",
"baseQuery": "查询数据库",
Expand Down
6 changes: 4 additions & 2 deletions packages/common-i18n/src/locales/zh/token.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"new": {
"headerTitle": "创建新令牌",
"title": "使用 Teable API 需要个人访问令牌。",
"description": "此令牌将授予对所选工作区和数据库中数据的访问权限。此令牌还将允许使用其他非工作区/数据库的 API 端点。只在您自己的开发中使用此令牌。不要与第三方服务和应用共享",
"description": "此令牌将授予对所选工作区和数据库中数据的访问权限。以及非工作区/数据库的 API 端点。请只在您自己的开发中使用此令牌。请谨慎与第三方服务和应用共享",
"button": "创建新令牌",
"success": {
"title": "令牌成功生成",
Expand All @@ -31,7 +31,9 @@
"edit": {
"title": "编辑令牌",
"name": "名称",
"scopes": "范围"
"scopes": "范围",
"selectAll": "全选",
"cancelSelectAll": "取消全选"
},
"refresh": {
"title": "重新生成个人访问令牌",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/auth/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const automationActions = [
export const automationActionSchema = z.enum(automationActions);
export type AutomationAction = z.infer<typeof automationActionSchema>;

export const userActions = ['user|read', 'user|email_read'] as const;
export const userActions = ['user|email_read'] as const;
export const userActionSchema = z.enum(userActions);
export type UserAction = z.infer<typeof userActionSchema>;

Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/auth/role/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const RolePermission: Record<IRole, Record<Action, boolean>> = {
'automation|delete': true,
'automation|read': true,
'automation|update': true,
'user|read': true,
'user|email_read': true,
'instance|read': false,
'instance|update': false,
Expand Down Expand Up @@ -106,7 +105,6 @@ export const RolePermission: Record<IRole, Record<Action, boolean>> = {
'automation|delete': true,
'automation|read': true,
'automation|update': true,
'user|read': true,
'user|email_read': true,
'instance|read': false,
'instance|update': false,
Expand Down Expand Up @@ -161,7 +159,6 @@ export const RolePermission: Record<IRole, Record<Action, boolean>> = {
'automation|delete': false,
'automation|read': true,
'automation|update': false,
'user|read': true,
'user|email_read': true,
'instance|read': false,
'instance|update': false,
Expand Down Expand Up @@ -216,7 +213,6 @@ export const RolePermission: Record<IRole, Record<Action, boolean>> = {
'automation|delete': false,
'automation|read': true,
'automation|update': false,
'user|read': true,
'user|email_read': true,
'instance|read': false,
'instance|update': false,
Expand Down Expand Up @@ -271,7 +267,6 @@ export const RolePermission: Record<IRole, Record<Action, boolean>> = {
'automation|delete': false,
'automation|read': true,
'automation|update': false,
'user|read': true,
'user|email_read': true,
'instance|read': false,
'instance|update': false,
Expand Down
3 changes: 0 additions & 3 deletions packages/sdk/src/hooks/use-permission-actions-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ const actionsI18nMap: Record<
'automation|update': {
description: 'permission.actionDescription.automationUpdate',
},
'user|read': {
description: 'permission.actionDescription.userRead',
},
'user|email_read': {
description: 'permission.actionDescription.userEmailRead',
},
Expand Down

0 comments on commit a68fd12

Please sign in to comment.