astro-tractstack 2.0.0-rc.20 → 2.0.0-rc.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-tractstack",
3
- "version": "2.0.0-rc.20",
3
+ "version": "2.0.0-rc.21",
4
4
  "description": "Astro integration for TractStack - redeeming the web from boring experiences",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,40 +1,40 @@
1
1
  ---
2
+ //import Collections from './pages/Collections.astro';
3
+ import type { ResourceNode } from '@/types/compositorTypes';
4
+
2
5
  export interface Props {
3
6
  route: string;
4
7
  slug: string;
5
- resources: any[];
8
+ resources: ResourceNode[];
6
9
  variation?: string;
7
10
  }
8
11
 
9
- const { route, slug, resources } = Astro.props;
12
+ const { route, slug /*, resources */ } = Astro.props;
10
13
 
11
- // Define available routes here
12
- export const routes = {
13
- // collections: true, // Uncomment to enable collections route
14
- };
14
+ // list all here !
15
+ export const routes = {};
15
16
  ---
16
17
 
17
18
  {
18
- (
19
- /*
20
- Uncomment and customize routes as needed:
21
-
22
- route === "collections" ? (
19
+ /*
20
+ route === 'collections' ? (
23
21
  <Collections route={route} slug={slug} resources={payload} />
24
- ) :
22
+ ) : (
25
23
  */
26
- <div class="rounded-lg bg-gray-50 p-8 text-center">
27
- <p class="text-gray-600">Custom route "{route}" not implemented</p>
28
- <p class="mt-2 text-sm text-gray-500">
29
- Edit <code>src/custom/CustomRoutes.astro</code> to add your custom
30
- routes
31
- </p>
32
- <div class="mt-4 rounded border bg-white p-4 text-left text-xs">
33
- <p class="mb-2 font-bold">Route Data:</p>
34
- <p>Route: {route}</p>
35
- <p>Slug: {slug}</p>
36
- <p>Resources: {resources.length} items</p>
37
- </div>
38
- </div>
39
- )
24
+ }
25
+
26
+ <div class="rounded-lg bg-gray-50 p-8 text-center">
27
+ <p class="text-gray-600">Custom route "{route}" not found</p>
28
+ <p class="mt-2 text-sm text-gray-500">Available routes: collections</p>
29
+ <div class="mt-4 rounded border bg-white p-4 text-left text-xs">
30
+ <p class="mb-2 font-bold">Route Data:</p>
31
+ <p>Route: {route}</p>
32
+ <p>Slug: {slug}</p>
33
+ </div>
34
+ </div>
35
+
36
+ {
37
+ /*
38
+ ) }
39
+ */
40
40
  }
@@ -1,25 +1,25 @@
1
1
  ---
2
2
  import Collections from './pages/Collections.astro';
3
+ import type { ResourceNode } from '@/types/compositorTypes';
3
4
 
4
5
  export interface Props {
5
6
  route: string;
6
7
  slug: string;
7
- resources: any[];
8
+ resources: ResourceNode[];
8
9
  variation?: string;
9
10
  }
10
11
 
11
12
  const { route, slug, resources } = Astro.props;
12
13
 
14
+ // list all here !
13
15
  export const routes = {
14
16
  collections: true,
15
17
  };
16
-
17
- const payload = resources;
18
18
  ---
19
19
 
