Skip to content

Commit

Permalink
Fix view filter creation on new view (#8199)
Browse files Browse the repository at this point in the history
Wrong view was used for the creation from another view (source and
target view were inverted)
  • Loading branch information
lucasbordeau authored Oct 31, 2024
1 parent b3f95d6 commit d468204
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,33 @@ export const useCreateViewFromCurrentView = (viewBarComponentId?: string) => {
}

// Here we might instead want to get view from unsaved filters ?
const view = await getViewFromCache(currentViewId);
const sourceView = await getViewFromCache(currentViewId);

if (!isDefined(view)) {
if (!isDefined(sourceView)) {
return;
}

set(isPersistingViewFieldsCallbackState, true);

const newView = await createOneRecord({
id: id ?? v4(),
name: name ?? view.name,
icon: icon ?? view.icon,
name: name ?? sourceView.name,
icon: icon ?? sourceView.icon,
key: null,
kanbanFieldMetadataId:
kanbanFieldMetadataId ?? view.kanbanFieldMetadataId,
type: type ?? view.type,
objectMetadataId: view.objectMetadataId,
kanbanFieldMetadataId ?? sourceView.kanbanFieldMetadataId,
type: type ?? sourceView.type,
objectMetadataId: sourceView.objectMetadataId,
});

if (isUndefinedOrNull(newView)) {
throw new Error('Failed to create view');
}

await createViewFieldRecords(view.viewFields, newView);
await createViewFieldRecords(sourceView.viewFields, newView);

if (type === ViewType.Kanban) {
if (!isNonEmptyArray(view.viewGroups)) {
if (!isNonEmptyArray(sourceView.viewGroups)) {
if (!isDefined(kanbanFieldMetadataId)) {
throw new Error('Kanban view must have a kanban field');
}
Expand Down Expand Up @@ -144,22 +144,24 @@ export const useCreateViewFromCurrentView = (viewBarComponentId?: string) => {

await createViewGroupRecords(viewGroupsToCreate, newView);
} else {
await createViewGroupRecords(view.viewGroups, newView);
await createViewGroupRecords(sourceView.viewGroups, newView);
}
}

if (shouldCopyFiltersAndSorts === true) {
const sourceViewCombinedFilterGroups = getViewFilterGroupsCombined(
view.id,
sourceView.id,
);
const sourceViewCombinedFilters = getViewFiltersCombined(view.id);
const sourceViewCombinedSorts = getViewSortsCombined(view.id);
const sourceViewCombinedFilters = getViewFiltersCombined(
sourceView.id,
);
const sourceViewCombinedSorts = getViewSortsCombined(sourceView.id);

await createViewSortRecords(sourceViewCombinedSorts, view);
await createViewFilterRecords(sourceViewCombinedFilters, view);
await createViewSortRecords(sourceViewCombinedSorts, newView);
await createViewFilterRecords(sourceViewCombinedFilters, newView);
await createViewFilterGroupRecords(
sourceViewCombinedFilterGroups,
view,
newView,
);
}

Expand Down

0 comments on commit d468204

Please sign in to comment.