fix: filter user option in usage
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
|||||||
LockOutlined,
|
LockOutlined,
|
||||||
UserOutlined
|
UserOutlined
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { Input as CInput, HighlightCode } from '@gpustack/core-ui';
|
import { Input as CInput, HighlightCode, IconFont } from '@gpustack/core-ui';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Checkbox, Divider, Form, FormInstance } from 'antd';
|
import { Button, Checkbox, Divider, Form, FormInstance } from 'antd';
|
||||||
import { createStyles } from 'antd-style';
|
import { createStyles } from 'antd-style';
|
||||||
@@ -149,6 +149,7 @@ const LocalUserForm: React.FC<LocalUserFormProps> = (props) => {
|
|||||||
type="primary"
|
type="primary"
|
||||||
block
|
block
|
||||||
loading={props.loading}
|
loading={props.loading}
|
||||||
|
icon={<IconFont type="icon-login" />}
|
||||||
style={{ height: '48px', fontSize: '14px' }}
|
style={{ height: '48px', fontSize: '14px' }}
|
||||||
>
|
>
|
||||||
{intl.formatMessage({ id: 'common.button.login' })}
|
{intl.formatMessage({ id: 'common.button.login' })}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import useCoolColors from '@/hooks/use-cool-colors';
|
import useCoolColors from '@/hooks/use-cool-colors';
|
||||||
import BarChart from '@/pages/_components/bar-chart';
|
import BarChart from '@/pages/_components/bar-chart';
|
||||||
import { BaseSelect, CardWrapper } from '@gpustack/core-ui';
|
import { BaseSelect, CardWrapper } from '@gpustack/core-ui';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl, useModel } from '@umijs/max';
|
||||||
import { Segmented } from 'antd';
|
import { Segmented } from 'antd';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
@@ -80,6 +80,8 @@ const DailyUsage: React.FC<DailyUsageProps> = (props) => {
|
|||||||
onGranularityChange
|
onGranularityChange
|
||||||
} = props;
|
} = props;
|
||||||
const generateCoolColors = useCoolColors();
|
const generateCoolColors = useCoolColors();
|
||||||
|
const { initialState } = useModel('@@initialState');
|
||||||
|
const { currentUser } = initialState || {};
|
||||||
|
|
||||||
const labelFormatter = (v: any) => {
|
const labelFormatter = (v: any) => {
|
||||||
if (granularity === 'month') {
|
if (granularity === 'month') {
|
||||||
@@ -245,6 +247,18 @@ const DailyUsage: React.FC<DailyUsageProps> = (props) => {
|
|||||||
onGroupByChange(value || null);
|
onGroupByChange(value || null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const groupByOptionsFiltered = groupByOptions
|
||||||
|
.map((item) => ({
|
||||||
|
label: intl.formatMessage({ id: item.label }),
|
||||||
|
value: item.value
|
||||||
|
}))
|
||||||
|
.filter((option) => {
|
||||||
|
if (currentUser?.is_admin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return option.value !== 'user';
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CardWrapper style={{ width: '100%', marginTop: 20 }}>
|
<CardWrapper style={{ width: '100%', marginTop: 20 }}>
|
||||||
@@ -275,10 +289,7 @@ const DailyUsage: React.FC<DailyUsageProps> = (props) => {
|
|||||||
{intl.formatMessage({ id: 'usage.filter.groupBy' })}
|
{intl.formatMessage({ id: 'usage.filter.groupBy' })}
|
||||||
</ControlLabel>
|
</ControlLabel>
|
||||||
}
|
}
|
||||||
options={groupByOptions.map((item) => ({
|
options={groupByOptionsFiltered}
|
||||||
label: intl.formatMessage({ id: item.label }),
|
|
||||||
value: item.value
|
|
||||||
}))}
|
|
||||||
value={groupBy}
|
value={groupBy}
|
||||||
popupMatchSelectWidth={false}
|
popupMatchSelectWidth={false}
|
||||||
onChange={handleOnGroupByChange}
|
onChange={handleOnGroupByChange}
|
||||||
|
|||||||
Reference in New Issue
Block a user