fix: FacePile is requesting avatars when SLACK_ENABLE_AVATARS is false (#30156)

This commit is contained in:
Michael S. Molina 2024-09-05 08:50:50 -03:00 committed by GitHub
parent 2097b716f4
commit de3de541e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 3 deletions

View File

@ -16,9 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Provider } from 'react-redux';
import { styledMount as mount } from 'spec/helpers/theming';
import { Avatar } from 'src/components';
import { store } from 'src/views/store';
import FacePile from '.';
import { getRandomColor } from './utils';
@ -29,7 +30,11 @@ const users = [...new Array(10)].map((_, i) => ({
}));
describe('FacePile', () => {
const wrapper = mount(<FacePile users={users} />);
const wrapper = mount(
<Provider store={store}>
<FacePile users={users} />
</Provider>,
);
it('is a valid element', () => {
expect(wrapper.find(FacePile)).toExist();

View File

@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { useSelector } from 'react-redux';
import {
getCategoricalSchemeRegistry,
styled,
@ -23,6 +24,7 @@ import {
} from '@superset-ui/core';
import { Tooltip } from 'src/components/Tooltip';
import { Avatar } from 'src/components';
import { RootState } from 'src/views/store';
import { getRandomColor } from './utils';
interface FacePileProps {
@ -53,13 +55,18 @@ const StyledGroup = styled(Avatar.Group)`
`;
export default function FacePile({ users, maxCount = 4 }: FacePileProps) {
const enableAvatars = useSelector<RootState, boolean>(
state => state.common?.conf?.SLACK_ENABLE_AVATARS,
);
return (
<StyledGroup maxCount={maxCount}>
{users.map(({ first_name, last_name, id }) => {
const name = `${first_name} ${last_name}`;
const uniqueKey = `${id}-${first_name}-${last_name}`;
const color = getRandomColor(uniqueKey, colorList);
const avatarUrl = `/api/v1/user/${id}/avatar.png`;
const avatarUrl = enableAvatars
? `/api/v1/user/${id}/avatar.png`
: undefined;
return (
<Tooltip key={name} title={name} placement="top">
<StyledAvatar

View File

@ -114,6 +114,7 @@ FRONTEND_CONF_KEYS = (
"NATIVE_FILTER_DEFAULT_ROW_LIMIT",
"PREVENT_UNSAFE_DEFAULT_URLS_ON_DATASET",
"JWT_ACCESS_CSRF_COOKIE_NAME",
"SLACK_ENABLE_AVATARS",
)
logger = logging.getLogger(__name__)