20
20
  {
21
21
  route === 'collections' ? (
22
- <Collections route={route} slug={slug} resources={payload} />
22
+ <Collections route={route} slug={slug} resources={resources} />
23
23
  ) : (
24
24
  <div class="rounded-lg bg-gray-50 p-8 text-center">
25
25
  <p class="text-gray-600">Custom route "{route}" not found</p>
@@ -1,110 +1,70 @@
1
1
  ---
2
- import Layout from '@/layouts/Layout.astro';
3
- //import type { MenuNode } from '@/types/tractstack';
2
+ import CustomRoutes, { routes } from '@/custom/CustomRoutes.astro';
3
+ import { preHealthCheck } from '@/utils/backend';
4
+ //import type { ResourceNode } from '@/types/compositorTypes';
4
5
 
5
- export interface Props {
6
- route: string;
7
- slug: string;
8
- variation?: string;
9
- resources: any[];
6
+ const tenantId =
7
+ Astro.locals.tenant?.id || import.meta.env.PUBLIC_TENANTID || 'default';
8
+
9
+ const healthCheckRedirect = await preHealthCheck(tenantId);
10
+ if (healthCheckRedirect !== undefined) {
11
+ return healthCheckRedirect;
10
12
  }
11
13
 
12
- const { route, slug, resources } = Astro.props;
14
+ const { param1 } = Astro.params;
15
+ // this needs to match the url path
16
+ const route = `collections`;
13
17
 
14
- // uncomment if you add a menu id
15
- //
16
- //let menuPayload: MenuNode | null = null;
17
- //const hardcodedMenuId = '';
18
- //const goBackend = import.meta.env.PUBLIC_GO_BACKEND || 'http://localhost:8080';
19
- //try {
20
- // const menuResponse = await fetch(`${goBackend}/api/v1/nodes/menus/${hardcodedMenuId}`);
21
- // if (menuResponse.ok) {
22
- // menuPayload = await menuResponse.json();
23
- // }
24
- //} catch (error) {
25
- // console.error('Error fetching menu:', error);
26
- //}
18
+ // Check if route is enabled
19
+ if (!param1 || !routes[route]) {
20
+ return new Response(null, {
21
+ status: 404,
22
+ statusText: 'Not Found',
23
+ });
24
+ }
27
25
 
28
- const targetSlug = `${route}-${slug}`;
29
- const categoryResources = resources || [];
30
- const activeResource = categoryResources.find(
31
- (resource: any) => resource.slug === targetSlug
32
- );
26
+ // include all resource categories here
27
+ const CATEGORIES = [`collections`];
33
28
 
34
- const pageTitle = `${route}=${slug}`;
35
- ---
29
+ let resources = [];
30
+ const goBackend = import.meta.env.PUBLIC_GO_BACKEND || 'http://localhost:8080';
36
31
 
37
- <Layout title={pageTitle}>
38
- <div class="border-b bg-gray-100 p-4">
39
- <h1 class="text-2xl font-bold">{pageTitle}</h1>
40
- <p class="text-sm text-gray-600">
41
- Collections page - slug: {slug}
42
- </p>
43
- </div>
32
+ try {
33
+ const resourcesResponse = await fetch(`${goBackend}/api/v1/nodes/resources`, {
34
+ method: 'POST',
35
+ headers: { 'Content-Type': 'application/json', 'X-Tenant-ID': tenantId },
36
+ body: JSON.stringify({ categories: CATEGORIES }),
37
+ });
44
38
 
45
- <main id="main-content" class="min-h-screen w-full">
46
- <div class="bg-white p-8">
47
- {
48
- slug ? (
49
- <div class="mx-auto max-w-4xl">
50
- <h2 class="mb-4 text-xl font-bold">
51
- Collection: {route}={slug}
52
- </h2>
39
+ if (resourcesResponse.ok) {
40
+ const responseData = await resourcesResponse.json();
41
+ if (responseData.resources) {
42
+ resources = responseData.resources;
43
+ }
44
+ }
45
+ } catch (error) {
46
+ console.error('Error fetching resources:', error);
47
+ return new Response(null, {
48
+ status: 500,
49
+ statusText: 'Internal Server Error',
50
+ });
51
+ }
53
52
 
54
- {activeResource ? (
55
- <div class="mb-6 rounded-lg bg-blue-50 p-6">
56
- <h3 class="mb-2 text-lg font-bold text-blue-900">
57
- {activeResource.title}
58
- </h3>
59
- <p class="mb-2 text-blue-800">{activeResource.oneliner}</p>
60
- <div class="text-sm text-blue-600">
61
- <p>ID: {activeResource.id}</p>
62
- <p>Slug: {activeResource.slug}</p>
63
- <p>Category: {activeResource.categorySlug || 'none'}</p>
64
- </div>
65
- </div>
66
- ) : (
67
- <div class="mb-6 rounded-lg bg-yellow-50 p-6">
68
- <p class="text-yellow-800">
69
- No active resource found for slug: {targetSlug}
70
- </p>
71
- </div>
72
- )}
53
+ /*
54
+ if (!resources.length) {
55
+ return new Response(null, {
56
+ status: 404,
57
+ statusText: 'Not Found',
58
+ });
59
+ }
60
+ */
73
61
 
74
- <div class="rounded-lg bg-gray-50 p-6">
75
- <h3 class="mb-4 text-lg font-bold">
76
- All Resources in Category ({categoryResources.length})
77
- </h3>
78
- {categoryResources.length > 0 ? (
79
- <div class="grid gap-4 md:grid-cols-2">
80
- {categoryResources.map((resource: any) => (
81
- <div class="rounded border bg-white p-4">
82
- <h4 class="font-bold text-gray-900">{resource.title}</h4>
83
- <p class="mt-1 text-sm text-gray-600">
84
- {resource.oneliner}
85
- </p>
86
- <div class="mt-2 text-xs text-gray-500">
87
- <p>Slug: {resource.slug}</p>
88
- {resource.categorySlug && (
89
- <p>Category: {resource.categorySlug}</p>
90
- )}
91
- </div>
92
- </div>
93
- ))}
94
- </div>
95
- ) : (
96
- <p class="text-gray-500">
97
- No resources found in this category.
98
- </p>
99
- )}
100
- </div>
101
- </div>
102
- ) : null
103
- }
104
- </div>
105
- </main>
62
+ const pageTitle = `${route} collection`;
63
+ ---
106
64
 
107
- <div class="border-t bg-gray-100 p-4">
108
- <p class="text-sm text-gray-600">Collections footer</p>
109
- </div>
110
- </Layout>
65
+ <div class="border-b bg-gray-100 p-4">
66
+ <h1 class="text-2xl font-bold">{pageTitle}</h1>
67
+ <p class="text-sm text-gray-600">
68
+ Collections page - slug: {param1}
69
+ </p>
70
+ </div>
@@ -27,12 +27,19 @@ const CodeHookContainer = ({
27
27
  {Object.entries(payload.params).map(
28
28
  ([key, value]) =>
29
29
  value && (
30
- <div key={key} className="flex items-start">
30
+ <>
31
31
  <span className="min-w-24 font-bold text-gray-600">{key}:</span>
32
- <span className="ml-2 truncate text-gray-800">
33
- {JSON.stringify(value)}
34
- </span>
35
- </div>
32
+ <div className="ml-2 flex flex-wrap gap-1">
33
+ {value.split('|').map((item, index) => (
34
+ <span
35
+ key={index}
36
+ className="inline-block rounded bg-gray-200 px-2 py-0.5 text-xs text-gray-800"
37
+ >
38
+ {item}
39
+ </span>
40
+ ))}
41
+ </div>
42
+ </>
36
43
  )
37
44
  )}
38
45
  </div>