Skip to content

Commit

Permalink
fix: FacePile is requesting avatars when SLACK_ENABLE_AVATARS is false (
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Sep 5, 2024
1 parent 2097b71 commit de3de54
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions superset-frontend/src/components/FacePile/FacePile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion superset-frontend/src/components/FacePile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
import { useSelector } from 'react-redux';
import {
getCategoricalSchemeRegistry,
styled,
SupersetTheme,
} 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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"NATIVE_FILTER_DEFAULT_ROW_LIMIT",
"PREVENT_UNSAFE_DEFAULT_URLS_ON_DATASET",
"JWT_ACCESS_CSRF_COOKIE_NAME",
"SLACK_ENABLE_AVATARS",
)

logger = logging.getLogger(__name__)
Expand Down

0 comments on commit de3de54

Please sign in to comment.