mirror of
https://github.com/navikt/aksel.git
synced 2026-11-23 21:24:06 +00:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21c119448f | ||
|
|
07a2d99798 | ||
|
|
d31d7a54a3 | ||
|
|
1c8e767038 | ||
|
|
2245e16b15 | ||
|
|
9c0a933b38 | ||
|
|
a1c75c0ed7 | ||
|
|
cd1abf54b5 | ||
|
|
d13727b130 | ||
|
|
b92ef1b486 | ||
|
|
6a01e3dac4 | ||
|
|
7dbf1d5382 |
No files matched your search
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"@navikt/ds-react": patch
|
||||
---
|
||||
|
||||
Button: Preserve keyboard modifiers during native Space activation.
|
||||
Vendored
+10
-3
@@ -2,10 +2,17 @@
|
||||
"cssVariables.lookupFiles": ["@navikt/core/tokens/dist/tokens.css"],
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"files.watcherExclude": {
|
||||
"**/.git/objects/**": true,
|
||||
"**/.git/subtree-cache/**": true,
|
||||
"**/node_modules/**": true,
|
||||
"**/.yarn/**": true,
|
||||
"**/dist": true,
|
||||
"**/esm": true,
|
||||
"**/cjs": true
|
||||
"**/dist/**": true,
|
||||
"**/esm/**": true,
|
||||
"**/cjs/**": true,
|
||||
"**/lib/**": true,
|
||||
"**/@navikt/aksel-icons/src/**": true,
|
||||
"**/.next/**": true,
|
||||
"**/storybook-static/**": true
|
||||
},
|
||||
"playwright.reuseBrowser": true,
|
||||
"js/ts.tsdk.path": "node_modules/typescript/lib",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @navikt/aksel-icons
|
||||
|
||||
## 8.23.1
|
||||
|
||||
## 8.23.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-icons",
|
||||
"version": "8.23.0",
|
||||
"version": "8.23.1",
|
||||
"author": "Aksel | Nav",
|
||||
"homepage": "https://aksel.nav.no/ikoner",
|
||||
"repository": {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @navikt/aksel-stylelint
|
||||
|
||||
## 8.23.1
|
||||
|
||||
## 8.23.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-stylelint",
|
||||
"version": "8.23.0",
|
||||
"version": "8.23.1",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=18.12.0"
|
||||
@@ -43,8 +43,8 @@
|
||||
"dev": "yarn watch:lint"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-css": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"@navikt/ds-css": "^8.23.1",
|
||||
"@navikt/ds-tokens": "^8.23.1",
|
||||
"concurrently": "10.0.6",
|
||||
"postcss-selector-parser": "^7.1.7",
|
||||
"postcss-value-parser": "^4.2.0",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @navikt/aksel
|
||||
|
||||
## 8.23.1
|
||||
|
||||
## 8.23.0
|
||||
|
||||
## 8.22.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel",
|
||||
"version": "8.23.0",
|
||||
"version": "8.23.1",
|
||||
"description": "Aksel command line interface. Codemods and other utilities for Aksel users.",
|
||||
"author": "Aksel | Nav designsystem team",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @navikt/ds-css
|
||||
|
||||
## 8.23.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- DataGrid: Change `overflow:hidden` to `min-height:0` and `min-width:0` on root ([#5568](https://github.com/navikt/aksel/pull/5568))
|
||||
|
||||
## 8.23.0
|
||||
|
||||
## 8.22.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-css",
|
||||
"version": "8.23.0",
|
||||
"version": "8.23.1",
|
||||
"description": "CSS for Nav Designsystem",
|
||||
"author": "Aksel | Nav designsystem team",
|
||||
"keywords": [
|
||||
@@ -32,7 +32,7 @@
|
||||
"css:get-version": "node config/get-version.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.1",
|
||||
"browserslist": "^4.28.7",
|
||||
"esbuild": "^0.28.2",
|
||||
"fast-glob": "3.3.3",
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
/* Makes DataGridRoot shrink inside a height-limited flex container */
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.aksel-data-table__frame {
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# @navikt/ds-react
|
||||
|
||||
## 8.23.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- DataGrid: Keyboard navigation in table no longer prevents shift+tabbing away from the table ([`7dbf1d5`](https://github.com/navikt/aksel/commit/7dbf1d5382367837b1f43fc76ca57d986218b64d))
|
||||
|
||||
- Button: Preserve keyboard modifiers during native Space activation. ([#5564](https://github.com/navikt/aksel/pull/5564))
|
||||
|
||||
- DataGrid.Table: Temporarily removed `topContent` and `bottomContent` props. ([#5579](https://github.com/navikt/aksel/pull/5579))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-tokens@8.23.1
|
||||
- @navikt/aksel-icons@8.23.1
|
||||
|
||||
## 8.23.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-react",
|
||||
"version": "8.23.0",
|
||||
"version": "8.23.1",
|
||||
"description": "React components from the Norwegian Labour and Welfare Administration.",
|
||||
"author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
|
||||
"license": "MIT",
|
||||
@@ -788,8 +788,8 @@
|
||||
"dependencies": {
|
||||
"@floating-ui/react": "0.27.20",
|
||||
"@floating-ui/react-dom": "^2.1.9",
|
||||
"@navikt/aksel-icons": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"@navikt/aksel-icons": "^8.23.1",
|
||||
"@navikt/ds-tokens": "^8.23.1",
|
||||
"date-fns": "^4.0.0",
|
||||
"react-day-picker": "10.0.2"
|
||||
},
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { DataGrid } from "..";
|
||||
import { Pagination } from "../../pagination";
|
||||
import { HStack, VStack } from "../../primitives/stack";
|
||||
import { Detail } from "../../typography";
|
||||
import {
|
||||
type DataGridPlugin,
|
||||
type DataGridPlugins,
|
||||
applyTableContext,
|
||||
useDataGridPlugins,
|
||||
} from "./useDataGridPlugins";
|
||||
|
||||
type InvoiceRow = {
|
||||
id: string;
|
||||
invoiceNumber: string;
|
||||
category: string;
|
||||
status: string;
|
||||
amount: string;
|
||||
};
|
||||
|
||||
const DEMO_ROWS: InvoiceRow[] = [
|
||||
{
|
||||
id: "1",
|
||||
invoiceNumber: "INV-2026-001",
|
||||
category: "Cloud Hosting",
|
||||
status: "Paid",
|
||||
amount: "12 400 kr",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
invoiceNumber: "INV-2026-002",
|
||||
category: "Software License",
|
||||
status: "Pending",
|
||||
amount: "4 850 kr",
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
invoiceNumber: "INV-2026-003",
|
||||
category: "Office Supplies",
|
||||
status: "Paid",
|
||||
amount: "1 290 kr",
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
invoiceNumber: "INV-2026-004",
|
||||
category: "Security Audit",
|
||||
status: "Overdue",
|
||||
amount: "28 000 kr",
|
||||
},
|
||||
{
|
||||
id: "5",
|
||||
invoiceNumber: "INV-2026-005",
|
||||
category: "Hardware",
|
||||
status: "Paid",
|
||||
amount: "19 990 kr",
|
||||
},
|
||||
{
|
||||
id: "6",
|
||||
invoiceNumber: "INV-2026-006",
|
||||
category: "Training",
|
||||
status: "Pending",
|
||||
amount: "7 500 kr",
|
||||
},
|
||||
{
|
||||
id: "7",
|
||||
invoiceNumber: "INV-2026-007",
|
||||
category: "Domain Renewal",
|
||||
status: "Paid",
|
||||
amount: "640 kr",
|
||||
},
|
||||
{
|
||||
id: "8",
|
||||
invoiceNumber: "INV-2026-008",
|
||||
category: "Monitoring",
|
||||
status: "Pending",
|
||||
amount: "3 200 kr",
|
||||
},
|
||||
];
|
||||
|
||||
const DEMO_COLUMNS: DataGrid.Columns<InvoiceRow> = [
|
||||
{
|
||||
id: "invoiceNumber",
|
||||
header: "Invoice",
|
||||
isRowHeader: true,
|
||||
bodyCell: (row) => row.invoiceNumber,
|
||||
},
|
||||
{ id: "category", header: "Category", bodyCell: (row) => row.category },
|
||||
{ id: "status", header: "Status", bodyCell: (row) => row.status },
|
||||
{ id: "amount", header: "Amount", bodyCell: (row) => row.amount },
|
||||
];
|
||||
|
||||
/**
|
||||
* Preview of how `DataGrid` will integrate the plugin API.
|
||||
* Only two lines are added around `DataGrid`'s children:
|
||||
* 1. `useDataGridPlugins(userPlugins)` to order and stabilize plugins
|
||||
* 2. `applyTableContext(plugins, children)` to wrap the grid output
|
||||
*/
|
||||
function PluginAwareDataGrid<RowT>({
|
||||
plugins: userPlugins,
|
||||
children,
|
||||
...dataGridProps
|
||||
}: DataGrid.Props<RowT> & { plugins?: DataGridPlugins }) {
|
||||
const plugins = useDataGridPlugins(userPlugins);
|
||||
|
||||
return (
|
||||
<DataGrid {...dataGridProps}>
|
||||
{applyTableContext(plugins, children)}
|
||||
</DataGrid>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Example first-party plugin hook.
|
||||
* The consumer owns pagination state; the hook returns a memoized `DataGridPlugin`
|
||||
* that wraps the table with Aksel's `<Pagination />`.
|
||||
*/
|
||||
function useDummyPaginationPlugin({
|
||||
page,
|
||||
pageSize,
|
||||
totalItems,
|
||||
onPageChange,
|
||||
}: {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
totalItems: number;
|
||||
onPageChange: (nextPage: number) => void;
|
||||
}): DataGridPlugin {
|
||||
return useMemo(() => {
|
||||
const pageCount = Math.max(1, Math.ceil(totalItems / pageSize));
|
||||
const start = (page - 1) * pageSize + 1;
|
||||
const end = Math.min(page * pageSize, totalItems);
|
||||
|
||||
return {
|
||||
transformTableContext: (children) => (
|
||||
<VStack gap="space-12" data-plugin="pagination">
|
||||
{children}
|
||||
<HStack align="center" justify="space-between" gap="space-16" wrap>
|
||||
<Detail>
|
||||
Showing {start}–{end} of {totalItems}
|
||||
</Detail>
|
||||
<Pagination
|
||||
page={page}
|
||||
count={pageCount}
|
||||
onPageChange={onPageChange}
|
||||
size="small"
|
||||
/>
|
||||
</HStack>
|
||||
</VStack>
|
||||
),
|
||||
};
|
||||
}, [page, pageSize, totalItems, onPageChange]);
|
||||
}
|
||||
|
||||
const meta: Meta = {
|
||||
title: "ds-react/DataGrid/Plugins",
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
layout: "padded",
|
||||
},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj;
|
||||
|
||||
/**
|
||||
* Shows the intended consumer API for a first-party plugin hook:
|
||||
* state stays in consumer code, the hook returns a memoized `DataGridPlugin`,
|
||||
* and `DataGrid` renders it through `plugins={{ pagination }}`.
|
||||
*/
|
||||
export const PaginationPlugin: Story = {
|
||||
render: function PaginationPluginDemo() {
|
||||
const [page, setPage] = useState(1);
|
||||
const pageSize = 3;
|
||||
|
||||
const paginationPlugin = useDummyPaginationPlugin({
|
||||
page,
|
||||
pageSize,
|
||||
totalItems: DEMO_ROWS.length,
|
||||
onPageChange: setPage,
|
||||
});
|
||||
|
||||
const pageRows = useMemo(
|
||||
() => DEMO_ROWS.slice((page - 1) * pageSize, page * pageSize),
|
||||
[page],
|
||||
);
|
||||
|
||||
return (
|
||||
<PluginAwareDataGrid
|
||||
columns={DEMO_COLUMNS}
|
||||
data={pageRows}
|
||||
getRowId={(row) => row.id}
|
||||
plugins={{ pagination: paginationPlugin }}
|
||||
>
|
||||
<DataGrid.Table />
|
||||
</PluginAwareDataGrid>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,160 +0,0 @@
|
||||
import { renderHook } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import * as consoleWarningModule from "../../utils/helpers/consoleWarning";
|
||||
import {
|
||||
type DataGridPlugin,
|
||||
type DataGridPlugins,
|
||||
applyTableContext,
|
||||
useDataGridPlugins,
|
||||
} from "./useDataGridPlugins";
|
||||
|
||||
const createContextPlugin = (label: string): DataGridPlugin => ({
|
||||
transformTableContext: (children) => `${label}(${children})`,
|
||||
});
|
||||
|
||||
describe("useDataGridPlugins", () => {
|
||||
test("returns a stable empty array when plugins are undefined or empty", () => {
|
||||
const { result, rerender } = renderHook<
|
||||
readonly DataGridPlugin[],
|
||||
{ plugins?: DataGridPlugins }
|
||||
>(({ plugins }) => useDataGridPlugins(plugins), {
|
||||
initialProps: { plugins: undefined },
|
||||
});
|
||||
|
||||
const initialResult = result.current;
|
||||
expect(initialResult).toEqual([]);
|
||||
|
||||
rerender({ plugins: {} });
|
||||
expect(result.current).toBe(initialResult);
|
||||
});
|
||||
|
||||
test("orders known plugins before unknown plugins, ignores prototype keys, and skips non-object entries", () => {
|
||||
const customFirst = createContextPlugin("first");
|
||||
const customSecond = createContextPlugin("second");
|
||||
const pagination = createContextPlugin("pagination");
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useDataGridPlugins({
|
||||
zCustom: customFirst,
|
||||
aCustom: customSecond,
|
||||
pagination,
|
||||
}),
|
||||
);
|
||||
expect(result.current).toEqual([pagination, customFirst, customSecond]);
|
||||
|
||||
const inherited = Object.create({ pagination }) as DataGridPlugins;
|
||||
inherited.custom = customFirst;
|
||||
const { result: inheritedResult } = renderHook(() =>
|
||||
useDataGridPlugins(inherited),
|
||||
);
|
||||
expect(inheritedResult.current).toEqual([customFirst]);
|
||||
|
||||
// Runtime guard: nullish or primitive entries on known or custom keys are skipped instead of crashing WeakMap
|
||||
const { result: invalidEntriesResult } = renderHook(() =>
|
||||
useDataGridPlugins({
|
||||
pagination: undefined,
|
||||
customUndefined: undefined,
|
||||
customNull: null,
|
||||
customPrimitive: "not-an-object",
|
||||
valid: customFirst,
|
||||
} as unknown as DataGridPlugins),
|
||||
);
|
||||
expect(invalidEntriesResult.current).toEqual([customFirst]);
|
||||
});
|
||||
|
||||
test("interns array reference by plugin identity and order across inline objects", () => {
|
||||
const pagination = createContextPlugin("pagination");
|
||||
const customA = createContextPlugin("a");
|
||||
const customB = createContextPlugin("b");
|
||||
|
||||
const { result, rerender } = renderHook<
|
||||
readonly DataGridPlugin[],
|
||||
{ plugins?: DataGridPlugins }
|
||||
>(({ plugins }) => useDataGridPlugins(plugins), {
|
||||
initialProps: { plugins: { customA, pagination } },
|
||||
});
|
||||
|
||||
const first = result.current;
|
||||
expect(Object.isFrozen(first)).toBe(true);
|
||||
|
||||
// New inline object with same plugin instances (even in different key order)
|
||||
rerender({ plugins: { pagination, customA } });
|
||||
expect(result.current).toBe(first);
|
||||
|
||||
// Removing a plugin returns a new array; restoring it returns the interned array
|
||||
rerender({ plugins: { pagination } });
|
||||
expect(result.current).not.toBe(first);
|
||||
expect(result.current).toEqual([pagination]);
|
||||
|
||||
rerender({ plugins: { pagination, customA } });
|
||||
expect(result.current).toBe(first);
|
||||
|
||||
// Changing plugin order or replacing an instance produces a new array
|
||||
rerender({ plugins: { customA, customB } });
|
||||
const ab = result.current;
|
||||
rerender({ plugins: { customB, customA } });
|
||||
expect(result.current).not.toBe(ab);
|
||||
expect(result.current).toEqual([customB, customA]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyTableContext", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
test("wraps children in reverse plugin order and skips plugins without a valid transform", () => {
|
||||
const pagination = createContextPlugin("pagination");
|
||||
const custom = createContextPlugin("custom");
|
||||
const noopPlugin = {} as DataGridPlugin;
|
||||
const invalidPlugin = {
|
||||
transformTableContext: "not-a-function",
|
||||
} as unknown as DataGridPlugin;
|
||||
|
||||
expect(applyTableContext([], "table")).toBe("table");
|
||||
expect(
|
||||
applyTableContext(
|
||||
[pagination, noopPlugin, invalidPlugin, custom],
|
||||
"table",
|
||||
),
|
||||
).toBe("pagination(custom(table))");
|
||||
});
|
||||
|
||||
test("preserves previous content and warns when transformTableContext returns undefined", () => {
|
||||
const warnSpy = vi
|
||||
.spyOn(consoleWarningModule, "consoleWarning")
|
||||
.mockImplementation(() => {});
|
||||
const outer = createContextPlugin("outer");
|
||||
const returnsUndefined: DataGridPlugin = {
|
||||
transformTableContext: () => undefined,
|
||||
};
|
||||
const inner = createContextPlugin("inner");
|
||||
|
||||
expect(applyTableContext([outer, returnsUndefined, inner], "table")).toBe(
|
||||
"outer(inner(table))",
|
||||
);
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining("transformTableContext returned undefined"),
|
||||
);
|
||||
});
|
||||
|
||||
test("catches plugin errors, logs them, and continues applying remaining plugins", () => {
|
||||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const boom = new Error("plugin failure");
|
||||
const outer = createContextPlugin("outer");
|
||||
const broken: DataGridPlugin = {
|
||||
transformTableContext: () => {
|
||||
throw boom;
|
||||
},
|
||||
};
|
||||
const inner = createContextPlugin("inner");
|
||||
|
||||
expect(applyTableContext([outer, broken, inner], "table")).toBe(
|
||||
"outer(inner(table))",
|
||||
);
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
"[Aksel] DataGrid: Plugin threw in transformTableContext:",
|
||||
boom,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,201 +0,0 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { consoleWarning } from "../../utils/helpers/consoleWarning";
|
||||
|
||||
/**
|
||||
* Plugin that extends DataGrid rendering (e.g. wrapping the table in providers
|
||||
* or extra UI). Remember to memoize the plugin object (with `useMemo`) so
|
||||
* DataGrid can skip unnecessary re-renders.
|
||||
*/
|
||||
interface DataGridPlugin {
|
||||
/**
|
||||
* Wraps the table output in context providers or surrounding UI (e.g. pagination).
|
||||
* Runs as a plain function during render. Do not call React hooks directly
|
||||
* inside this function; render a component or provider that calls hooks instead.
|
||||
*/
|
||||
transformTableContext: (children: ReactNode) => ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed order for built-in plugins so behavior doesn't depend on key order
|
||||
* in `plugins={{ ... }}`. Custom plugins are placed after these, in their
|
||||
* original order.
|
||||
*/
|
||||
const PLUGIN_ORDER = ["pagination"] as const;
|
||||
const KNOWN_PLUGINS = new Set<string>(PLUGIN_ORDER);
|
||||
|
||||
type BuiltInDataGridPluginKey = (typeof PLUGIN_ORDER)[number];
|
||||
|
||||
/**
|
||||
* Named plugins passed to DataGrid.
|
||||
*
|
||||
* Keep plugins always present rather than toggling entries conditionally:
|
||||
* adding or removing a plugin that wraps children changes React's tree depth and remounts the grid.
|
||||
* Control active/visible state inside the plugin instead.
|
||||
*/
|
||||
type DataGridPlugins = Partial<
|
||||
Record<BuiltInDataGridPluginKey, DataGridPlugin>
|
||||
> &
|
||||
Record<string, DataGridPlugin>;
|
||||
|
||||
/**
|
||||
* We freeze in dev-mode to enforce immutability of the empty plugin array.
|
||||
* Based on React best practices: https://react.dev/reference/react/createElement#caveats
|
||||
*/
|
||||
const EMPTY_PLUGINS: readonly never[] =
|
||||
process.env.NODE_ENV !== "production" ? Object.freeze([]) : [];
|
||||
|
||||
/**
|
||||
* Turns a `plugins={{ ... }}` object into an ordered, stable plugin array.
|
||||
*
|
||||
* - Orders built-in plugins consistently (`orderPlugins`).
|
||||
* - Keeps the same array reference even when the consumer passes an inline
|
||||
* `plugins={{ pagination }}` object on every render (`internByIdentity`).
|
||||
*/
|
||||
function useDataGridPlugins(
|
||||
userPlugins?: DataGridPlugins,
|
||||
): readonly DataGridPlugin[] {
|
||||
return internByIdentity(orderPlugins(userPlugins));
|
||||
}
|
||||
|
||||
// WeakMap keys must be objects; guard against nullish/primitive entries at runtime.
|
||||
function isPluginObject(value: unknown): value is DataGridPlugin {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Places known plugins first (in `PLUGIN_ORDER`), then unknown plugins in
|
||||
* insertion order.
|
||||
*/
|
||||
function orderPlugins(
|
||||
userPlugins?: DataGridPlugins,
|
||||
): readonly DataGridPlugin[] {
|
||||
if (!userPlugins) {
|
||||
return EMPTY_PLUGINS;
|
||||
}
|
||||
|
||||
const keys = Object.keys(userPlugins);
|
||||
if (keys.length === 0) {
|
||||
return EMPTY_PLUGINS;
|
||||
}
|
||||
|
||||
const ordered: DataGridPlugin[] = [];
|
||||
|
||||
for (const name of PLUGIN_ORDER) {
|
||||
/* TS target does not support Object.hasOwn */
|
||||
if (Object.prototype.hasOwnProperty.call(userPlugins, name)) {
|
||||
const plugin = userPlugins[name];
|
||||
if (isPluginObject(plugin)) {
|
||||
ordered.push(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const name of keys) {
|
||||
if (!KNOWN_PLUGINS.has(name)) {
|
||||
const plugin = userPlugins[name];
|
||||
if (isPluginObject(plugin)) {
|
||||
ordered.push(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ordered;
|
||||
}
|
||||
|
||||
interface InternNode {
|
||||
readonly next: WeakMap<object, InternNode>;
|
||||
array?: readonly object[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tree of WeakMaps where each path represents a sequence of plugin objects.
|
||||
* WeakMap lets unused paths be garbage-collected when plugins go away.
|
||||
*/
|
||||
const internRoot: InternNode = { next: new WeakMap() };
|
||||
|
||||
/**
|
||||
* Returns the same array instance whenever given the same objects in the same order
|
||||
* using a WeakMap trie (prefix tree keyed by object identity).
|
||||
*
|
||||
* Solves inline `plugins={{ pagination }}` props: `useMemo` on the outer object
|
||||
* would miss every render, and mutating a `useRef` during render is unsafe in
|
||||
* StrictMode / concurrent React.
|
||||
*
|
||||
* Each item walks one step down `internRoot`:
|
||||
* ```text
|
||||
* internRoot
|
||||
* └─ [pluginA] ──▶ nodeA (array: [pluginA])
|
||||
* └─ [pluginB] ──▶ nodeAB (array: [pluginA, pluginB])
|
||||
* └─ [pluginB] ──▶ nodeB
|
||||
* └─ [pluginA] ──▶ nodeBA (array: [pluginB, pluginA])
|
||||
* ```
|
||||
*
|
||||
* 1. Walk `internRoot` using each item as a `WeakMap` key, creating nodes as needed.
|
||||
* 2. Cache a copy at the terminal node so future calls with the same sequence return the exact same (`===`) array.
|
||||
* 3. Unused branches are garbage-collected automatically once any plugin object in the path is no longer referenced.
|
||||
*/
|
||||
function internByIdentity<T extends object>(items: readonly T[]): readonly T[] {
|
||||
if (items.length === 0) {
|
||||
return EMPTY_PLUGINS;
|
||||
}
|
||||
|
||||
let node = internRoot;
|
||||
for (const item of items) {
|
||||
let child = node.next.get(item);
|
||||
if (child === undefined) {
|
||||
child = { next: new WeakMap() };
|
||||
node.next.set(item, child);
|
||||
}
|
||||
node = child;
|
||||
}
|
||||
|
||||
if (node.array === undefined) {
|
||||
const copy = items.slice();
|
||||
/* Freeze in dev so accidental mutation fails fast instead of corrupting the shared cache. */
|
||||
node.array =
|
||||
process.env.NODE_ENV !== "production" ? Object.freeze(copy) : copy;
|
||||
}
|
||||
return node.array as readonly T[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps `children` with each plugin's `transformTableContext`.
|
||||
* Runs in reverse so the first plugin wraps outermost.
|
||||
* Synchronous errors are caught and logged, and an `undefined` return preserves
|
||||
* the previous content so one broken plugin doesn't blank or crash the grid.
|
||||
*/
|
||||
function applyTableContext(
|
||||
plugins: readonly DataGridPlugin[],
|
||||
children: ReactNode,
|
||||
): ReactNode {
|
||||
let content = children;
|
||||
|
||||
for (let i = plugins.length - 1; i >= 0; i--) {
|
||||
const transform = plugins[i].transformTableContext;
|
||||
|
||||
if (typeof transform !== "function") {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const next = transform(content);
|
||||
if (next === undefined) {
|
||||
consoleWarning(
|
||||
"DataGrid: Plugin transformTableContext returned undefined. Preserving previous content.",
|
||||
);
|
||||
continue;
|
||||
}
|
||||
content = next;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"[Aksel] DataGrid: Plugin threw in transformTableContext:",
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
export { applyTableContext, useDataGridPlugins };
|
||||
export type { DataGridPlugin, DataGridPlugins };
|
||||
@@ -59,6 +59,7 @@ export const Attachments: Story = {
|
||||
table content scrolls.
|
||||
</BodyShort>
|
||||
</VStack>
|
||||
<Content />
|
||||
<div
|
||||
style={{
|
||||
overflow: "hidden",
|
||||
@@ -69,8 +70,8 @@ export const Attachments: Story = {
|
||||
>
|
||||
<DataGrid columns={getColDefs(overflow)} data={getData(overflow)}>
|
||||
<DataGrid.Table
|
||||
topContent={<Content />}
|
||||
bottomContent={<Content />}
|
||||
// topContent={<Content />}
|
||||
// bottomContent={<Content />}
|
||||
stickyHeader
|
||||
/>
|
||||
</DataGrid>
|
||||
|
||||
@@ -22,6 +22,7 @@ type UseTableKeyboardNavOptions = {
|
||||
|
||||
function useTableKeyboardNav({ enabled }: UseTableKeyboardNavOptions) {
|
||||
const [tableRef, setTableRef] = useState<HTMLTableElement | null>(null);
|
||||
const [isFocusWithin, setIsFocusWithin] = useState(false);
|
||||
const { getTableGrid, activeCell, setActiveCell } = useGridCache(
|
||||
tableRef,
|
||||
enabled,
|
||||
@@ -122,6 +123,7 @@ function useTableKeyboardNav({ enabled }: UseTableKeyboardNavOptions) {
|
||||
* Make sure td/th elements have tabIndex={-1} so they can receive focus on click
|
||||
*/
|
||||
const handleTableFocusIn = useEventCallback((event: FocusEvent): void => {
|
||||
setIsFocusWithin(true);
|
||||
const target = event.target as Element | null;
|
||||
|
||||
if (tableRef && target === tableRef) {
|
||||
@@ -146,6 +148,15 @@ function useTableKeyboardNav({ enabled }: UseTableKeyboardNavOptions) {
|
||||
}
|
||||
});
|
||||
|
||||
const handleTableFocusOut = useEventCallback((event: FocusEvent): void => {
|
||||
if (
|
||||
!(event.relatedTarget instanceof Node) ||
|
||||
!tableRef?.contains(event.relatedTarget)
|
||||
) {
|
||||
setIsFocusWithin(false);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach event listeners for keyboard navigation and focus management.
|
||||
*/
|
||||
@@ -156,16 +167,27 @@ function useTableKeyboardNav({ enabled }: UseTableKeyboardNavOptions) {
|
||||
|
||||
tableRef.addEventListener("keydown", handleTableKeyDown);
|
||||
tableRef.addEventListener("focusin", handleTableFocusIn);
|
||||
tableRef.addEventListener("focusout", handleTableFocusOut);
|
||||
|
||||
return () => {
|
||||
tableRef.removeEventListener("keydown", handleTableKeyDown);
|
||||
tableRef.removeEventListener("focusin", handleTableFocusIn);
|
||||
tableRef.removeEventListener("focusout", handleTableFocusOut);
|
||||
};
|
||||
}, [tableRef, handleTableKeyDown, handleTableFocusIn, enabled]);
|
||||
}, [
|
||||
tableRef,
|
||||
handleTableKeyDown,
|
||||
handleTableFocusIn,
|
||||
handleTableFocusOut,
|
||||
enabled,
|
||||
]);
|
||||
|
||||
return {
|
||||
/* Table should only have tabIndex until the focus is moved inside and is enabled */
|
||||
tabIndex: enabled ? 0 : undefined,
|
||||
/*
|
||||
* Table should only have tabIndex until the focus is moved inside and is enabled
|
||||
* This allows focus to "escape" the table and move to other elements on the page.
|
||||
*/
|
||||
tabIndex: enabled ? (isFocusWithin ? -1 : 0) : undefined,
|
||||
setTableRef,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -138,14 +138,16 @@ interface DataGridTableProps<T> extends React.HTMLAttributes<HTMLTableElement> {
|
||||
* @default "row"
|
||||
*/
|
||||
selectionTrigger?: "row" | "control";
|
||||
|
||||
/* TODO: Temp removed to better integrate with plugins API */
|
||||
/**
|
||||
* Content to render above the table, outside its scrollable area.
|
||||
*/
|
||||
topContent?: React.ReactNode;
|
||||
//topContent?: React.ReactNode;
|
||||
/**
|
||||
* Content to render below the table, outside its scrollable area.
|
||||
*/
|
||||
bottomContent?: React.ReactNode;
|
||||
//bottomContent?: React.ReactNode;
|
||||
}
|
||||
|
||||
const DataGridTableInternal = forwardRef<
|
||||
@@ -169,8 +171,6 @@ const DataGridTableInternal = forwardRef<
|
||||
subRows,
|
||||
sorting,
|
||||
selectionTrigger = "row",
|
||||
topContent,
|
||||
bottomContent,
|
||||
...rest
|
||||
}: DataGridTableProps<unknown>,
|
||||
forwardedRef,
|
||||
@@ -211,31 +211,31 @@ const DataGridTableInternal = forwardRef<
|
||||
|
||||
const tableId = useId(id);
|
||||
|
||||
const hasTopContent = topContent != null && topContent !== false;
|
||||
const hasBottomContent = bottomContent != null && bottomContent !== false;
|
||||
let attachmentPosition: "top" | "bottom" | "both" | undefined;
|
||||
// const hasTopContent = topContent != null && topContent !== false;
|
||||
// const hasBottomContent = bottomContent != null && bottomContent !== false;
|
||||
// let attachmentPosition: "top" | "bottom" | "both" | undefined;
|
||||
|
||||
/* TODO: Need to figure out how to handle this since settings is provided from root, not table itself */
|
||||
const truncateContent = tableSettings?.truncateContent ?? layout !== "auto";
|
||||
|
||||
if (hasTopContent && hasBottomContent) {
|
||||
attachmentPosition = "both";
|
||||
} else if (hasTopContent) {
|
||||
attachmentPosition = "top";
|
||||
} else if (hasBottomContent) {
|
||||
attachmentPosition = "bottom";
|
||||
}
|
||||
// if (hasTopContent && hasBottomContent) {
|
||||
// attachmentPosition = "both";
|
||||
// } else if (hasTopContent) {
|
||||
// attachmentPosition = "top";
|
||||
// } else if (hasBottomContent) {
|
||||
// attachmentPosition = "bottom";
|
||||
// }
|
||||
|
||||
return (
|
||||
<div
|
||||
className="aksel-data-table__frame"
|
||||
data-attachments={attachmentPosition}
|
||||
// data-attachments={attachmentPosition}
|
||||
>
|
||||
{hasTopContent && (
|
||||
{/* {hasTopContent && (
|
||||
<div className="aksel-data-table__attachment" data-attachment="top">
|
||||
{topContent}
|
||||
</div>
|
||||
)}
|
||||
)} */}
|
||||
|
||||
<DataTableContextProvider
|
||||
layout={layout}
|
||||
@@ -314,14 +314,14 @@ const DataGridTableInternal = forwardRef<
|
||||
</table>
|
||||
</TableElementWrapper>
|
||||
</DataTableContextProvider>
|
||||
{hasBottomContent && (
|
||||
{/* {hasBottomContent && (
|
||||
<div
|
||||
className="aksel-data-table__attachment"
|
||||
data-attachment="bottom"
|
||||
>
|
||||
{bottomContent}
|
||||
</div>
|
||||
)}
|
||||
)} */}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @navikt/ds-tailwind
|
||||
|
||||
## 8.23.1
|
||||
|
||||
## 8.23.0
|
||||
|
||||
## 8.22.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-tailwind",
|
||||
"version": "8.23.0",
|
||||
"version": "8.23.1",
|
||||
"description": "Tailwind config based on @navikt/ds-tokens",
|
||||
"author": "Aksel | Nav designsystem team",
|
||||
"keywords": [
|
||||
@@ -28,7 +28,7 @@
|
||||
},
|
||||
"homepage": "https://aksel.nav.no/grunnleggende/kode/tailwind/",
|
||||
"devDependencies": {
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.1",
|
||||
"@types/node": "^24.10.9",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"tsx": "^4.23.15",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @navikt/ds-tokens
|
||||
|
||||
## 8.23.1
|
||||
|
||||
## 8.23.0
|
||||
|
||||
## 8.22.1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-tokens",
|
||||
"version": "8.23.0",
|
||||
"version": "8.23.1",
|
||||
"description": "Design-tokens for Nav designsystem",
|
||||
"author": "Aksel | Nav designsystem team",
|
||||
"keywords": [
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## 8.23.1
|
||||
|
||||
### @navikt/ds-css
|
||||
|
||||
- DataGrid: Change `overflow:hidden` to `min-height:0` and `min-width:0` on root ([#5568](https://github.com/navikt/aksel/pull/5568))
|
||||
|
||||
### @navikt/ds-react
|
||||
|
||||
- DataGrid: Keyboard navigation in table no longer prevents shift+tabbing away from the table ([`7dbf1d5`](https://github.com/navikt/aksel/commit/7dbf1d5382367837b1f43fc76ca57d986218b64d))
|
||||
|
||||
- Button: Preserve keyboard modifiers during native Space activation. ([#5564](https://github.com/navikt/aksel/pull/5564))
|
||||
|
||||
- DataGrid.Table: Temporarily removed `topContent` and `bottomContent` props. ([#5579](https://github.com/navikt/aksel/pull/5579))
|
||||
|
||||
## 8.23.0
|
||||
|
||||
### @navikt/aksel-icons
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
"sanity:update": "yarn workspace website update:sanity"
|
||||
},
|
||||
"dependencies": {
|
||||
"@navikt/aksel": "^8.23.0",
|
||||
"@navikt/aksel-icons": "^8.23.0",
|
||||
"@navikt/ds-css": "^8.23.0",
|
||||
"@navikt/ds-react": "^8.23.0",
|
||||
"@navikt/ds-tailwind": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.0"
|
||||
"@navikt/aksel": "^8.23.1",
|
||||
"@navikt/aksel-icons": "^8.23.1",
|
||||
"@navikt/ds-css": "^8.23.1",
|
||||
"@navikt/ds-react": "^8.23.1",
|
||||
"@navikt/ds-tailwind": "^8.23.1",
|
||||
"@navikt/ds-tokens": "^8.23.1"
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,12 @@
|
||||
"dependencies": {
|
||||
"@portabletext/react": "^8.0.1",
|
||||
"@sanity/client": "7.27.0",
|
||||
"@sanity/code-input": "7.3.8",
|
||||
"@sanity/color-input": "6.1.8",
|
||||
"@sanity/code-input": "7.3.16",
|
||||
"@sanity/color-input": "6.1.10",
|
||||
"@sanity/image-url": "2.1.1",
|
||||
"@sanity/locale-nb-no": "1.1.39",
|
||||
"@sanity/preview-url-secret": "4.1.5",
|
||||
"@sanity/table": "3.1.20",
|
||||
"@sanity/table": "3.1.21",
|
||||
"@sanity/vision": "6.17.0",
|
||||
"date-fns": "^4.0.0",
|
||||
"lodash": "4.18.1",
|
||||
@@ -31,15 +31,15 @@
|
||||
"react-rx": "^5.1.1",
|
||||
"rxjs": "^7.8.2",
|
||||
"sanity": "6.17.0",
|
||||
"sanity-plugin-iframe-pane": "5.0.41",
|
||||
"sanity-plugin-media": "6.1.8",
|
||||
"sanity-plugin-iframe-pane": "5.0.43",
|
||||
"sanity-plugin-media": "6.6.3",
|
||||
"sanity-plugin-references": "1.2.0",
|
||||
"styled-components": "6.6.0",
|
||||
"swr": "^2.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sanity/blueprints": "0.28.0",
|
||||
"@sanity/export": "7.0.3",
|
||||
"@sanity/blueprints": "0.34.1",
|
||||
"@sanity/export": "7.1.1",
|
||||
"@sanity/functions": "1.11.0",
|
||||
"@sanity/schema": "6.17.0",
|
||||
"@types/lodash": "4.17.25",
|
||||
|
||||
@@ -11,7 +11,7 @@ export const locations: DocumentLocationResolver = (params, context) => {
|
||||
const doc$ = context.documentStore.listenQuery(
|
||||
`*[(_type != $type && references($id)) || _id == $id && _type in $articleTypes ]{_type, slug, title, heading, "tema": undertema[]->tema->title}`,
|
||||
{ id: params.id, type: params.type, articleTypes: validTypes },
|
||||
{ perspective: "previewDrafts" },
|
||||
{ perspective: "drafts" },
|
||||
) as Observable<
|
||||
| {
|
||||
_type: string;
|
||||
|
||||
@@ -6,4 +6,11 @@ if (process.env.LOCAL_DATASET_OVERRIDE === "development") {
|
||||
SANITY_DATASET = "development";
|
||||
}
|
||||
|
||||
export { SANITY_API_VERSION, SANITY_DATASET, SANITY_PROJECT_ID };
|
||||
const DEFAULT_OUTDATED_THRESHOLD = 365;
|
||||
|
||||
export {
|
||||
SANITY_API_VERSION,
|
||||
SANITY_DATASET,
|
||||
SANITY_PROJECT_ID,
|
||||
DEFAULT_OUTDATED_THRESHOLD,
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { differenceInDays, differenceInMonths, format } from "date-fns";
|
||||
import { differenceInDays, format } from "date-fns";
|
||||
import { type ComponentType, useState } from "react";
|
||||
import {
|
||||
type ObjectFieldProps,
|
||||
@@ -8,8 +8,11 @@ import {
|
||||
useFormValue,
|
||||
} from "sanity";
|
||||
import { HourglassBottomFilledIcon } from "@navikt/aksel-icons";
|
||||
import { BodyLong, Box, Button, InfoCard } from "@navikt/ds-react";
|
||||
import { SANITY_API_VERSION } from "../../sanity.env";
|
||||
import { BodyLong, Button, InfoCard } from "@navikt/ds-react";
|
||||
import {
|
||||
DEFAULT_OUTDATED_THRESHOLD,
|
||||
SANITY_API_VERSION,
|
||||
} from "../../sanity.env";
|
||||
|
||||
const UpdateInfoInput: ComponentType<ObjectInputProps> = (props) => {
|
||||
const { onChange, readOnly } = props;
|
||||
@@ -45,37 +48,31 @@ const UpdateInfoInput: ComponentType<ObjectInputProps> = (props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Box marginBlock="space-16 space-0">
|
||||
<Button
|
||||
size="small"
|
||||
variant="primary"
|
||||
loading={updating}
|
||||
onClick={handleUpdate}
|
||||
disabled={readOnly}
|
||||
data-color="neutral"
|
||||
>
|
||||
Oppdater godkjenningsdato
|
||||
</Button>
|
||||
</Box>
|
||||
<Button
|
||||
size="small"
|
||||
variant="primary"
|
||||
loading={updating}
|
||||
onClick={handleUpdate}
|
||||
disabled={readOnly}
|
||||
data-color="neutral"
|
||||
>
|
||||
Oppdater godkjenningsdato
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
const UpdateInfo: ComponentType<ObjectFieldProps> = (props) => {
|
||||
const articleType = useFormValue(["_type"]);
|
||||
|
||||
const verified = useFormValue(["updateInfo", "lastVerified"]);
|
||||
|
||||
if (typeof verified !== "string") {
|
||||
return null;
|
||||
}
|
||||
|
||||
// oxlint-disable-next-line react/purity -- Age relative to now is intended.
|
||||
const diff = differenceInMonths(new Date(), new Date(verified));
|
||||
// oxlint-disable-next-line react/purity -- Age relative to now is intended.
|
||||
const diffInDays = differenceInDays(new Date(), new Date(verified));
|
||||
const outDated = diff >= (articleType === "aksel_artikkel" ? 12 : 6);
|
||||
const outdated = diffInDays >= DEFAULT_OUTDATED_THRESHOLD;
|
||||
|
||||
if (!outDated) {
|
||||
if (!outdated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -91,10 +88,8 @@ const UpdateInfo: ComponentType<ObjectFieldProps> = (props) => {
|
||||
Artikkelen trenger ny godkjenning. Les gjennom og oppdater innholdet,
|
||||
for så å oppdatere godkjenningsdatoen.
|
||||
</BodyLong>
|
||||
<BodyLong size="small">
|
||||
{articleType === "aksel_artikkel"
|
||||
? "En God praksis-artikkel regnes som utdatert etter 12 måneder."
|
||||
: "En Designsystem-artikkel regnes som utdatert etter 6 måneder."}
|
||||
<BodyLong size="small" spacing>
|
||||
En artikkel regnes som utdatert etter 12 måneder.
|
||||
</BodyLong>
|
||||
{props.children}
|
||||
</InfoCard.Content>
|
||||
|
||||
@@ -16,7 +16,7 @@ export const GrunnleggendeArtikkel = defineType({
|
||||
name: "ds_artikkel",
|
||||
type: "document",
|
||||
groups: SanityTabGroups,
|
||||
...artikkelPreview("Grunnleggende", 6),
|
||||
...artikkelPreview("Grunnleggende"),
|
||||
renderMembers: (members) => {
|
||||
return [
|
||||
...members,
|
||||
|
||||
@@ -18,7 +18,7 @@ export const KomponentArtikkel = defineType({
|
||||
name: "komponent_artikkel",
|
||||
type: "document",
|
||||
groups: SanityTabGroups,
|
||||
...artikkelPreview("Komponenter", 6),
|
||||
...artikkelPreview("Komponenter"),
|
||||
renderMembers: (members) => {
|
||||
return [
|
||||
...members,
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { differenceInMonths } from "date-fns";
|
||||
import { differenceInDays } from "date-fns";
|
||||
import { HourglassBottomFilledIcon } from "@navikt/aksel-icons";
|
||||
import { DEFAULT_OUTDATED_THRESHOLD } from "../../../sanity.env";
|
||||
|
||||
const isAfter = (date: string, threshold: number) =>
|
||||
differenceInMonths(new Date(), new Date(date)) >= threshold;
|
||||
differenceInDays(new Date(), new Date(date)) >= threshold;
|
||||
|
||||
/**
|
||||
* @param _type document type
|
||||
* @param threshold number of months before article is considered outdated in **months**
|
||||
* @param threshold number of days before article is considered outdated
|
||||
*/
|
||||
export const artikkelPreview = (_type: string, threshold: number = 12) => {
|
||||
export const artikkelPreview = (
|
||||
_type: string,
|
||||
threshold: number = DEFAULT_OUTDATED_THRESHOLD,
|
||||
) => {
|
||||
return {
|
||||
preview: {
|
||||
select: {
|
||||
|
||||
@@ -16,7 +16,7 @@ export const TemplatesArtikkel = defineType({
|
||||
name: "templates_artikkel",
|
||||
type: "document",
|
||||
groups: SanityTabGroups,
|
||||
...artikkelPreview("Mønster/Maler", 6),
|
||||
...artikkelPreview("Mønster/Maler"),
|
||||
renderMembers: (members) => {
|
||||
return [
|
||||
...members,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ComponentType } from "react";
|
||||
import type { StructureBuilder } from "sanity/structure";
|
||||
import { FileXMarkIcon, HouseIcon } from "@navikt/aksel-icons";
|
||||
import { SANITY_API_VERSION } from "../sanity.env";
|
||||
import { DEFAULT_OUTDATED_THRESHOLD, SANITY_API_VERSION } from "../sanity.env";
|
||||
import type { AllArticleDocumentsT } from "../schema/schema.config";
|
||||
|
||||
type ArticleDocumentType = AllArticleDocumentsT;
|
||||
@@ -55,7 +55,7 @@ export function listDraftArticles(
|
||||
export function listOutdatedArticles(
|
||||
S: StructureBuilder,
|
||||
type: ArticleDocumentType,
|
||||
threshold: number = 365,
|
||||
threshold: number = DEFAULT_OUTDATED_THRESHOLD,
|
||||
) {
|
||||
return S.listItem({
|
||||
id: `article_${type}_outdated`,
|
||||
@@ -65,7 +65,7 @@ export function listOutdatedArticles(
|
||||
S.documentTypeList(type)
|
||||
.title("Artikler")
|
||||
.filter(
|
||||
`_type == $type && (dateTime(updateInfo.lastVerified + "T00:00:00Z") < dateTime(now()) - 60*60*24*$threshold) && ${IS_PUBLISHED}`,
|
||||
`_type == $type && (dateTime(updateInfo.lastVerified + "T00:00:00Z") < dateTime(now()) - 60*60*24*$threshold)`,
|
||||
)
|
||||
.apiVersion(SANITY_API_VERSION)
|
||||
.params({ type, threshold })
|
||||
|
||||
@@ -19,7 +19,7 @@ export function grunnleggendeStructure(S: StructureBuilder) {
|
||||
landingssideItem(S, "grunnleggende_landingsside"),
|
||||
S.divider(),
|
||||
listDraftArticles(S, "ds_artikkel"),
|
||||
listOutdatedArticles(S, "ds_artikkel", 180),
|
||||
listOutdatedArticles(S, "ds_artikkel"),
|
||||
|
||||
S.divider(),
|
||||
...categoryPanes(
|
||||
|
||||
@@ -19,7 +19,7 @@ export function komponenterStructure(S: StructureBuilder) {
|
||||
landingssideItem(S, "komponenter_landingsside"),
|
||||
S.divider(),
|
||||
listDraftArticles(S, "komponent_artikkel"),
|
||||
listOutdatedArticles(S, "komponent_artikkel", 180),
|
||||
listOutdatedArticles(S, "komponent_artikkel"),
|
||||
|
||||
S.divider(),
|
||||
...categoryPanes(
|
||||
|
||||
@@ -19,7 +19,7 @@ export function monsterStructure(S: StructureBuilder) {
|
||||
landingssideItem(S, "templates_landingsside"),
|
||||
S.divider(),
|
||||
listDraftArticles(S, "templates_artikkel"),
|
||||
listOutdatedArticles(S, "templates_artikkel", 180),
|
||||
listOutdatedArticles(S, "templates_artikkel"),
|
||||
|
||||
S.divider(),
|
||||
...categoryPanes(
|
||||
|
||||
+5
-4
@@ -1,4 +1,5 @@
|
||||
import { differenceInMonths, isSameDay } from "date-fns";
|
||||
import { DEFAULT_OUTDATED_THRESHOLD } from "aksel-sanity-studio/env";
|
||||
import { differenceInDays, isSameDay } from "date-fns";
|
||||
import type { Metadata } from "next";
|
||||
import { type PortableTextBlock, stegaClean } from "next-sanity";
|
||||
import { draftMode } from "next/headers";
|
||||
@@ -177,11 +178,11 @@ async function CachedArticle({
|
||||
pageData?.updateInfo?.lastVerified ??
|
||||
pageData?.publishedAt ??
|
||||
pageData?._updatedAt;
|
||||
|
||||
// oxlint-disable-next-line react/purity -- Server Component, rendered once per request.
|
||||
const outdated = differenceInMonths(new Date(), new Date(verifiedDate)) >= 12;
|
||||
const writers = getValidRenderArray(pageData.writers);
|
||||
const diffInDays = differenceInDays(new Date(), new Date(verifiedDate));
|
||||
const outdated = diffInDays >= DEFAULT_OUTDATED_THRESHOLD;
|
||||
|
||||
const writers = getValidRenderArray(pageData.writers);
|
||||
const undertema = getValidRenderArray(pageData.undertema);
|
||||
const relevanteArtikler = getValidRenderArray(pageData.relevante_artikler);
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
"@babel/core": "^7.19.0",
|
||||
"@babel/parser": "^7.27.5",
|
||||
"@babel/traverse": "^7.27.4",
|
||||
"@google-cloud/bigquery": "^9.5.0",
|
||||
"@google-cloud/bigquery": "^9.6.1",
|
||||
"@playwright/test": "1.61.1",
|
||||
"@portabletext/block-tools": "^6.0.7",
|
||||
"@portabletext/markdown": "^2.5.1",
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@navikt/aksel-icons": "^8.23.0",
|
||||
"@navikt/ds-css": "^8.23.0",
|
||||
"@navikt/ds-react": "^8.23.0",
|
||||
"@navikt/aksel-icons": "^8.23.1",
|
||||
"@navikt/ds-css": "^8.23.1",
|
||||
"@navikt/ds-react": "^8.23.1",
|
||||
"fuse.js": "7.4.2",
|
||||
"react": "19.3.1",
|
||||
"react-dom": "19.3.1"
|
||||
@@ -25,7 +25,7 @@
|
||||
"@types/node": "^24.10.9",
|
||||
"@types/react": "19.2.14",
|
||||
"@types/react-dom": "19.2.3",
|
||||
"@vitejs/plugin-react": "^6.2.1",
|
||||
"@vitejs/plugin-react": "^6.3.0",
|
||||
"typescript": "6.0.3",
|
||||
"vite": "^8.3.5",
|
||||
"vite-plugin-singlefile": "^2.3.4"
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
"devDependencies": {
|
||||
"@modelcontextprotocol/inspector": "^2.11.0",
|
||||
"@modelcontextprotocol/sdk": "^1.32.0",
|
||||
"@navikt/aksel": "^8.23.0",
|
||||
"@navikt/aksel-icons": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"@navikt/aksel": "^8.23.1",
|
||||
"@navikt/aksel-icons": "^8.23.1",
|
||||
"@navikt/ds-tokens": "^8.23.1",
|
||||
"@sanity/client": "7.27.0",
|
||||
"@types/express": "^5.0.3",
|
||||
"@types/node": "^24.10.9",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"sync-imports": "tsx --tsconfig ./scripts/tsconfig.json ./scripts/generate-imports.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "^7.29.0",
|
||||
"@babel/preset-env": "^7.29.14",
|
||||
"@babel/preset-react": "^7.28.5",
|
||||
"@babel/preset-typescript": "^7.28.5",
|
||||
"@types/node": "^24.10.9",
|
||||
@@ -20,9 +20,9 @@
|
||||
"typescript": "6.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@navikt/aksel-icons": "^8.23.0",
|
||||
"@navikt/ds-css": "^8.23.0",
|
||||
"@navikt/ds-react": "^8.23.0",
|
||||
"@navikt/aksel-icons": "^8.23.1",
|
||||
"@navikt/ds-css": "^8.23.1",
|
||||
"@navikt/ds-react": "^8.23.1",
|
||||
"react": "19.3.1"
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -76,12 +76,12 @@
|
||||
"@actions/core": "^3.0.1",
|
||||
"@changesets/cli": "2.31.1",
|
||||
"@github-ui/storybook-addon-performance-panel": "^1.3.1",
|
||||
"@storybook/addon-a11y": "^10.6.3",
|
||||
"@storybook/addon-docs": "^10.6.3",
|
||||
"@storybook/addon-themes": "^10.6.3",
|
||||
"@storybook/addon-vitest": "^10.6.3",
|
||||
"@storybook/nextjs-vite": "^10.6.3",
|
||||
"@storybook/react-vite": "^10.6.3",
|
||||
"@storybook/addon-a11y": "^10.6.7",
|
||||
"@storybook/addon-docs": "^10.6.7",
|
||||
"@storybook/addon-themes": "^10.6.7",
|
||||
"@storybook/addon-vitest": "^10.6.7",
|
||||
"@storybook/nextjs-vite": "^10.6.7",
|
||||
"@storybook/react-vite": "^10.6.7",
|
||||
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
|
||||
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
||||
"@types/node": "^24.10.9",
|
||||
@@ -94,7 +94,7 @@
|
||||
"cross-env": "^10.1.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-aksel-local": "*",
|
||||
"eslint-plugin-storybook": "^10.6.3",
|
||||
"eslint-plugin-storybook": "^10.6.7",
|
||||
"eslint-plugin-testing-library": "^7.16.0",
|
||||
"fast-glob": "3.3.3",
|
||||
"husky": "^9.1.7",
|
||||
@@ -105,7 +105,7 @@
|
||||
"react": "19.3.1",
|
||||
"react-docgen-typescript": "2.4.0",
|
||||
"react-dom": "19.3.1",
|
||||
"storybook": "^10.6.3",
|
||||
"storybook": "^10.6.7",
|
||||
"stylelint": "^17.15.0",
|
||||
"stylelint-config-standard": "^40.0.0",
|
||||
"stylelint-declaration-block-no-ignored-properties": "^3.0.0",
|
||||
|
||||
Reference in new issue
Block a user