Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update label for roles on user views #219

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/earth-admin/src/components/search-input/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import React, { useContext, useEffect, useState } from 'react';

import { LinkWithOrg } from '@app/components/link-with-org';
import { getAllLayers, getAllWidgets, getAvailableGroups } from '@app/services';
import { encodeQueryToURL } from '@app/utils';
import { encodeQueryToURL, normalizeGroupName } from '@app/utils';
import { Auth0Context } from '@app/utils/contexts';

interface SearchInputProps {
Expand Down Expand Up @@ -67,6 +67,11 @@ export default function SearchInput(props: SearchInputProps) {
}
});

const processGroupNames = (result: any): any => ({
...result,
data: result.data.map((item) => ({ ...item, name: normalizeGroupName(item.name) })),
});

useEffect(() => {
clearTimeout(timer);

Expand All @@ -82,7 +87,7 @@ export default function SearchInput(props: SearchInputProps) {
optionType === 'layers'
? await getAllLayers(encodedOptionsQuery)
: optionType === 'userGroups'
? await getAvailableGroups(selectedGroup)
? processGroupNames(await getAvailableGroups(selectedGroup))
: await getAllWidgets(encodedOptionsQuery);

setAvailableOptions(res.data);
Expand Down Expand Up @@ -147,7 +152,7 @@ export default function SearchInput(props: SearchInputProps) {
key={option.id}
className="ng-margin-medium-right"
>
{option.name}
{optionType === 'userGroups' ? normalizeGroupName(option.name) : option.name}
<span
className="ng-padding-left ng-icon-hover"
onClick={(e) => handleChange(e, option)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import React, { useState } from 'react';
import { AuthzGuards, ErrorMessages } from '@marapp/earth-shared';

import { useAuth0 } from '@app/auth/auth0';
import { normalizeGroupName } from '@app/utils';
import { LinkWithOrg } from '@app/components/link-with-org';
import { DeleteConfirmation } from '@app/components/modals/delete-confirmation';

Expand Down Expand Up @@ -73,8 +74,8 @@ export default function UserDetails(props: UserProps) {
<span className="ng-text-weight-medium">Name: </span> {name || '-'}
</p>
<p>
<span className="ng-text-weight-medium">Groups:</span>{' '}
{groups.map((group) => group.name).join(', ') || '-'}
<span className="ng-text-weight-medium">Roles:</span>{' '}
{groups.map((group) => normalizeGroupName(group.name)).join(', ') || '-'}
</p>
</div>
<div className="ng-padding-medium ng-background-ultradkgray ng-margin-medium-bottom">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function UserEdit(props: UserEditProps) {
</div>

<div className="ng-margin-medium-bottom">
<label htmlFor="role">User groups*</label>
<label htmlFor="role">User roles*</label>
<Controller
name="groups"
control={control}
Expand Down
5 changes: 1 addition & 4 deletions packages/earth-admin/src/pages-client/users/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import List from '@researchgate/react-intersection-list';
import { navigate } from 'gatsby';
import React, { useEffect, useState } from 'react';
import { capitalize } from 'lodash/fp';
import { Controller, useForm } from 'react-hook-form';
import Select from 'react-select';
import Creatable from 'react-select/creatable';
Expand All @@ -32,7 +31,7 @@ import { Card } from '@app/components/card';
import { ContentLayout } from '@app/layouts';
import { getAvailableGroups } from '@app/services';
import { addUsers, getAllUsers } from '@app/services/users';
import { encodeQueryToURL } from '@app/utils';
import { encodeQueryToURL, normalizeGroupName } from '@app/utils';
import { useInfiniteListPaged } from '@app/utils/hooks';
import { validEmail } from '@app/utils/validations';

Expand All @@ -49,8 +48,6 @@ export function UsersHome(props: any) {
const [serverErrors, setServerErrors] = useState([]);
const [usersFeedback, setUsersFeedback] = useState([]);

const normalizeGroupName = (groupName: string): string => capitalize(groupName.split('-').pop());

const getQuery = (pageIndex) => {
const query = {
page: { size: PAGE_SIZE, number: pageIndex },
Expand Down
8 changes: 8 additions & 0 deletions packages/earth-admin/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { navigate } from 'gatsby';
import moment from 'moment';
import queryStringEncode from 'query-string-encode';
import { RefObject } from 'react';
import { capitalize } from 'lodash';

import { ADMIN_PAGES } from '@app/components/sidebar-select/model';
import { BASE_URL } from '@app/config';
Expand Down Expand Up @@ -160,3 +161,10 @@ export function copyToClipboard(
successFunction('');
}, 4000);
}

/**
* Normalize group (role) name
* @param groupName
*/
export const normalizeGroupName = (groupName: string): string =>
capitalize(groupName.split('-').pop() || groupName);