Skip to content

Commit

Permalink
Add neww canBeRoot and mayContainRootCandidates flags (#2376)
Browse files Browse the repository at this point in the history
-   Ticket: [ENG-6436]
-   Feature flag: n/a

## Purpose
- Add logic to prevent users from selecting or navigating into an inappropriate item when selecting a root folder

## Summary of Changes
- Add `canBeRoot` and `mayContainRootCandidates` flags to addon-operation-invocation item-results
- Use these flags to control whether a user can navigate into that item (`mayContainRootCandidates`), or select an item as a root folder (`canBeRoot`)
- Relevant GV PR CenterForOpenScience/gravyvalet#139
  • Loading branch information
futa-ikeda authored Nov 4, 2024
1 parent b6b68f6 commit 51a0b3a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
2 changes: 2 additions & 0 deletions app/models/addon-operation-invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface Item {
itemId: string;
itemName: string;
itemType: ItemType;
canBeRoot: boolean;
mayContainRootCandidates: boolean;
itemPath?: Item[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,36 @@
{{#each fileManager.currentItems as |folder|}}
<tr>
<td>
<Button
data-test-folder-link='{{folder.itemName}}'
data-analytics-name='Go to folder'
@layout='fake-link'
aria-label={{t 'addons.configure.go-to-folder' folderName=folder.itemName}}
{{on 'click' (fn fileManager.goToFolder folder)}}
>
<FaIcon @icon='folder' />
{{folder.itemName}}
</Button>
{{#if folder.mayContainRootCandidates}}
<Button
data-test-folder-link='{{folder.itemName}}'
data-analytics-name='Go to folder'
@layout='fake-link'
aria-label={{t 'addons.configure.go-to-folder' folderName=folder.itemName}}
{{on 'click' (fn fileManager.goToFolder folder)}}
>
<FaIcon @icon='folder' />
{{folder.itemName}}
</Button>
{{else}}
<span>
<FaIcon @icon='folder' />
{{folder.itemName}}
</span>
{{/if}}
</td>
<td>
<input
data-test-root-folder-option='{{folder.itemName}}'
data-analytics-name='Select folder'
type='radio'
name='folder'
value={{folder.itemName}}
aria-label={{t 'addons.configure.select-folder' folderName=folder.itemName}}
{{on 'change'(fn this.selectFolder folder)}}
>
{{#if folder.canBeRoot}}
<input
data-test-root-folder-option='{{folder.itemName}}'
data-analytics-name='Select folder'
type='radio'
name='folder'
value={{folder.itemName}}
aria-label={{t 'addons.configure.select-folder' folderName=folder.itemName}}
{{on 'change'(fn this.selectFolder folder)}}
>
{{/if}}
</td>
</tr>
{{else}}
Expand Down
4 changes: 4 additions & 0 deletions mirage/views/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ export function createAddonOperationInvocation(this: HandlerContext, schema: Sch
item_name: `Folder with ID ${folderId}`,
item_type,
item_path: folderId === 'root' ? undefined : fakePath,
canBeRoot: item_type === ItemType.Folder,
mayContainRootCandidates: item_type === ItemType.Folder,
};
} else {
result = {
Expand All @@ -277,6 +279,8 @@ export function createAddonOperationInvocation(this: HandlerContext, schema: Sch
item_name: `${item_type}${i} in ${folderId}`,
item_type,
item_path: folderId === 'root' ? undefined : fakePath,
canBeRoot: item_type === ItemType.Folder,
mayContainRootCandidates: item_type === ItemType.Folder,
})),
};
}
Expand Down

0 comments on commit 51a0b3a

Please sign in to comment.