Skip to content
Draft
Show file tree
Hide file tree
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 @@ -56,6 +56,7 @@ describe("update content database view", () => {
},
],
collapsedGroupIds: ["status:done"],
propertyOrderIds: ["name", "status"],
hideEmptyGroups: true,
calculations: { status: "count_values" },
wrapCells: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import {
databaseNextBuilderHydrationSource,
databasePreviewItem,
databaseItemPagePath,
orderDatabasePropertiesForView,
reorderDatabaseViewProperty,
databaseRecordBuilderContinuationAttempt,
databaseSourceOperationIsPending,
databaseSourceChangeSetsAreComplete,
Expand Down Expand Up @@ -1270,6 +1272,87 @@ const baseProperty = (
editable: true,
});

describe("database property column order", () => {
const view = {
id: "table",
name: "Table",
type: "table" as const,
sorts: [],
filters: [],
columnWidths: {},
};
const propertyIds = (properties: DocumentProperty[]) =>
properties.map((property) => property.definition.id);

it("moves a visible property before another while preserving hidden columns", () => {
const allProperties = [
baseProperty("alpha"),
baseProperty("hidden"),
baseProperty("bravo"),
baseProperty("charlie"),
];
const visibleProperties = [
allProperties[0],
allProperties[2],
allProperties[3],
];

const reordered = reorderDatabaseViewProperty(
view,
"charlie",
"alpha",
{ allProperties, visibleProperties },
"before",
);

expect(reordered.propertyOrderIds).toEqual([
"charlie",
"alpha",
"hidden",
"bravo",
]);
expect(
propertyIds(orderDatabasePropertiesForView(allProperties, reordered)),
).toEqual(["charlie", "alpha", "hidden", "bravo"]);
});

it("keeps surviving explicit order and appends new properties", () => {
const properties = [
baseProperty("alpha"),
baseProperty("bravo"),
baseProperty("charlie"),
baseProperty("delta"),
];

expect(
propertyIds(
orderDatabasePropertiesForView(properties, {
propertyOrderIds: ["deleted", "charlie", "alpha", "bravo"],
}),
),
).toEqual(["charlie", "alpha", "bravo", "delta"]);
});

it("does not reorder from or onto a hidden property", () => {
const allProperties = [
baseProperty("alpha"),
baseProperty("hidden"),
baseProperty("bravo"),
];
const visibleProperties = [allProperties[0], allProperties[2]];

expect(
reorderDatabaseViewProperty(
view,
"hidden",
"alpha",
{ allProperties, visibleProperties },
"before",
),
).toBe(view);
});
});

const builderRowItem = (id: string): ContentDatabaseItem => ({
id: `item-${id}`,
databaseId: "database",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@
);
const orderedProperties = useMemo(
() => orderDatabasePropertiesForView(properties, activeView),
[properties, activeView],

Check warning on line 996 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React hook useMemo depends on `properties`, which changes every render
);
const sorts = activeView.sorts;
const filters = activeView.filters;
Expand Down Expand Up @@ -1051,7 +1051,7 @@
orderedProperties.filter((property) =>
isDatabasePropertyVisibleInView(property, items, activeView),
),
[orderedProperties, items, activeView],

Check warning on line 1054 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React hook useMemo depends on `items`, which changes every render
);
const hiddenProperties = useMemo(
() =>
Expand All @@ -1059,7 +1059,7 @@
(property) =>
!isDatabasePropertyVisibleInView(property, items, activeView),
),
[orderedProperties, items, activeView],

Check warning on line 1062 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React hook useMemo depends on `items`, which changes every render
);
const visibleItems = useMemo(
() =>
Expand All @@ -1071,7 +1071,7 @@
sorts,
filterMode,
),
[items, properties, searchQuery, filters, sorts, filterMode],

Check warning on line 1074 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React hook useMemo depends on `properties`, which changes every render

Check warning on line 1074 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React hook useMemo depends on `items`, which changes every render
);
const screenVisibleItems = useMemo(
() =>
Expand Down Expand Up @@ -1259,7 +1259,7 @@
if (!acquireDatabaseSourceOperation(refreshSourceInFlightRef, sourceId)) {
return false;
}
refreshSource.mutate(

Check warning on line 1262 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'refreshSource'
{
documentId: document.id,
sourceId,
Expand All @@ -1277,7 +1277,7 @@
);
return true;
},
[document.id, refreshSource.mutate],

Check warning on line 1280 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React Hook useCallback has unnecessary dependency: refreshSource.mutate
);
const handleBuilderContinuationError = useCallback(
(continuationKey: string) => {
Expand Down Expand Up @@ -1314,7 +1314,7 @@
}
const pump = () => {
let result: ProcessBuilderBodyHydrationResponse | null = null;
processBuilderBodies.mutate(

Check warning on line 1317 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'processBuilderBodies'
{ sourceId, ...request },
{
onSuccess: (nextResult) => {
Expand Down Expand Up @@ -1343,7 +1343,7 @@
pump();
return true;
},
[processBuilderBodies.mutate],

Check warning on line 1346 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React Hook useCallback has unnecessary dependency: processBuilderBodies.mutate
);

useEffect(() => {
Expand Down Expand Up @@ -1498,7 +1498,7 @@
hostDocumentId,
renderMode,
source,
views: viewConfig.views,

Check warning on line 1501 in templates/content/app/components/editor/database/DatabaseView.tsx

View workflow job for this annotation

GitHub Actions / Lint & format

react-hooks(exhaustive-deps)

React Hook useEffect has a missing dependency: 'viewConfig.views'
activeView,
searchQuery,
sorts,
Expand Down Expand Up @@ -2431,6 +2431,14 @@
: nextViewConfig,
);
},
onError: (err) => {
toast.error(dbText("failedToSaveView"), {
description:
err instanceof Error
? err.message
: dbText("somethingWentWrong"),
});
},
},
);
}, 350);
Expand Down
Loading