forked from datalens-tech/datalens-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor helper getWorkbookBreadcrumbsItems (datalens-tech#381)
* Refactor helper getWorkbookBreadcrumbsItems * Fix after review * Fix types * Add catch for getting breadcrumbs * Add condition for set breadcrumbs * Fix type * Fix type * Fix case, when have not collection id
- Loading branch information
1 parent
01d7ca1
commit d621515
Showing
7 changed files
with
101 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,76 @@ | ||
import {BreadcrumbsItem} from '@gravity-ui/uikit'; | ||
import {History, Location} from 'history'; | ||
import {I18n} from 'i18n'; | ||
import {EntryBreadcrumbsProps} from 'ui/registry/units/common/types/components/EntryBreadcrumbs'; | ||
import Utils from 'ui/utils'; | ||
|
||
const i18n = I18n.keyset('component.collection-breadcrumbs'); | ||
|
||
export const getWorkbookBreadcrumbsItems = ({ | ||
entry, | ||
workbookBreadcrumbs, | ||
workbookName, | ||
history, | ||
location, | ||
}: { | ||
entry: EntryBreadcrumbsProps['entry']; | ||
workbookBreadcrumbs: EntryBreadcrumbsProps['workbookBreadcrumbs']; | ||
workbookName: EntryBreadcrumbsProps['workbookName']; | ||
history: History; | ||
location: Location; | ||
}): BreadcrumbsItem[] => { | ||
if (!entry) { | ||
return []; | ||
} | ||
|
||
const rootName = workbookName || 'Workbook'; | ||
let entryName = Utils.getEntryNameFromKey(entry.key || ''); | ||
entryName = (entry as {fake?: boolean}).fake ? '' : entryName; | ||
const fakeName = (entry as {fakeName?: string}).fakeName; | ||
if (!entry) return []; | ||
|
||
const items: BreadcrumbsItem[] = []; | ||
const breadcrumbsItems: BreadcrumbsItem[] = [ | ||
{ | ||
text: i18n('label_root-title'), | ||
action: () => { | ||
history.push('/collections'); | ||
}, | ||
}, | ||
]; | ||
|
||
const workbookId = entry.workbookId; | ||
if (workbookBreadcrumbs && workbookBreadcrumbs.length > 0) { | ||
workbookBreadcrumbs.forEach((item: {title: string; collectionId: string}) => { | ||
breadcrumbsItems.push({ | ||
text: item.title, | ||
action: () => { | ||
history.push({ | ||
...location, | ||
pathname: `/collections/${item.collectionId}`, | ||
}); | ||
}, | ||
}); | ||
}); | ||
} | ||
|
||
if (workbookId) { | ||
items.push({ | ||
text: rootName, | ||
if (workbookName) { | ||
breadcrumbsItems.push({ | ||
text: workbookName, | ||
action: () => { | ||
history.push({ | ||
...location, | ||
pathname: `/workbooks/${workbookId}`, | ||
pathname: `/workbooks/${entry.workbookId}`, | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
let entryName = Utils.getEntryNameFromKey(entry?.key || ''); | ||
entryName = (entry as {fake?: boolean}).fake ? '' : entryName; | ||
const fakeName = (entry as {fakeName?: string}).fakeName; | ||
|
||
if (entryName) { | ||
items.push({ | ||
breadcrumbsItems.push({ | ||
text: entryName, | ||
action: () => {}, | ||
}); | ||
} else if (fakeName) { | ||
items.push({ | ||
breadcrumbsItems.push({ | ||
text: fakeName, | ||
action: () => {}, | ||
}); | ||
} | ||
|
||
return items; | ||
return breadcrumbsItems; | ||
}; |
3 changes: 2 additions & 1 deletion
3
src/ui/registry/units/common/types/components/EntryBreadcrumbs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import {BreadcrumbsProps} from '@gravity-ui/uikit/build/esm/components/Breadcrumbs/Breadcrumbs'; | ||
import {GetEntryResponse} from 'shared/schema'; | ||
import {GetCollectionBreadcrumbsResponse, GetEntryResponse} from 'shared/schema'; | ||
|
||
export type EntryBreadcrumbsProps = { | ||
renderRootContent?: BreadcrumbsProps['renderRootContent']; | ||
entry?: GetEntryResponse; | ||
workbookName?: string; | ||
workbookBreadcrumbs?: GetCollectionBreadcrumbsResponse | null; | ||
openNavigationAction?: (startFromNavigation: string) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters