From 00b3b3612e89729cab4bd999cab3f1994f5d4c07 Mon Sep 17 00:00:00 2001 From: netroms Date: Wed, 28 Jun 2023 05:11:52 +0800 Subject: [PATCH] feat: only show pats that you created (#1347) (cherry picked from commit 37b723ab5ebe86e5dc2dd92a4f60804c7dc6a47e) --- .../PersonalAccessTokens.component.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/personalAccessTokens/PersonalAccessTokens.component.js b/src/personalAccessTokens/PersonalAccessTokens.component.js index 39753368..5cba7253 100644 --- a/src/personalAccessTokens/PersonalAccessTokens.component.js +++ b/src/personalAccessTokens/PersonalAccessTokens.component.js @@ -2,6 +2,7 @@ import { useDataQuery } from '@dhis2/app-runtime' import { Card, Button } from '@dhis2/ui' import React, { useState } from 'react' import i18n from '../locales/index.js' +import userProfileStore from '../profile/profile.store.js' import GenerateTokenModal from './generateTokenModal/GenerateTokenModal.component.js' import styles from './PersonalAccessTokens.module.css' import TokensList from './TokensList.component.js' @@ -10,16 +11,20 @@ import { useModal } from './use-modal.js' const query = { tokens: { resource: 'apiToken', - params: { + params: ({ userId }) => ({ fields: ['id', 'created', 'expire', 'attributes'], paging: false, - }, + filter: `createdBy.id:eq:${userId}`, + }), }, } const PersonalAccessTokens = () => { + const userId = userProfileStore.state.id const [tokenKeys, setTokenKeys] = useState(new Map()) - const { loading, error, data, refetch } = useDataQuery(query) + const { loading, error, data, refetch } = useDataQuery(query, { + variables: { userId }, + }) const generateTokenModal = useModal() const tokens = data?.tokens.apiToken