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

Fix view filter creation on new view #8199

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
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 @@ -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
Loading