Skip to content

Commit

Permalink
feat: org edit optimize (#309)
Browse files Browse the repository at this point in the history
Signed-off-by: laixingyou <[email protected]>
  • Loading branch information
coder-sett authored Jan 31, 2024
1 parent f3d971e commit b87becb
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 31 deletions.
2 changes: 1 addition & 1 deletion apps/web/i18n
Submodule i18n updated 2 files
+2 −1 en/analyze.json
+2 −1 zh/analyze.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ import {
} from './contribution';
import { getMaxDomain } from './utils';
import DomainPersona from './DomainPersona';
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
import type { FilterValue, SorterResult } from 'antd/es/table/interface';
import { useTranslation } from 'next-i18next';
import Download from '@common/components/Table/Download';
import { getContributorPolling, getContributorExport } from '../tableDownload';
import { useRouter } from 'next/router';
import { useHandleQueryParams } from '@modules/analyze/hooks/useHandleQueryParams';
import Dialog from '@common/components/Dialog';
import Tooltip from '@common/components/Tooltip';
import { FiEdit } from 'react-icons/fi';
import { GrClose } from 'react-icons/gr';
import ManageOrgEdit from '@common/components/OrgEdit/ManageOrgEdit';
import useVerifyDetailRange from '@modules/analyze/hooks/useVerifyDetailRange';
import { useIsCurrentUser } from '@modules/analyze/hooks/useIsCurrentUser';

import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
import type { FilterValue, SorterResult } from 'antd/es/table/interface';
interface TableParams {
pagination?: TablePaginationConfig;
filterOpts?: FilterOptionInput[];
Expand All @@ -47,7 +49,7 @@ const MetricTable: React.FC<{
const [currentName, setCurrentName] = useState('');
const [currentOrgName, setCurrentOrgName] = useState('');
const { data } = useVerifyDetailRange();

const { isCurrentUser } = useIsCurrentUser();
const ecologicalOptions = useEcologicalType();
const mileageOptions = useMileageOptions();
const filterMap = {
Expand Down Expand Up @@ -131,15 +133,6 @@ const MetricTable: React.FC<{
});
setData(items);
},
// keepPreviousData: true,
// onError(res: any) {
// toast.error(
// getErrorMessage(res) || (() => <>{t('lab:create_failed')}</>),
// {
// position: 'top-center',
// }
// );
// },
}
);
const handleTableChange = (
Expand Down Expand Up @@ -246,21 +239,44 @@ const MetricTable: React.FC<{
align: 'left',
width: '160px',
render: (text, col) => {
let edit = null;
if (isCurrentUser(col.contributor)) {
edit = (
<FiEdit
className="cursor-pointer"
onClick={() => {
window.open('/settings/profile');
}}
/>
);
} else if (data?.verifyDetailDataRange?.labelAdmin) {
edit = (
<FiEdit
className="cursor-pointer"
onClick={() => {
setCurrentName(col.contributor);
col.organization && setCurrentOrgName(col.organization);
setOpenConfirm(true);
}}
/>
);
} else {
edit = (
<Tooltip
arrow
title={<div>{t('analyze:no_role_desc')}</div>}
placement="top"
>
<div>
<FiEdit className="cursor-not-allowed text-[#868690]" />
</div>
</Tooltip>
);
}
return (
<div className="flex">
<span>{text || '-'}</span>
<span className="text-primary ml-2 mt-1">
{data?.verifyDetailDataRange?.labelAdmin && (
<FiEdit
className="cursor-pointer"
onClick={() => {
setCurrentName(col.contributor);
col.organization && setCurrentOrgName(col.organization);
setOpenConfirm(true);
}}
/>
)}
</span>
<span className="text-primary ml-2 mt-1">{}</span>
</div>
);
},
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/modules/analyze/hooks/useIsCurrentUser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useSnapshot } from 'valtio';
import { userInfoStore } from '@modules/auth/UserInfoStore';

export const useIsCurrentUser = () => {
const { currentUser } = useSnapshot(userInfoStore);
const loginBinds = currentUser?.loginBinds;

const isCurrentUser = (name) => {
return loginBinds?.find((item) => item.nickname === name);
};

return {
isCurrentUser,
};
};
4 changes: 0 additions & 4 deletions packages/graphql/src/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4876,8 +4876,6 @@ export type VerifyDetailDataRangeQuery = {
verifyDetailDataRange: {
__typename?: 'ValidDataRange';
status?: boolean | null;
max?: any | null;
min?: any | null;
labelAdmin?: boolean | null;
};
};
Expand Down Expand Up @@ -8978,8 +8976,6 @@ export const VerifyDetailDataRangeDocument = /*#__PURE__*/ `
endDate: $endDate
) {
status
max
min
labelAdmin
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/graphql/src/gql/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,6 @@ query verifyDetailDataRange(
endDate: $endDate
) {
status
max
min
labelAdmin
}
}
Expand Down

0 comments on commit b87becb

Please sign in to comment.