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

feat(editor): Implement breadcrumbs component #13317

Merged
merged 31 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c206128
feat(design-system): Implemented breadcrumbs component
MiloradFilipovic Feb 13, 2025
4a77617
✨ Implemented async hidden items loading
MiloradFilipovic Feb 14, 2025
0424bd1
✨ Added slots
MiloradFilipovic Feb 14, 2025
6be03e5
💄 Adding tags to story
MiloradFilipovic Feb 14, 2025
683429c
💄 Implementing correct styles for medium variant
MiloradFilipovic Feb 14, 2025
6d581a4
💄 Implementing styles for small variant
MiloradFilipovic Feb 14, 2025
b4a2b06
Merge branch 'master' into ADO-3176-breadcrumbs-component
MiloradFilipovic Feb 17, 2025
0006162
🔨 Simplifying the component, adding skeletons loading
MiloradFilipovic Feb 17, 2025
0bdab90
⚡Implementing small version loading state
MiloradFilipovic Feb 17, 2025
b8ee1fe
✅ Adding test and more props
MiloradFilipovic Feb 17, 2025
e3c7888
⚡Hidden items caching and minor refactoring
MiloradFilipovic Feb 17, 2025
e23a4a3
👕 Disabling async warning in storybook entry
MiloradFilipovic Feb 17, 2025
eb62cbe
💄 More customization options
MiloradFilipovic Feb 17, 2025
d7c9b2d
✨ Adding loading state to action toggle
MiloradFilipovic Feb 17, 2025
e9a9b4e
⚡Using action toggle instead of tooltip
MiloradFilipovic Feb 17, 2025
f7b9bf3
⚡Refactoring events, fixing spacing
MiloradFilipovic Feb 18, 2025
ef12997
⚡Adding itemSelected event
MiloradFilipovic Feb 18, 2025
51bc787
🔨 Cleanup
MiloradFilipovic Feb 18, 2025
dcd5272
👌 Highlighting only current item
MiloradFilipovic Feb 18, 2025
c2f38da
👌 Implemented watch on hidden items & cache bust mechanism
MiloradFilipovic Feb 18, 2025
fd42fbd
👌 Simplifying component API by allowing promise
MiloradFilipovic Feb 18, 2025
54867c6
✅ Updating tests and stories
MiloradFilipovic Feb 18, 2025
432e3f8
👕 Removing unused imports
MiloradFilipovic Feb 18, 2025
4528fbf
✨ Allowing ellipsis to show when there are no hidden items
MiloradFilipovic Feb 19, 2025
1ad8c3e
👌 Simplify watch
MiloradFilipovic Feb 19, 2025
585f6a3
⚡Adding more docs and stories
MiloradFilipovic Feb 19, 2025
186a41c
refactor: dots in slot
RobTF9 Feb 19, 2025
666c907
✅ Adding tests
MiloradFilipovic Feb 19, 2025
2aa2b25
Merge remote-tracking branch 'origin/ADO-3176-breadcrumbs-component' …
MiloradFilipovic Feb 19, 2025
a2160a9
💄 Update styles for ellipses
MiloradFilipovic Feb 19, 2025
4054105
👌 Removing unused prop
MiloradFilipovic Feb 19, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { ref } from 'vue';
import type { PathItem } from './Breadcrumbs.vue';
import Breadcrumbs from './Breadcrumbs.vue';

/**
* Demo component to showcase different usage of Breadcrumbs component
*/

defineOptions({ name: 'AsyncLoadingCacheDemo' });

const FETCH_TIMEOUT = 1000;
Expand All @@ -12,6 +16,7 @@ type Props = {
title: string;
mode: 'sync' | 'async';
testCache?: boolean;
// Breadcrumbs props
theme?: 'small' | 'medium';
showBorder?: boolean;
};
Expand All @@ -23,21 +28,28 @@ const props = withDefaults(defineProps<Props>(), {
showBorder: false,
});

// We'll use this to break the cache after a few fetches in the demo
const fetchCount = ref(0);

const items = ref<PathItem[]>([
{ id: '1', label: 'Home', href: '/' },
{ id: '2', label: 'Parent', href: '/parent' },
]);

// For async version, hidden items are a promise, we can also make it reactive like this
const hiddenItemsPromise = ref<Promise<PathItem[]>>(new Promise(() => {}));
// For sync version, hidden items are a just a reactive array
const hiddenItemsSync = ref<PathItem[]>([
{ id: 'folder2', label: 'Folder 2' },
{ id: 'folder3', label: 'Folder 3' },
]);

const onDropdownOpened = () => {
// In the current implementation, we need to init a promise only when needed
if (fetchCount.value === 0) {
hiddenItemsPromise.value = fetchHiddenItems();
}
// Demo code
fetchCount.value++;
if (props.testCache) {
if (fetchCount.value > 2 && props.mode === 'async') {
Expand All @@ -48,6 +60,16 @@ const onDropdownOpened = () => {
}
};

const fetchHiddenItems = async (): Promise<PathItem[]> => {
await new Promise((resolve) => setTimeout(resolve, FETCH_TIMEOUT));
return [
{ id: 'home', label: 'Home' },
{ id: 'projects', label: 'Projects' },
{ id: 'folder1', label: 'Folder 1' },
];
};

// Updates the promise ref with new items to showcase it's reactivity
const updatePromise = () => {
hiddenItemsPromise.value = new Promise((resolve) => {
setTimeout(() => {
Expand All @@ -60,20 +82,12 @@ const updatePromise = () => {
});
};

// Updates the sync array to showcase it's reactivity
const updateSyncItems = () => {
const newId = fetchCount.value + 3;
const newItem = { id: `'folder${newId}'`, label: `Folder ${newId}` };
hiddenItemsSync.value.push(newItem);
};

const fetchHiddenItems = async (): Promise<PathItem[]> => {
await new Promise((resolve) => setTimeout(resolve, FETCH_TIMEOUT));
return [
{ id: 'home', label: 'Home' },
{ id: 'projects', label: 'Projects' },
{ id: 'folder1', label: 'Folder 1' },
];
};
</script>

<template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,19 @@ SmallAsyncLoading.args = {
theme: 'small',
showBorder: true,
};

const smallHiddenItemsDisabledTemplate: StoryFn = (args, { argTypes }) => ({
setup: () => ({ args }),
components: { Breadcrumbs },
props: Object.keys(argTypes),
template: '<Breadcrumbs v-bind="args" />',
});

export const SmallWithHiddenItemsDisabled = smallHiddenItemsDisabledTemplate.bind({});
SmallWithHiddenItemsDisabled.args = {
theme: 'small',
showBorder: true,
items: items.slice(2),
hiddenItems: [],
pathTruncated: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const emit = defineEmits<{
}>();

const props = withDefaults(defineProps<Props>(), {
hiddenItems: () => [],
hiddenItems: () => new Array<PathItem>(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I was just asking if this should be hiddenItems: [], but I guess this might get us a reference to the same object every time like in Python parameter defaults 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we must use the function. In Vue, Object or array defaults must be returned from a factory function like this. I just though types array like this is cleaner

theme: 'medium',
showBorder: false,
loadingSkeletonRows: 3,
Expand Down