Skip to content

Commit

Permalink
fix(dashboard): Invalid owner's name displayed after updates (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Sep 17, 2024
1 parent c33d49e commit 2f0c994
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
9 changes: 6 additions & 3 deletions superset-frontend/src/components/FacePile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
import type Owner from 'src/types/Owner';
import {
getCategoricalSchemeRegistry,
styled,
isFeatureEnabled,
FeatureFlag,
SupersetTheme,
} from '@superset-ui/core';
import getOwnerName from 'src/utils/getOwnerName';
import { Tooltip } from 'src/components/Tooltip';
import { Avatar } from 'src/components';
import { getRandomColor } from './utils';

interface FacePileProps {
users: { first_name: string; last_name: string; id: number }[];
users: Owner[];
maxCount?: number;
}

Expand Down Expand Up @@ -57,8 +59,9 @@ const StyledGroup = styled(Avatar.Group)`
export default function FacePile({ users, maxCount = 4 }: FacePileProps) {
return (
<StyledGroup maxCount={maxCount}>
{users.map(({ first_name, last_name, id }) => {
const name = `${first_name} ${last_name}`;
{users.map(user => {
const { first_name, last_name, id } = user;
const name = getOwnerName(user);
const uniqueKey = `${id}-${first_name}-${last_name}`;
const color = getRandomColor(uniqueKey, colorList);
const avatarUrl = isFeatureEnabled(FeatureFlag.SlackEnableAvatars)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import TagType from 'src/types/TagType';
import { fetchTags, OBJECT_TYPES } from 'src/features/tags/tags';
import { loadTags } from 'src/components/Tags/utils';
import { applyColors, getColorNamespace } from 'src/utils/colorScheme';
import getOwnerName from 'src/utils/getOwnerName';
import Owner from 'src/types/Owner';

const StyledFormItem = styled(FormItem)`
margin-bottom: 0;
Expand Down Expand Up @@ -250,17 +252,10 @@ const PropertiesModal = ({
};

const handleOwnersSelectValue = () => {
const parsedOwners = (owners || []).map(
(owner: {
id: number;
first_name?: string;
last_name?: string;
full_name?: string;
}) => ({
value: owner.id,
label: owner.full_name || `${owner.first_name} ${owner.last_name}`,
}),
);
const parsedOwners = (owners || []).map((owner: Owner) => ({
value: owner.id,
label: getOwnerName(owner),
}));
return parsedOwners;
};

Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/types/Owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
*/

export default interface Owner {
first_name: string;
first_name?: string;
id: number;
last_name: string;
last_name?: string;
full_name?: string;
}
2 changes: 2 additions & 0 deletions superset-frontend/src/utils/getOwnerName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ test('render owner name correctly', () => {
expect(getOwnerName({ id: 1, first_name: 'Foo', last_name: 'Bar' })).toEqual(
'Foo Bar',
);

expect(getOwnerName({ id: 2, full_name: 'John Doe' })).toEqual('John Doe');
});

test('return empty string for undefined owner', () => {
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/utils/getOwnerName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export default function getOwnerName(owner?: Owner): string {
if (!owner) {
return '';
}
return `${owner.first_name} ${owner.last_name}`;
return owner.full_name || `${owner.first_name} ${owner.last_name}`;
}

0 comments on commit 2f0c994

Please sign in to comment.