@instructure/platform-modules 0.3.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/adapters/canvasGraphql/index.d.ts +4 -40
- package/dist/adapters/canvasGraphql/index.d.ts.map +1 -1
- package/dist/adapters/canvasGraphql/normalize.d.ts +9 -220
- package/dist/adapters/canvasGraphql/normalize.d.ts.map +1 -1
- package/dist/adapters/canvasGraphql/queries.d.ts +7 -49
- package/dist/adapters/canvasGraphql/queries.d.ts.map +1 -1
- package/dist/adapters/inMemory.d.ts +0 -40
- package/dist/adapters/inMemory.d.ts.map +1 -1
- package/dist/adapters/limits.d.ts +3 -81
- package/dist/adapters/limits.d.ts.map +1 -1
- package/dist/adapters/types.d.ts +11 -61
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/cache/invalidate.d.ts +0 -46
- package/dist/cache/invalidate.d.ts.map +1 -1
- package/dist/cache/keys.d.ts +3 -55
- package/dist/cache/keys.d.ts.map +1 -1
- package/dist/components/FilterChips.d.ts +4 -17
- package/dist/components/FilterChips.d.ts.map +1 -1
- package/dist/components/ModuleCard.d.ts +5 -29
- package/dist/components/ModuleCard.d.ts.map +1 -1
- package/dist/components/ModuleCard.stories.d.ts +14 -1
- package/dist/components/ModuleCard.stories.d.ts.map +1 -1
- package/dist/components/ModuleItemRow.d.ts +0 -10
- package/dist/components/ModuleItemRow.d.ts.map +1 -1
- package/dist/components/ModuleNumberBadge.d.ts +0 -1
- package/dist/components/ModuleNumberBadge.d.ts.map +1 -1
- package/dist/components/ModulesList.d.ts +2 -54
- package/dist/components/ModulesList.d.ts.map +1 -1
- package/dist/components/ModulesList.stories.d.ts +11 -128
- package/dist/components/ModulesList.stories.d.ts.map +1 -1
- package/dist/components/StatusPill.d.ts +4 -6
- package/dist/components/StatusPill.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/labels.d.ts +8 -78
- package/dist/components/labels.d.ts.map +1 -1
- package/dist/components/lightThemeDecorator.d.ts +3 -0
- package/dist/components/lightThemeDecorator.d.ts.map +1 -0
- package/dist/config/base.d.ts +0 -5
- package/dist/config/base.d.ts.map +1 -1
- package/dist/config/capabilities.d.ts +8 -0
- package/dist/config/capabilities.d.ts.map +1 -0
- package/dist/config/context.d.ts +1 -2
- package/dist/config/context.d.ts.map +1 -1
- package/dist/config/filters.d.ts +15 -0
- package/dist/config/filters.d.ts.map +1 -0
- package/dist/config/formatters.d.ts +15 -0
- package/dist/config/formatters.d.ts.map +1 -0
- package/dist/config/index.d.ts +9 -4
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/itemMeta.d.ts +5 -0
- package/dist/config/itemMeta.d.ts.map +1 -0
- package/dist/config/itemTypes.d.ts +4 -0
- package/dist/config/itemTypes.d.ts.map +1 -0
- package/dist/config/partialModulesConfig.d.ts +0 -1
- package/dist/config/partialModulesConfig.d.ts.map +1 -1
- package/dist/config/registry.d.ts +2 -30
- package/dist/config/registry.d.ts.map +1 -1
- package/dist/config/resolve.d.ts +0 -4
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/schemas.d.ts +37 -7
- package/dist/config/schemas.d.ts.map +1 -1
- package/dist/config/types.d.ts +8 -14
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/useFormatters.d.ts +10 -0
- package/dist/config/useFormatters.d.ts.map +1 -0
- package/dist/fixtures/generate.d.ts +1 -37
- package/dist/fixtures/generate.d.ts.map +1 -1
- package/dist/fixtures/index.d.ts +1 -1
- package/dist/fixtures/index.d.ts.map +1 -1
- package/dist/fixtures/scenarios.d.ts +4 -34
- package/dist/fixtures/scenarios.d.ts.map +1 -1
- package/dist/hooks/constants.d.ts +6 -40
- package/dist/hooks/constants.d.ts.map +1 -1
- package/dist/hooks/queryOptions.d.ts +2 -26
- package/dist/hooks/queryOptions.d.ts.map +1 -1
- package/dist/hooks/useItemsMode.d.ts +3 -84
- package/dist/hooks/useItemsMode.d.ts.map +1 -1
- package/dist/hooks/useModuleItemQueries.d.ts +1 -45
- package/dist/hooks/useModuleItemQueries.d.ts.map +1 -1
- package/dist/hooks/useModuleItems.d.ts +0 -16
- package/dist/hooks/useModuleItems.d.ts.map +1 -1
- package/dist/hooks/useModules.d.ts +3 -24
- package/dist/hooks/useModules.d.ts.map +1 -1
- package/dist/hooks/useModulesPageData.d.ts +9 -33
- package/dist/hooks/useModulesPageData.d.ts.map +1 -1
- package/dist/i18n.d.ts +8 -45
- package/dist/i18n.d.ts.map +1 -1
- package/dist/index.d.ts +5 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1874 -1344
- package/dist/types/domain.d.ts +9 -87
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/types/enums.d.ts +5 -58
- package/dist/types/enums.d.ts.map +1 -1
- package/dist/types/extensions.d.ts +0 -43
- package/dist/types/extensions.d.ts.map +1 -1
- package/dist/types/filterClause.d.ts +18 -0
- package/dist/types/filterClause.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/navigation.d.ts +0 -6
- package/dist/types/navigation.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +2 -28
- package/dist/types/schemas.d.ts.map +1 -1
- package/locales/en.json +20 -9
- package/package.json +35 -31
package/dist/config/schemas.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
1
2
|
import { z } from 'zod';
|
|
3
|
+
import { TranslateFunction } from '../i18n';
|
|
4
|
+
import { FilterClause, Module, ModuleItem } from '../types';
|
|
5
|
+
import { BoundFormatters } from './useFormatters';
|
|
2
6
|
import { ModulesConfig } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* The shape every registry entry shares, schema first so the type is inferred
|
|
5
|
-
* from one list of fields — same inversion as `types/enums.ts`.
|
|
6
|
-
*
|
|
7
|
-
* Registries are validated at runtime rather than typed with generics, because
|
|
8
|
-
* a host may fetch one. See `docs/adr/0001-customization.md`.
|
|
9
|
-
*/
|
|
10
7
|
export declare const RegistryEntrySchema: z.ZodObject<{
|
|
11
8
|
label: z.ZodString;
|
|
12
9
|
order: z.ZodNumber;
|
|
@@ -14,5 +11,38 @@ export declare const RegistryEntrySchema: z.ZodObject<{
|
|
|
14
11
|
}>;
|
|
15
12
|
export type RegistryEntry = z.infer<typeof RegistryEntrySchema>;
|
|
16
13
|
export declare function registrySchema<E extends RegistryEntry>(entrySchema: z.ZodType<E>): z.ZodRecord<z.ZodString, z.ZodType<E>>;
|
|
14
|
+
export interface ItemTypeContext {
|
|
15
|
+
item: ModuleItem;
|
|
16
|
+
}
|
|
17
|
+
export interface ItemTypeEntry extends RegistryEntry {
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
renderIcon?: (context: ItemTypeContext) => ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export declare const ItemTypeEntrySchema: z.ZodType<ItemTypeEntry>;
|
|
22
|
+
export interface MetaFieldContext {
|
|
23
|
+
item: ModuleItem;
|
|
24
|
+
t: TranslateFunction;
|
|
25
|
+
today: Date;
|
|
26
|
+
locale: string;
|
|
27
|
+
timezone?: string;
|
|
28
|
+
formatters: BoundFormatters;
|
|
29
|
+
config: ModulesConfig;
|
|
30
|
+
}
|
|
31
|
+
export interface MetaFieldEntry extends RegistryEntry {
|
|
32
|
+
render: (context: MetaFieldContext) => ReactNode;
|
|
33
|
+
}
|
|
34
|
+
export declare const MetaFieldEntrySchema: z.ZodType<MetaFieldEntry>;
|
|
35
|
+
export interface FilterContext {
|
|
36
|
+
today: Date;
|
|
37
|
+
timezone?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface FilterEntry extends RegistryEntry {
|
|
40
|
+
/** Runs over loaded pages only. */
|
|
41
|
+
predicate: (module: Module, context: FilterContext) => boolean;
|
|
42
|
+
query?: FilterClause;
|
|
43
|
+
/** Ignore any inherited `query` and serve this filter by its predicate. */
|
|
44
|
+
clientOnly?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare const FilterEntrySchema: z.ZodType<FilterEntry>;
|
|
17
47
|
export declare const ModulesConfigSchema: z.ZodType<ModulesConfig>;
|
|
18
48
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/config/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/config/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,EAAE,KAAK,YAAY,EAAsB,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAA;AAE9F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,SAAS,CAAC;IAC5C,KAAK,EAAE,CAAC,CAAC,SAAS,CAAA;IAClB,KAAK,EAAE,CAAC,CAAC,SAAS,CAAA;IAClB,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;CACpC,CAMC,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAE/D,wBAAgB,cAAc,CAAC,CAAC,SAAS,aAAa,EACpD,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GACxB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAExC;AAID,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,UAAU,CAAA;CACjB;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,IAAI,CAAC,EAAE,SAAS,CAAA;IAEhB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,SAAS,CAAA;CACrD;AAgBD,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAK9C,CAAA;AAQX,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAA;IAChB,CAAC,EAAE,iBAAiB,CAAA;IACpB,KAAK,EAAE,IAAI,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,eAAe,CAAA;IAC3B,MAAM,EAAE,aAAa,CAAA;CACtB;AAED,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD,MAAM,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,SAAS,CAAA;CACjD;AAED,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAIhD,CAAA;AAEX,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,IAAI,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,mCAAmC;IACnC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAA;IAC9D,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAM1C,CAAA;AAEX,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAgBvD,CAAA"}
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
+
import { ModulesFormatters } from './formatters';
|
|
1
2
|
import { Registry, RegistryOverride } from './registry';
|
|
2
|
-
|
|
3
|
-
export interface ModulesFormatters {
|
|
4
|
-
}
|
|
5
|
-
/** Where a click on a module or an item goes. */
|
|
3
|
+
import { FilterEntry, ItemTypeEntry, MetaFieldEntry } from './schemas';
|
|
6
4
|
export interface ModulesNavigation {
|
|
7
5
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Everything a host can customize. Not customizable means nothing to set.
|
|
10
|
-
*/
|
|
11
6
|
export interface ModulesConfig {
|
|
12
7
|
formatters: ModulesFormatters;
|
|
13
|
-
itemTypes: Registry
|
|
8
|
+
itemTypes: Registry<ItemTypeEntry>;
|
|
14
9
|
itemStatuses: Registry;
|
|
15
|
-
itemMeta: Registry
|
|
16
|
-
filters: Registry
|
|
10
|
+
itemMeta: Registry<MetaFieldEntry>;
|
|
11
|
+
filters: Registry<FilterEntry>;
|
|
17
12
|
moduleActions: Registry;
|
|
18
13
|
itemActions: Registry;
|
|
19
14
|
navigation: ModulesNavigation;
|
|
20
15
|
}
|
|
21
|
-
/** A host writes only the surfaces it wants different from the base. */
|
|
22
16
|
export interface ModulesConfigOverride {
|
|
23
17
|
formatters?: Partial<ModulesFormatters>;
|
|
24
|
-
itemTypes?: RegistryOverride
|
|
18
|
+
itemTypes?: RegistryOverride<ItemTypeEntry>;
|
|
25
19
|
itemStatuses?: RegistryOverride;
|
|
26
|
-
itemMeta?: RegistryOverride
|
|
27
|
-
filters?: RegistryOverride
|
|
20
|
+
itemMeta?: RegistryOverride<MetaFieldEntry>;
|
|
21
|
+
filters?: RegistryOverride<FilterEntry>;
|
|
28
22
|
moduleActions?: RegistryOverride;
|
|
29
23
|
itemActions?: RegistryOverride;
|
|
30
24
|
navigation?: Partial<ModulesNavigation>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE3E,MAAM,WAAW,iBAAiB;CAAG;AAErC,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAA;IAClC,YAAY,EAAE,QAAQ,CAAA;IACtB,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAA;IAClC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAA;IAC9B,aAAa,EAAE,QAAQ,CAAA;IACvB,WAAW,EAAE,QAAQ,CAAA;IACrB,UAAU,EAAE,iBAAiB,CAAA;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAA;IACvC,SAAS,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAC3C,YAAY,CAAC,EAAE,gBAAgB,CAAA;IAC/B,QAAQ,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAA;IAC3C,OAAO,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAA;IACvC,aAAa,CAAC,EAAE,gBAAgB,CAAA;IAChC,WAAW,CAAC,EAAE,gBAAgB,CAAA;IAC9B,UAAU,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAA;CACxC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Module } from '../types';
|
|
2
|
+
export interface BoundFormatters {
|
|
3
|
+
moduleLabel: (position: number, module: Module) => string | null;
|
|
4
|
+
dueByline: (iso: string, today: Date) => string;
|
|
5
|
+
unlockByline: (iso: string, today: Date) => string;
|
|
6
|
+
points: (pointsPossible: number | null | undefined) => string | null;
|
|
7
|
+
progress: (percentComplete: number, met: number, total: number) => string;
|
|
8
|
+
}
|
|
9
|
+
export declare function useFormatters(): BoundFormatters;
|
|
10
|
+
//# sourceMappingURL=useFormatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormatters.d.ts","sourceRoot":"","sources":["../../src/config/useFormatters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGtC,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IAChE,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,KAAK,MAAM,CAAA;IAC/C,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,KAAK,MAAM,CAAA;IAClD,MAAM,EAAE,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,KAAK,MAAM,GAAG,IAAI,CAAA;IACpE,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CAC1E;AAED,wBAAgB,aAAa,IAAI,eAAe,CAiB/C"}
|
|
@@ -1,47 +1,11 @@
|
|
|
1
1
|
import { InMemoryFixture } from '../adapters/inMemory';
|
|
2
2
|
import { ModuleStatus } from '../types/domain';
|
|
3
|
-
/**
|
|
4
|
-
* The full `ModuleStatus` enum, one per module, cycled.
|
|
5
|
-
*
|
|
6
|
-
* Exported because it is also the reason `SMALL_MODULE_COUNT` is what it is:
|
|
7
|
-
* a fixture shorter than this cycle cannot show every state.
|
|
8
|
-
*/
|
|
9
3
|
export declare const MODULE_STATUS_CYCLE: readonly ModuleStatus[];
|
|
10
|
-
/** The course every fixture belongs to; only used to build plausible URLs. */
|
|
11
4
|
export declare const FIXTURE_COURSE_ID = "1";
|
|
12
|
-
/**
|
|
13
|
-
* Build a fixture from a per-module item count, e.g. `[8, 250, 8]` is three
|
|
14
|
-
* modules where the middle one is far past the inline limit.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Which audience the fixture describes.
|
|
18
|
-
*
|
|
19
|
-
* Not cosmetic: the two shapes are mutually exclusive in Canvas, and a fixture
|
|
20
|
-
* that mixes them describes a page no host can ever render.
|
|
21
|
-
*
|
|
22
|
-
* - `student` — everything is published, and every module carries a `progress`
|
|
23
|
-
* with every item a `status`. A student's module list contains no unpublished
|
|
24
|
-
* content at all; that is exactly why normalization rule 2 reads a null
|
|
25
|
-
* `published` as `true` for a viewer without manage permission.
|
|
26
|
-
* - `teacher` — publish state varies, and nothing carries progress. Canvas
|
|
27
|
-
* resolves `progression` to null for a viewer with no progression record, so a
|
|
28
|
-
* teacher fixture with a `progress` would be describing a student.
|
|
29
|
-
*
|
|
30
|
-
* The bug this fixes: the generator used to emit unpublished modules *and*
|
|
31
|
-
* student progress on the same module, so `courseSmall`'s module 4 rendered as
|
|
32
|
-
* "(unpublished)" next to a progress bar — a combination that cannot occur.
|
|
33
|
-
*/
|
|
5
|
+
/** `student` publishes everything and carries progress. `teacher` does neither. */
|
|
34
6
|
export type FixtureView = 'student' | 'teacher';
|
|
35
7
|
export interface BuildFixtureOptions {
|
|
36
|
-
/** Defaults to `student`. */
|
|
37
8
|
view?: FixtureView;
|
|
38
|
-
/**
|
|
39
|
-
* Which course the fixture is for. Defaults to `FIXTURE_COURSE_ID` ('1').
|
|
40
|
-
*
|
|
41
|
-
* Override it to prove a hook actually threads `courseId` through: with every
|
|
42
|
-
* fixture on course '1', a hook that hardcoded '1' internally would be
|
|
43
|
-
* indistinguishable from one that passed the caller's value.
|
|
44
|
-
*/
|
|
45
9
|
courseId?: string;
|
|
46
10
|
}
|
|
47
11
|
export declare function buildFixture(itemCounts: readonly number[], options?: BuildFixtureOptions): InMemoryFixture;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/fixtures/generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAQV,YAAY,EACb,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/fixtures/generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAQV,YAAY,EACb,MAAM,iBAAiB,CAAA;AAcxB,eAAO,MAAM,mBAAmB,EAAE,SAAS,YAAY,EAQtD,CAAA;AAoBD,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAsOpC,mFAAmF;AACnF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,CAAA;AAE/C,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAeD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,GAAE,mBAAwB,GAChC,eAAe,CAiBjB"}
|
package/dist/fixtures/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { buildFixture, type BuildFixtureOptions, FIXTURE_COURSE_ID, type FixtureView, MODULE_STATUS_CYCLE, } from './generate';
|
|
2
|
-
export { courseEmpty, courseFatModule, courseItemLinks, courseLarge, courseSmall, FAT_MODULE_ITEM_COUNT, FAT_MODULE_SIBLING_ITEM_COUNT, LARGE_ITEMS_PER_MODULE, LARGE_MODULE_COUNT, SMALL_ITEMS_PER_MODULE, SMALL_MODULE_COUNT, } from './scenarios';
|
|
2
|
+
export { courseEmpty, courseFatModule, courseItemLinks, courseItemRowVariants, courseLarge, courseLockReasons, courseSmall, FAT_MODULE_ITEM_COUNT, FAT_MODULE_SIBLING_ITEM_COUNT, FUTURE_UNLOCK_AT, LARGE_ITEMS_PER_MODULE, LARGE_MODULE_COUNT, PAST_UNLOCK_AT, SMALL_ITEMS_PER_MODULE, SMALL_MODULE_COUNT, } from './scenarios';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixtures/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,iBAAiB,EACjB,KAAK,WAAW,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,WAAW,EACX,eAAe,EACf,eAAe,EACf,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,6BAA6B,EAC7B,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixtures/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,iBAAiB,EACjB,KAAK,WAAW,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,WAAW,EACX,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,6BAA6B,EAC7B,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,aAAa,CAAA"}
|
|
@@ -1,47 +1,17 @@
|
|
|
1
1
|
import { InMemoryFixture } from '../adapters/inMemory';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* ship silently, so they are sized against real Canvas limits rather than
|
|
5
|
-
* chosen for convenience.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* 6 modules × 8 items. Inline mode resolves; the whole course in ~2 requests.
|
|
9
|
-
*
|
|
10
|
-
* The module count is `MODULE_STATUS_CYCLE.length` rather than a round number:
|
|
11
|
-
* this is the fixture a story reaches for by default, and at five modules it
|
|
12
|
-
* would silently omit one of the six `ModuleStatus` states.
|
|
13
|
-
*/
|
|
2
|
+
export declare const FUTURE_UNLOCK_AT = "2099-08-31T06:59:00Z";
|
|
3
|
+
export declare const PAST_UNLOCK_AT = "2020-01-06T07:00:00Z";
|
|
14
4
|
export declare const SMALL_MODULE_COUNT: number;
|
|
15
5
|
export declare const SMALL_ITEMS_PER_MODULE = 8;
|
|
16
|
-
/** 120 modules × 25 items. Past the 100-per-page module limit Career truncates at. */
|
|
17
6
|
export declare const LARGE_MODULE_COUNT = 120;
|
|
18
7
|
export declare const LARGE_ITEMS_PER_MODULE = 25;
|
|
19
|
-
/** 3 modules, the middle one 250 items — 2.5× `INLINE_ITEM_LIMIT`. */
|
|
20
8
|
export declare const FAT_MODULE_ITEM_COUNT = 250;
|
|
21
9
|
export declare const FAT_MODULE_SIBLING_ITEM_COUNT = 8;
|
|
22
|
-
/**
|
|
23
|
-
* The happy path: everything fits in one page of modules with items inlined,
|
|
24
|
-
* so a correct implementation renders the course in about two requests.
|
|
25
|
-
*/
|
|
26
10
|
export declare function courseSmall(): InMemoryFixture;
|
|
27
|
-
/**
|
|
28
|
-
* Module-list pagination past 100. Canvas caps `per_page` at 100, so a client
|
|
29
|
-
* that ignores the next cursor shows 100 of 120 modules and says nothing —
|
|
30
|
-
* which is what Canvas Career does today.
|
|
31
|
-
*/
|
|
32
11
|
export declare function courseLarge(): InMemoryFixture;
|
|
33
|
-
/**
|
|
34
|
-
* Item pagination past `INLINE_ITEM_LIMIT`. Canvas omits the `items` key
|
|
35
|
-
* entirely for the fat module, so the client must fall back to a per-module
|
|
36
|
-
* fetch and then page it. The "renders exactly 100 items and stops" bug lives
|
|
37
|
-
* here and cannot recur while this fixture is in the suite.
|
|
38
|
-
*/
|
|
39
12
|
export declare function courseFatModule(): InMemoryFixture;
|
|
40
|
-
|
|
13
|
+
export declare function courseLockReasons(): InMemoryFixture;
|
|
41
14
|
export declare function courseEmpty(): InMemoryFixture;
|
|
42
|
-
|
|
43
|
-
* The item-title edge cases, hand-authored: linked, new tab, sub-header, no url,
|
|
44
|
-
* a very long title, and locked.
|
|
45
|
-
*/
|
|
15
|
+
export declare function courseItemRowVariants(): InMemoryFixture;
|
|
46
16
|
export declare function courseItemLinks(): InMemoryFixture;
|
|
47
17
|
//# sourceMappingURL=scenarios.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenarios.d.ts","sourceRoot":"","sources":["../../src/fixtures/scenarios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"scenarios.d.ts","sourceRoot":"","sources":["../../src/fixtures/scenarios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAM3D,eAAO,MAAM,gBAAgB,yBAAyB,CAAA;AACtD,eAAO,MAAM,cAAc,yBAAyB,CAAA;AAEpD,eAAO,MAAM,kBAAkB,EAAE,MAAmC,CAAA;AACpE,eAAO,MAAM,sBAAsB,IAAI,CAAA;AAEvC,eAAO,MAAM,kBAAkB,MAAM,CAAA;AACrC,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,eAAO,MAAM,qBAAqB,MAAM,CAAA;AACxC,eAAO,MAAM,6BAA6B,IAAI,CAAA;AAE9C,wBAAgB,WAAW,IAAI,eAAe,CAE7C;AAED,wBAAgB,WAAW,IAAI,eAAe,CAE7C;AAED,wBAAgB,eAAe,IAAI,eAAe,CAMjD;AAED,wBAAgB,iBAAiB,IAAI,eAAe,CAyCnD;AAED,wBAAgB,WAAW,IAAI,eAAe,CAE7C;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CAmEvD;AAED,wBAAgB,eAAe,IAAI,eAAe,CA8CjD"}
|
|
@@ -1,49 +1,15 @@
|
|
|
1
1
|
import { PageInfo } from '../types/domain';
|
|
2
|
-
/** Canvas's `Api::MAX_PER_PAGE`.
|
|
2
|
+
/** Canvas's `Api::MAX_PER_PAGE`. */
|
|
3
3
|
export declare const DEFAULT_PAGE_SIZE: number;
|
|
4
|
-
/** Items
|
|
4
|
+
/** Items page separately, against the same ceiling. */
|
|
5
5
|
export declare const DEFAULT_ITEM_PAGE_SIZE: number;
|
|
6
|
-
/**
|
|
7
|
-
* Per-module ceiling above which inlining stops being worthwhile.
|
|
8
|
-
*
|
|
9
|
-
* Matches `Api::MAX_PER_PAGE` and `INLINE_ITEM_LIMIT`. On REST that is Canvas's
|
|
10
|
-
* own rule — the `items` key is simply absent above it. On GraphQL it is this
|
|
11
|
-
* package's policy rather than a server constraint. @see INLINE_ITEM_LIMIT
|
|
12
|
-
*/
|
|
6
|
+
/** Per-module ceiling above which inlining stops paying. @see INLINE_ITEM_LIMIT */
|
|
13
7
|
export declare const DEFAULT_INLINE_THRESHOLD: number;
|
|
14
|
-
/**
|
|
15
|
-
* How many per-module item requests may be in flight at once.
|
|
16
|
-
*
|
|
17
|
-
* Expanding "all modules" on a 40-module course should not open 40 sockets;
|
|
18
|
-
* browsers queue them anyway, but the server sees the whole burst.
|
|
19
|
-
*/
|
|
8
|
+
/** Caps the burst the server sees when a user expands every module at once. */
|
|
20
9
|
export declare const DEFAULT_ITEM_CONCURRENCY: number;
|
|
21
|
-
/**
|
|
22
|
-
* Why this is not zero.
|
|
23
|
-
*
|
|
24
|
-
* With `staleTime: 0` every re-enable of a query — which is what re-expanding a
|
|
25
|
-
* module is — counts as stale and refetches. That is the behavior this package
|
|
26
|
-
* exists to remove. Five minutes is long enough that expand/collapse within a
|
|
27
|
-
* sitting is free, short enough that coming back to the tab later is honest.
|
|
28
|
-
*/
|
|
10
|
+
/** Not zero: re-expanding a module re-enables its query, and a stale query refetches. */
|
|
29
11
|
export declare const DEFAULT_STALE_TIME_MS: number;
|
|
30
|
-
/**
|
|
31
|
-
* How many *collapsed* modules keep their item query subscribed.
|
|
32
|
-
*
|
|
33
|
-
* A collapsed module's observer is retained on purpose — that is what makes
|
|
34
|
-
* re-expanding a guaranteed cache hit rather than a lucky one. But retention has
|
|
35
|
-
* to stop somewhere: "Expand all" followed by "Collapse all" on a 120-module
|
|
36
|
-
* course would otherwise leave 120 subscriptions alive for the life of the page,
|
|
37
|
-
* each pinning its own pages of items past any `gcTime`.
|
|
38
|
-
*
|
|
39
|
-
* Twenty is chosen against the interaction rather than the data: a reader moving
|
|
40
|
-
* through a course revisits the handful of modules around where they are, and
|
|
41
|
-
* twenty covers that with room to spare while keeping the retained set a fixed
|
|
42
|
-
* cost instead of one that grows with course size. Above the cap the
|
|
43
|
-
* least-recently-active collapsed module is evicted, and re-expanding it may
|
|
44
|
-
* refetch.
|
|
45
|
-
*/
|
|
12
|
+
/** A collapsed query stays subscribed and pins its cache entry. Past this the oldest is evicted. */
|
|
46
13
|
export declare const DEFAULT_RETAIN_COLLAPSED_LIMIT: number;
|
|
47
|
-
/** The pageInfo of a query that has not resolved yet. Never truncates silently. */
|
|
48
14
|
export declare const EMPTY_PAGE_INFO: PageInfo;
|
|
49
15
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/hooks/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE/C,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/hooks/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE/C,oCAAoC;AACpC,eAAO,MAAM,iBAAiB,EAAE,MAAY,CAAA;AAE5C,uDAAuD;AACvD,eAAO,MAAM,sBAAsB,EAAE,MAAY,CAAA;AAEjD,mFAAmF;AACnF,eAAO,MAAM,wBAAwB,EAAE,MAAY,CAAA;AAEnD,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,EAAE,MAAU,CAAA;AAEjD,yFAAyF;AACzF,eAAO,MAAM,qBAAqB,EAAE,MAAsB,CAAA;AAE1D,oGAAoG;AACpG,eAAO,MAAM,8BAA8B,EAAE,MAAW,CAAA;AAExD,eAAO,MAAM,eAAe,EAAE,QAAkD,CAAA"}
|
|
@@ -3,20 +3,7 @@ import { LimitFunction } from 'p-limit';
|
|
|
3
3
|
import { ModulesDataAdapter } from '../adapters/types';
|
|
4
4
|
import { ModuleItemsKey, ModulesListKey, ModulesView } from '../cache/keys';
|
|
5
5
|
import { ModuleItemsPage, ModulesPage } from '../types/domain';
|
|
6
|
-
|
|
7
|
-
* The two query definitions this package has, factored out of the hooks.
|
|
8
|
-
*
|
|
9
|
-
* They live here because the same definition is consumed two ways: through
|
|
10
|
-
* `useInfiniteQuery` (one module, one hook) and through a raw
|
|
11
|
-
* `InfiniteQueryObserver` (a dynamic set of expanded modules, which React's
|
|
12
|
-
* rules of hooks will not let you express as N `useInfiniteQuery` calls).
|
|
13
|
-
* Sharing the factory is what guarantees both paths land on the *same* cache
|
|
14
|
-
* entry, so a module fetched by one is a cache hit for the other.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* The page cursor. `null` is the first page — the adapter contract forbids
|
|
18
|
-
* synthesizing cursors, so this is only ever `null` or something a server said.
|
|
19
|
-
*/
|
|
6
|
+
import { FilterClause } from '../types/filterClause';
|
|
20
7
|
export type ModulesCursor = string | null;
|
|
21
8
|
export type ModulesQueryOptions = InfiniteQueryObserverOptions<ModulesPage, Error, InfiniteData<ModulesPage, ModulesCursor>, ModulesListKey, ModulesCursor>;
|
|
22
9
|
export type ModuleItemsQueryOptions = InfiniteQueryObserverOptions<ModuleItemsPage, Error, InfiniteData<ModuleItemsPage, ModulesCursor>, ModuleItemsKey, ModulesCursor>;
|
|
@@ -25,9 +12,8 @@ export interface ModulesQueryArgs {
|
|
|
25
12
|
adapter: ModulesDataAdapter;
|
|
26
13
|
pageSize: number;
|
|
27
14
|
includeItems: boolean;
|
|
28
|
-
|
|
15
|
+
filter?: FilterClause;
|
|
29
16
|
inlineItemsFirst?: number;
|
|
30
|
-
/** Modules to request when inlining. @see ListModulesArgs.inlineFirst */
|
|
31
17
|
inlineFirst?: number;
|
|
32
18
|
view?: ModulesView;
|
|
33
19
|
staleTime: number;
|
|
@@ -38,19 +24,9 @@ export interface ModuleItemsQueryArgs {
|
|
|
38
24
|
moduleId: string;
|
|
39
25
|
adapter: ModulesDataAdapter;
|
|
40
26
|
pageSize: number;
|
|
41
|
-
/**
|
|
42
|
-
* The audience this page is rendered for. Not sent to the adapter — a host
|
|
43
|
-
* configures its adapter for the current user — but it partitions the key,
|
|
44
|
-
* because `published` is a per-item field. See `ModuleItemsKeyOptions`.
|
|
45
|
-
*/
|
|
46
27
|
view?: ModulesView;
|
|
47
28
|
staleTime: number;
|
|
48
29
|
enabled: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Shared concurrency gate. Every expanded module's item fetch goes through
|
|
51
|
-
* the same limiter instance, so "expand all" is a trickle rather than a
|
|
52
|
-
* thundering herd.
|
|
53
|
-
*/
|
|
54
30
|
limit?: LimitFunction;
|
|
55
31
|
}
|
|
56
32
|
export declare function modulesQueryOptions(args: ModulesQueryArgs): ModulesQueryOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryOptions.d.ts","sourceRoot":"","sources":["../../src/hooks/queryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAA;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"queryOptions.d.ts","sourceRoot":"","sources":["../../src/hooks/queryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAA;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEzD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,CAAA;AAEzC,MAAM,MAAM,mBAAmB,GAAG,4BAA4B,CAC5D,WAAW,EACX,KAAK,EACL,YAAY,CAAC,WAAW,EAAE,aAAa,CAAC,EACxC,cAAc,EACd,aAAa,CACd,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,CAChE,eAAe,EACf,KAAK,EACL,YAAY,CAAC,eAAe,EAAE,aAAa,CAAC,EAC5C,cAAc,EACd,aAAa,CACd,CAAA;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAMD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,mBAAmB,CAiC/E;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,oBAAoB,GAAG,uBAAuB,CAsB3F"}
|
|
@@ -1,114 +1,33 @@
|
|
|
1
1
|
import { ModulesDataAdapter } from '../adapters/types';
|
|
2
2
|
import { ModulesView } from '../cache/keys';
|
|
3
3
|
import { ModulesPage } from '../types/domain';
|
|
4
|
-
|
|
5
|
-
* How a course's module items get fetched.
|
|
6
|
-
*
|
|
7
|
-
* - `inline` — ask for items alongside the module list. One round trip for the
|
|
8
|
-
* whole page. Great for a small course, ruinous for a big one: the response
|
|
9
|
-
* grows with the number of items, and no module over `inlineThreshold` is
|
|
10
|
-
* inlined on either transport anyway (@see INLINE_ITEM_LIMIT).
|
|
11
|
-
* - `onDemand` — fetch a module's items when it is expanded. Constant-cost
|
|
12
|
-
* first paint, one extra request per module the user actually opens.
|
|
13
|
-
* - `auto` — probe, then pick. The default.
|
|
14
|
-
*/
|
|
4
|
+
import { FilterClause } from '../types/filterClause';
|
|
15
5
|
export type ItemsMode = 'auto' | 'inline' | 'onDemand';
|
|
16
|
-
/** What `auto` collapses to. */
|
|
17
6
|
export type ResolvedItemsMode = 'inline' | 'onDemand';
|
|
18
7
|
export interface UseItemsModeOptions {
|
|
19
8
|
courseId: string;
|
|
20
9
|
adapter: ModulesDataAdapter;
|
|
21
10
|
mode?: ItemsMode;
|
|
22
|
-
/** Per-module ceiling for inlining. Defaults to 100. @see INLINE_ITEM_LIMIT */
|
|
23
11
|
inlineThreshold?: number;
|
|
24
|
-
/**
|
|
25
|
-
* Ceiling on the implied request's node product.
|
|
26
|
-
*
|
|
27
|
-
* Defaults to what the adapter declares (`inlineNodeBudget`), then to
|
|
28
|
-
* `INLINE_QUERY_NODE_BUDGET`. Pass it only to override both.
|
|
29
|
-
*/
|
|
30
12
|
nodeBudget?: number;
|
|
31
13
|
pageSize?: number;
|
|
14
|
+
/** Must match what the list query gets. The probe shares its key. */
|
|
15
|
+
filter?: FilterClause;
|
|
32
16
|
view?: ModulesView;
|
|
33
17
|
staleTime?: number;
|
|
34
18
|
}
|
|
35
19
|
export interface UseItemsModeResult {
|
|
36
|
-
/** `null` while the `auto` probe is still in flight. */
|
|
37
20
|
resolvedMode: ResolvedItemsMode | null;
|
|
38
21
|
isResolving: boolean;
|
|
39
|
-
/** True when a probe request was actually needed — i.e. `mode` was `auto`. */
|
|
40
22
|
probed: boolean;
|
|
41
23
|
error: Error | null;
|
|
42
|
-
/**
|
|
43
|
-
* How many items to actually ask for per module when inlining, and how many
|
|
44
|
-
* modules to ask for — both measured from the probe rather than assumed.
|
|
45
|
-
*
|
|
46
|
-
* `null` when unknown (probe unresolved, or an explicit mode skipped it), in
|
|
47
|
-
* which case the adapter falls back to its own defaults.
|
|
48
|
-
*
|
|
49
|
-
* It exists because a transport can charge for the shape of the request rather
|
|
50
|
-
* than the size of the result, so asking for what the probe actually saw is
|
|
51
|
-
* what keeps an inline page deliverable. @see INLINE_QUERY_NODE_BUDGET
|
|
52
|
-
*/
|
|
53
24
|
inlineShape: InlineQueryShape | null;
|
|
54
25
|
}
|
|
55
|
-
/** What an inline `listModules` should request, measured from the probe. */
|
|
56
26
|
export interface InlineQueryShape {
|
|
57
|
-
/** Modules on page 1. */
|
|
58
27
|
moduleCount: number;
|
|
59
|
-
/** The largest `itemCount` among them. */
|
|
60
28
|
maxItemCount: number;
|
|
61
29
|
}
|
|
62
|
-
/**
|
|
63
|
-
* The policy itself, as a pure function over the probe's first page.
|
|
64
|
-
*
|
|
65
|
-
* Inline is chosen only when all three hold:
|
|
66
|
-
*
|
|
67
|
-
* 1. The first page is the whole list. If there is a second page of modules,
|
|
68
|
-
* the course total is unknown, and guessing from a partial view is how you
|
|
69
|
-
* end up inlining a 3000-item course. Conservative on purpose.
|
|
70
|
-
* 2. No single module exceeds `inlineThreshold`. Above it no adapter inlines
|
|
71
|
-
* the module — REST because Canvas drops the `items` key, GraphQL because
|
|
72
|
-
* this package declines to — so inlining buys nothing there and it would
|
|
73
|
-
* need an on-demand fetch regardless.
|
|
74
|
-
* 3. The course total is within `inlineThreshold * 2`. One module at the
|
|
75
|
-
* ceiling is fine; forty of them is a payload nobody asked for.
|
|
76
|
-
* 4. The implied request fits Canvas's complexity budget. Rules 1-3 bound the
|
|
77
|
-
* *data*; this one bounds the *query*, and they are not the same thing.
|
|
78
|
-
* @see INLINE_QUERY_NODE_BUDGET
|
|
79
|
-
*
|
|
80
|
-
* Exported so the policy can be unit-tested without React.
|
|
81
|
-
*/
|
|
82
30
|
export declare function resolveItemsMode(firstPage: ModulesPage, inlineThreshold: number, nodeBudget?: number): ResolvedItemsMode;
|
|
83
|
-
/**
|
|
84
|
-
* Resolves the items mode for a course.
|
|
85
|
-
*
|
|
86
|
-
* An explicit `mode` skips the probe entirely — the probe query is disabled, so
|
|
87
|
-
* it costs zero requests.
|
|
88
|
-
*
|
|
89
|
-
* For `auto`, the probe *is* the module list query with `includeItems: false`.
|
|
90
|
-
* That matters: if the probe resolves to `onDemand`, the page's own list query
|
|
91
|
-
* has the identical cache key and the probe becomes the first page for free. A
|
|
92
|
-
* second request happens only when the answer is `inline`, because inlined
|
|
93
|
-
* modules are a genuinely different payload and get their own key.
|
|
94
|
-
*
|
|
95
|
-
* Known cost of that shape, in the `auto -> inline` case only: the probe query
|
|
96
|
-
* stays mounted and enabled on its own key alongside the list query's, since
|
|
97
|
-
* `cache/keys.ts` partitions on `includeItems`. So `invalidateModuleList` refetches
|
|
98
|
-
* both where one would do, and a course that changes shape between refetches can
|
|
99
|
-
* flip the resolved mode mid-session. Neither is wrong, but neither is free —
|
|
100
|
-
* disabling the probe once it has answered would fix the first and make the second
|
|
101
|
-
* explicit.
|
|
102
|
-
*
|
|
103
|
-
* The decision is read from page 1 only, so paging further into the list can
|
|
104
|
-
* never flip the mode out from under a rendered page.
|
|
105
|
-
*/
|
|
106
31
|
export declare function useItemsMode(options: UseItemsModeOptions): UseItemsModeResult;
|
|
107
|
-
/**
|
|
108
|
-
* The smallest request that still returns the whole page inline.
|
|
109
|
-
*
|
|
110
|
-
* `maxItemCount` is at least 1 because `first: 0` is not a meaningful request,
|
|
111
|
-
* and a course of entirely empty modules should still round-trip.
|
|
112
|
-
*/
|
|
113
32
|
export declare function inlineShapeOf(firstPage: ModulesPage): InlineQueryShape;
|
|
114
33
|
//# sourceMappingURL=useItemsMode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useItemsMode.d.ts","sourceRoot":"","sources":["../../src/hooks/useItemsMode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"useItemsMode.d.ts","sourceRoot":"","sources":["../../src/hooks/useItemsMode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAIzD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAA;AAEtD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,UAAU,CAAA;AAErD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qEAAqE;IACrE,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,iBAAiB,GAAG,IAAI,CAAA;IACtC,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,WAAW,EAAE,gBAAgB,GAAG,IAAI,CAAA;CACrC;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,WAAW,EACtB,eAAe,EAAE,MAAM,EACvB,UAAU,GAAE,MAAiC,GAC5C,iBAAiB,CAgBnB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CA4D7E;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,GAAG,gBAAgB,CAMtE"}
|
|
@@ -1,56 +1,12 @@
|
|
|
1
1
|
import { InfiniteData, InfiniteQueryObserverResult } from '@tanstack/react-query';
|
|
2
2
|
import { ModuleItemsPage } from '../types/domain';
|
|
3
3
|
import { ModuleItemsQueryOptions, ModulesCursor } from './queryOptions';
|
|
4
|
-
/**
|
|
5
|
-
* A dynamic set of module-item infinite queries.
|
|
6
|
-
*
|
|
7
|
-
* ## Why this is not N `useModuleItems` calls
|
|
8
|
-
*
|
|
9
|
-
* The number of expanded modules changes at runtime, and React's rules of hooks
|
|
10
|
-
* forbid a variable number of hook calls. `useQueries` would solve it for plain
|
|
11
|
-
* queries, but it builds `QueryObserver`s, not `InfiniteQueryObserver`s — there
|
|
12
|
-
* is no `useInfiniteQueries`. So this hook does what `useQueries` does
|
|
13
|
-
* internally: it owns a map of observers keyed by module id, subscribes to each,
|
|
14
|
-
* and republishes their results into React state.
|
|
15
|
-
*
|
|
16
|
-
* The observers are built from the same `moduleItemsQueryOptions` factory
|
|
17
|
-
* `useModuleItems` uses, so both paths hit the same cache entry.
|
|
18
|
-
*
|
|
19
|
-
* ## Why a collapsed module keeps its observer
|
|
20
|
-
*
|
|
21
|
-
* Collapsing flips a module's options to `enabled: false` and leaves the
|
|
22
|
-
* subscription in place, which pins the cache entry no matter how aggressive the
|
|
23
|
-
* host's `gcTime` is. Re-expanding is then a cache hit by construction rather
|
|
24
|
-
* than by luck.
|
|
25
|
-
*
|
|
26
|
-
* ## Why the retained set is nevertheless bounded
|
|
27
|
-
*
|
|
28
|
-
* "Bounded by the modules a user actually opened" is only reassuring while
|
|
29
|
-
* opening a module is a click. `ModulesList` has an "Expand all", which on the
|
|
30
|
-
* 120-module fixture would leave 120 subscribed `InfiniteQueryObserver`s alive
|
|
31
|
-
* for the life of the page — each pinning its own pages of items — even after
|
|
32
|
-
* the user collapsed the lot.
|
|
33
|
-
*
|
|
34
|
-
* So retention is capped at `retainCollapsedLimit` *collapsed* observers, evicted
|
|
35
|
-
* least-recently-active first. Active observers are never evicted, whatever the
|
|
36
|
-
* limit: they are the ones with something on screen. Eviction destroys the
|
|
37
|
-
* observer, which unpins its cache entry and lets the host's `gcTime` apply —
|
|
38
|
-
* meaning re-expanding an evicted module may refetch. That is the trade, and it
|
|
39
|
-
* is the right way round: a guaranteed cache hit on the last N modules touched
|
|
40
|
-
* beats an unbounded set of subscriptions.
|
|
41
|
-
*/
|
|
42
4
|
type ItemsData = InfiniteData<ModuleItemsPage, ModulesCursor>;
|
|
43
5
|
export type ModuleItemsObserverResult = InfiniteQueryObserverResult<ItemsData, Error>;
|
|
44
6
|
export interface ModuleItemQueries {
|
|
45
7
|
results: ReadonlyMap<string, ModuleItemsObserverResult>;
|
|
46
8
|
fetchNextPage: (moduleId: string) => void;
|
|
47
9
|
}
|
|
48
|
-
export declare function useModuleItemQueries(
|
|
49
|
-
/** Modules whose items should be fetching right now. */
|
|
50
|
-
activeModuleIds: readonly string[],
|
|
51
|
-
/** Must be referentially stable — memoize it in the caller. */
|
|
52
|
-
buildOptions: (moduleId: string, enabled: boolean) => ModuleItemsQueryOptions,
|
|
53
|
-
/** @see DEFAULT_RETAIN_COLLAPSED_LIMIT */
|
|
54
|
-
retainCollapsedLimit?: number): ModuleItemQueries;
|
|
10
|
+
export declare function useModuleItemQueries(activeModuleIds: readonly string[], buildOptions: (moduleId: string, enabled: boolean) => ModuleItemsQueryOptions, retainCollapsedLimit?: number): ModuleItemQueries;
|
|
55
11
|
export {};
|
|
56
12
|
//# sourceMappingURL=useModuleItemQueries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModuleItemQueries.d.ts","sourceRoot":"","sources":["../../src/hooks/useModuleItemQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,2BAA2B,EACjC,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE5E
|
|
1
|
+
{"version":3,"file":"useModuleItemQueries.d.ts","sourceRoot":"","sources":["../../src/hooks/useModuleItemQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,2BAA2B,EACjC,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE5E,KAAK,SAAS,GAAG,YAAY,CAAC,eAAe,EAAE,aAAa,CAAC,CAAA;AAE7D,MAAM,MAAM,yBAAyB,GAAG,2BAA2B,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;AAUrF,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAA;IACvD,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAC1C;AAMD,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,SAAS,MAAM,EAAE,EAClC,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,uBAAuB,EAC7E,oBAAoB,GAAE,MAAuC,GAC5D,iBAAiB,CA4EnB"}
|
|
@@ -7,13 +7,7 @@ export interface UseModuleItemsOptions {
|
|
|
7
7
|
moduleId: string;
|
|
8
8
|
adapter: ModulesDataAdapter;
|
|
9
9
|
pageSize?: number;
|
|
10
|
-
/** The audience being rendered. Partitions the cache; see `ModuleItemsKeyOptions`. */
|
|
11
10
|
view?: ModulesView;
|
|
12
|
-
/**
|
|
13
|
-
* Set to the module's expanded state. A collapsed module fetches nothing, and
|
|
14
|
-
* — because the query stays mounted while disabled — re-expanding it is a
|
|
15
|
-
* cache hit rather than a refetch.
|
|
16
|
-
*/
|
|
17
11
|
enabled?: boolean;
|
|
18
12
|
staleTime?: number;
|
|
19
13
|
limit?: LimitFunction;
|
|
@@ -27,15 +21,5 @@ export interface UseModuleItemsResult {
|
|
|
27
21
|
isFetchingNextPage: boolean;
|
|
28
22
|
error: Error | null;
|
|
29
23
|
}
|
|
30
|
-
/**
|
|
31
|
-
* One module's items, paged explicitly, keyed per module.
|
|
32
|
-
*
|
|
33
|
-
* The query's `AbortSignal` is handed to the adapter (in `queryOptions.ts`), so
|
|
34
|
-
* canceling the query — which is what collapsing a module does — aborts the
|
|
35
|
-
* request rather than letting a response nobody wants land in the cache.
|
|
36
|
-
*
|
|
37
|
-
* `useModulesPageData` is the hook a page should use; this one is for a caller
|
|
38
|
-
* that already knows it wants exactly one module.
|
|
39
|
-
*/
|
|
40
24
|
export declare function useModuleItems(options: UseModuleItemsOptions): UseModuleItemsResult;
|
|
41
25
|
//# sourceMappingURL=useModuleItems.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModuleItems.d.ts","sourceRoot":"","sources":["../../src/hooks/useModuleItems.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAI3D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,
|
|
1
|
+
{"version":3,"file":"useModuleItems.d.ts","sourceRoot":"","sources":["../../src/hooks/useModuleItems.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAI3D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,QAAQ,EAAE,QAAQ,CAAA;IAClB,WAAW,EAAE,OAAO,CAAA;IACpB,aAAa,EAAE,MAAM,IAAI,CAAA;IACzB,SAAS,EAAE,OAAO,CAAA;IAClB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CA2CnF"}
|