fix(frontend): improves UI/UX of aliases modal

Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
This commit is contained in:
yamashush 2024-01-12 19:51:14 +09:00 committed by Erik Michelson
parent f56abf74e0
commit c5d8341c45
6 changed files with 57 additions and 55 deletions

View file

@ -441,6 +441,7 @@
"addAlias": "Add alias", "addAlias": "Add alias",
"makePrimary": "Mark this alias as primary", "makePrimary": "Mark this alias as primary",
"isPrimary": "This is the primary alias", "isPrimary": "This is the primary alias",
"primaryLabel": "Primary Alias",
"removeAlias": "Remove this alias", "removeAlias": "Remove this alias",
"errorAddingAlias": "The chosen alias can not be added to this note", "errorAddingAlias": "The chosen alias can not be added to this note",
"errorRemovingAlias": "There was an error removing the alias", "errorRemovingAlias": "There was an error removing the alias",

View file

@ -14,13 +14,13 @@ exports[`AliasesAddForm renders the input form 1`] = `
value="" value=""
/> />
<button <button
class="text-secondary ms-2 btn btn-light" class="ms-2 btn btn-primary"
data-testid="addAliasButton" data-testid="addAliasButton"
disabled="" disabled=""
title="editor.modal.aliases.addAlias" title="editor.modal.aliases.addAlias"
type="submit" type="submit"
> >
BootstrapIconMock_Plus BootstrapIconMock_PlusLg
</button> </button>
</div> </div>
</form> </form>

View file

@ -1,23 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AliasesListEntry disables button in AliasesListEntry if it's not primary 1`] = ` exports[`AliasesListEntry adds aliasPrimaryBadge & removes aliasButtonMakePrimary in AliasesListEntry if it's primary 1`] = `
<div> <div>
<li <li
class="list-group-item d-flex flex-row justify-content-between align-items-center" class="list-group-item d-flex flex-row justify-content-between align-items-center"
> >
test-primary <div>
test-primary
<span
class="ms-2 badge bg-secondary"
data-testid="aliasPrimaryBadge"
title="editor.modal.aliases.isPrimary"
>
editor.modal.aliases.primaryLabel
</span>
</div>
<div> <div>
<button <button
class="me-2 btn btn-light" class="btn btn-danger"
data-testid="aliasButtonMakePrimary"
disabled=""
title="editor.modal.aliases.makePrimary"
type="button"
>
BootstrapIconMock_StarFill
</button>
<button
class="text-danger btn btn-light"
data-testid="aliasButtonRemove" data-testid="aliasButtonRemove"
disabled="" disabled=""
title="editor.modal.aliases.removeAlias" title="editor.modal.aliases.removeAlias"
@ -30,24 +30,26 @@ exports[`AliasesListEntry disables button in AliasesListEntry if it's not primar
</div> </div>
`; `;
exports[`AliasesListEntry disables button in AliasesListEntry if it's primary 1`] = ` exports[`AliasesListEntry removes aliasPrimaryBadge & adds aliasButtonMakePrimary in AliasesListEntry if it's not primary 1`] = `
<div> <div>
<li <li
class="list-group-item d-flex flex-row justify-content-between align-items-center" class="list-group-item d-flex flex-row justify-content-between align-items-center"
> >
test-primary <div>
test-primary
</div>
<div> <div>
<button <button
class="me-2 text-warning btn btn-light" class="me-2 btn btn-secondary"
data-testid="aliasIsPrimary" data-testid="aliasButtonMakePrimary"
disabled="" disabled=""
title="editor.modal.aliases.isPrimary" title="editor.modal.aliases.makePrimary"
type="button" type="button"
> >
BootstrapIconMock_Star BootstrapIconMock_Star
</button> </button>
<button <button
class="text-danger btn btn-light" class="btn btn-danger"
data-testid="aliasButtonRemove" data-testid="aliasButtonRemove"
disabled="" disabled=""
title="editor.modal.aliases.removeAlias" title="editor.modal.aliases.removeAlias"
@ -65,18 +67,20 @@ exports[`AliasesListEntry renders an AliasesListEntry that is not primary 1`] =
<li <li
class="list-group-item d-flex flex-row justify-content-between align-items-center" class="list-group-item d-flex flex-row justify-content-between align-items-center"
> >
test-non-primary <div>
test-non-primary
</div>
<div> <div>
<button <button
class="me-2 btn btn-light" class="me-2 btn btn-secondary"
data-testid="aliasButtonMakePrimary" data-testid="aliasButtonMakePrimary"
title="editor.modal.aliases.makePrimary" title="editor.modal.aliases.makePrimary"
type="button" type="button"
> >
BootstrapIconMock_StarFill BootstrapIconMock_Star
</button> </button>
<button <button
class="text-danger btn btn-light" class="btn btn-danger"
data-testid="aliasButtonRemove" data-testid="aliasButtonRemove"
title="editor.modal.aliases.removeAlias" title="editor.modal.aliases.removeAlias"
type="button" type="button"
@ -93,19 +97,19 @@ exports[`AliasesListEntry renders an AliasesListEntry that is primary 1`] = `
<li <li
class="list-group-item d-flex flex-row justify-content-between align-items-center" class="list-group-item d-flex flex-row justify-content-between align-items-center"
> >
test-primary <div>
test-primary
<span
class="ms-2 badge bg-secondary"
data-testid="aliasPrimaryBadge"
title="editor.modal.aliases.isPrimary"
>
editor.modal.aliases.primaryLabel
</span>
</div>
<div> <div>
<button <button
class="me-2 text-warning btn btn-light" class="btn btn-danger"
data-testid="aliasIsPrimary"
disabled=""
title="editor.modal.aliases.isPrimary"
type="button"
>
BootstrapIconMock_Star
</button>
<button
class="text-danger btn btn-light"
data-testid="aliasButtonRemove" data-testid="aliasButtonRemove"
title="editor.modal.aliases.removeAlias" title="editor.modal.aliases.removeAlias"
type="button" type="button"

View file

@ -15,7 +15,7 @@ import { useUiNotifications } from '../../../../../notifications/ui-notification
import type { FormEvent } from 'react' import type { FormEvent } from 'react'
import React, { useCallback, useMemo, useState } from 'react' import React, { useCallback, useMemo, useState } from 'react'
import { Button, Form, InputGroup } from 'react-bootstrap' import { Button, Form, InputGroup } from 'react-bootstrap'
import { Plus as IconPlus } from 'react-bootstrap-icons' import { PlusLg as IconPlus } from 'react-bootstrap-icons'
const validAliasRegex = /^[a-z0-9_-]*$/ const validAliasRegex = /^[a-z0-9_-]*$/
@ -66,8 +66,8 @@ export const AliasesAddForm: React.FC = () => {
/> />
<Button <Button
type={'submit'} type={'submit'}
variant='light' variant='primary'
className={'text-secondary ms-2'} className={'ms-2'}
disabled={!isOwner || !newAliasValid || newAlias === ''} disabled={!isOwner || !newAliasValid || newAlias === ''}
title={addAliasText} title={addAliasText}
{...testId('addAliasButton')}> {...testId('addAliasButton')}>

View file

@ -53,7 +53,7 @@ describe('AliasesListEntry', () => {
expect(NoteDetailsReduxModule.updateMetadata).toBeCalled() expect(NoteDetailsReduxModule.updateMetadata).toBeCalled()
}) })
it("disables button in AliasesListEntry if it's primary", () => { it("adds aliasPrimaryBadge & removes aliasButtonMakePrimary in AliasesListEntry if it's primary", () => {
mockNotePermissions('test2', 'test') mockNotePermissions('test2', 'test')
const testAlias: Alias = { const testAlias: Alias = {
name: 'test-primary', name: 'test-primary',
@ -89,7 +89,7 @@ describe('AliasesListEntry', () => {
expect(NoteDetailsReduxModule.updateMetadata).toBeCalled() expect(NoteDetailsReduxModule.updateMetadata).toBeCalled()
}) })
it("disables button in AliasesListEntry if it's not primary", () => { it("removes aliasPrimaryBadge & adds aliasButtonMakePrimary in AliasesListEntry if it's not primary", () => {
mockNotePermissions('test2', 'test') mockNotePermissions('test2', 'test')
const testAlias: Alias = { const testAlias: Alias = {
name: 'test-primary', name: 'test-primary',

View file

@ -12,9 +12,10 @@ import { testId } from '../../../../../../utils/test-id'
import { UiIcon } from '../../../../../common/icons/ui-icon' import { UiIcon } from '../../../../../common/icons/ui-icon'
import { useUiNotifications } from '../../../../../notifications/ui-notification-boundary' import { useUiNotifications } from '../../../../../notifications/ui-notification-boundary'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import { Badge } from 'react-bootstrap'
import { Button } from 'react-bootstrap' import { Button } from 'react-bootstrap'
import { Star as IconStar, StarFill as IconStarFill, X as IconX } from 'react-bootstrap-icons' import { Star as IconStar, X as IconX } from 'react-bootstrap-icons'
import { useTranslation } from 'react-i18next' import { useTranslation, Trans } from 'react-i18next'
export interface AliasesListEntryProps { export interface AliasesListEntryProps {
alias: Alias alias: Alias
@ -48,32 +49,28 @@ export const AliasesListEntry: React.FC<AliasesListEntryProps> = ({ alias }) =>
return ( return (
<li className={'list-group-item d-flex flex-row justify-content-between align-items-center'}> <li className={'list-group-item d-flex flex-row justify-content-between align-items-center'}>
{alias.name}
<div> <div>
{alias.name}
{alias.primaryAlias && ( {alias.primaryAlias && (
<Button <Badge bg='secondary' className={'ms-2'} title={isPrimaryText} {...testId('aliasPrimaryBadge')}>
className={'me-2 text-warning'} <Trans i18nKey={'editor.modal.aliases.primaryLabel'}></Trans>
variant='light' </Badge>
disabled={true}
title={isPrimaryText}
{...testId('aliasIsPrimary')}>
<UiIcon icon={IconStar} />
</Button>
)} )}
</div>
<div>
{!alias.primaryAlias && ( {!alias.primaryAlias && (
<Button <Button
className={'me-2'} className={'me-2'}
variant='light' variant='secondary'
disabled={!isOwner} disabled={!isOwner}
title={makePrimaryText} title={makePrimaryText}
onClick={onMakePrimaryClick} onClick={onMakePrimaryClick}
{...testId('aliasButtonMakePrimary')}> {...testId('aliasButtonMakePrimary')}>
<UiIcon icon={IconStarFill} /> <UiIcon icon={IconStar} />
</Button> </Button>
)} )}
<Button <Button
variant='light' variant='danger'
className={'text-danger'}
disabled={!isOwner} disabled={!isOwner}
title={removeAliasText} title={removeAliasText}
onClick={onRemoveClick} onClick={onRemoveClick}