@arcforgelabs/flow 2026.10.33 → 2026.10.34
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 +6 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api/custom-fields.js +114 -0
- package/server/api/invoicing.js +2 -1
- package/server/api/work-moves.js +80 -0
- package/server/app.js +12 -0
- package/server/core/custom-fields.js +300 -0
- package/server/core/job-board.js +2 -0
- package/server/core/tracing.js +64 -0
- package/server/db/migrations/0018_custom_fields.sql +78 -0
- package/server/db/migrations/meta/0018_snapshot.json +4289 -0
- package/server/db/migrations/meta/_journal.json +7 -0
- package/server/db/schema.js +59 -0
- package/server/index.js +6 -1
- package/server/integrations/port.js +7 -1
- package/server/integrations/seazona/index.js +47 -1
- package/server/integrations/seazona/migrations/0007_stage_moves.sql +18 -0
- package/server/integrations/seazona/migrations/meta/0007_snapshot.json +1519 -0
- package/server/integrations/seazona/migrations/meta/_journal.json +7 -0
- package/server/integrations/seazona/schema.js +26 -0
- package/server/integrations/seazona/settings.js +14 -0
- package/server/integrations/seazona/stage-moves.js +135 -0
- package/server/integrations/seazona/tables.js +2 -0
- package/server/integrations/sentry/index.js +61 -10
- package/server/ui/app-page.js +1 -1
- package/server/ui/app.js +40 -2
- package/server/ui/custom-fields.js +190 -0
- package/server/ui/flow.css +48 -9
- package/server/ui/invoicing.js +83 -5
- package/server/ui/jobs.js +3 -1
- package/server/ui/monitoring.js +44 -2
- package/server/ui/routes.js +1 -1
|
@@ -292,3 +292,29 @@ export const seazonaSweepFindings = pgTable('seazona_sweep_findings', {
|
|
|
292
292
|
primaryKey({ columns: [t.resource, t.recordKey, t.kind] }),
|
|
293
293
|
index('seazona_sweep_findings_found').on(t.lastFoundAt),
|
|
294
294
|
]);
|
|
295
|
+
|
|
296
|
+
// A person's stage move on the Jobs board that Seazona must make, because
|
|
297
|
+
// Seazona's API cannot change an order's status (docs/SEAZONA.md, "Stage
|
|
298
|
+
// moves"). One row per order: the latest move. `state` is waiting until the
|
|
299
|
+
// sync reads the new status (done), a day passes (expired), or the person
|
|
300
|
+
// takes it back (cancelled). Statuses only; never patient data.
|
|
301
|
+
export const seazonaStageMoves = pgTable('seazona_stage_moves', {
|
|
302
|
+
orderId: text('order_id').primaryKey(),
|
|
303
|
+
fromStatus: text('from_status'),
|
|
304
|
+
toStatus: text('to_status').notNull(),
|
|
305
|
+
requestedBy: text('requested_by'),
|
|
306
|
+
requestedAt: at('requested_at').notNull(),
|
|
307
|
+
expiresAt: at('expires_at').notNull(),
|
|
308
|
+
state: text('state').notNull().default('waiting'),
|
|
309
|
+
settledAt: at('settled_at'),
|
|
310
|
+
}, (t) => [
|
|
311
|
+
index('seazona_stage_moves_state').on(t.state, t.expiresAt),
|
|
312
|
+
]);
|
|
313
|
+
|
|
314
|
+
// Each person's own Seazona choices. `ask_before_stage_moves`: show the
|
|
315
|
+
// "Move in Seazona" dialog before a stage move on the Jobs board.
|
|
316
|
+
export const seazonaPersonSettings = pgTable('seazona_person_settings', {
|
|
317
|
+
personId: text('person_id').primaryKey(),
|
|
318
|
+
askBeforeStageMoves: boolean('ask_before_stage_moves').notNull().default(true),
|
|
319
|
+
updatedAt: at('updated_at').notNull(),
|
|
320
|
+
});
|
|
@@ -55,6 +55,16 @@ export function normaliseBaseUrl(value) {
|
|
|
55
55
|
return `${url.origin}${path}/v1`;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function orderUrlTemplate(value) {
|
|
59
|
+
const raw = text(value);
|
|
60
|
+
if (!raw.includes('{ref}')) return null;
|
|
61
|
+
try {
|
|
62
|
+
return new URL(raw.replaceAll('{ref}', 'x')).protocol === 'https:' ? raw : null;
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
// Returns the resolved settings, or throws SeazonaSettingsError. `mode` is
|
|
59
69
|
// null when SEAZONA_MODE is unset: the adapter is then not configured.
|
|
60
70
|
export function resolveSeazonaSettings(env = process.env) {
|
|
@@ -161,6 +171,10 @@ export function resolveSeazonaSettings(env = process.env) {
|
|
|
161
171
|
rate,
|
|
162
172
|
// The scheduler starts only in live mode (issue #10).
|
|
163
173
|
scheduled: mode === 'live',
|
|
174
|
+
// The address of one order in Seazona's own screens, with {ref} for the
|
|
175
|
+
// order number, for "Open in Seazona" on a stage move. Optional; one
|
|
176
|
+
// without {ref} is ignored.
|
|
177
|
+
orderUrlTemplate: orderUrlTemplate(env.SEAZONA_ORDER_URL),
|
|
164
178
|
};
|
|
165
179
|
|
|
166
180
|
if (mode === 'live' || mode === 'sandbox') {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { and, eq, gte, inArray, lt, sql } from 'drizzle-orm';
|
|
2
|
+
import { FlowError } from '../../core/errors.js';
|
|
3
|
+
import { orderStatusLabel } from './map.js';
|
|
4
|
+
import { seazonaOrders, seazonaPersonSettings, seazonaStageMoves } from './schema.js';
|
|
5
|
+
|
|
6
|
+
// Stage moves on the Jobs board (docs/SEAZONA.md, "Stage moves"). Seazona's
|
|
7
|
+
// API cannot change an order's status, so Flow never tries: a move becomes a
|
|
8
|
+
// hand-off. Flow records the move, the person makes it in Seazona, and the
|
|
9
|
+
// next sync that reads the new status settles it. Until then the card shows
|
|
10
|
+
// "Waiting for Seazona" in the new lane. After a day with no change the move
|
|
11
|
+
// expires, the card goes back to Seazona's stage, and a quiet alert says so.
|
|
12
|
+
// Every function here reads and writes Flow's database only.
|
|
13
|
+
|
|
14
|
+
export const HAND_OFF_MS = 24 * 60 * 60_000;
|
|
15
|
+
// How long an expired move stays in the alert.
|
|
16
|
+
const EXPIRED_ALERT_MS = 7 * 24 * 60 * 60_000;
|
|
17
|
+
const MAX_STATUS = 80;
|
|
18
|
+
|
|
19
|
+
// The address that opens one order in Seazona, from SEAZONA_ORDER_URL with
|
|
20
|
+
// its {ref} placeholder, or null when the installation has not set one.
|
|
21
|
+
export function orderUrl(template, ref) {
|
|
22
|
+
if (!template || !template.includes('{ref}')) return null;
|
|
23
|
+
return template.replaceAll('{ref}', encodeURIComponent(ref));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Record a person's move of one order to `toStatus`, and answer the hand-off
|
|
27
|
+
// the board shows. A second move of the same order replaces the first.
|
|
28
|
+
export async function requestStageMove(db, { orderId, toStatus, personId = null, orderUrlTemplate = null, now = Date.now() }) {
|
|
29
|
+
const to = typeof toStatus === 'string' ? toStatus.trim() : '';
|
|
30
|
+
if (!to || to.length > MAX_STATUS) throw new FlowError('invalid', 'toStatus must be a Seazona status');
|
|
31
|
+
const [order] = await db.select().from(seazonaOrders).where(eq(seazonaOrders.id, String(orderId ?? '')));
|
|
32
|
+
if (!order || order.deletedInSourceAt) throw new FlowError('not_found', 'Flow has no Seazona order with that number');
|
|
33
|
+
const known = await db.selectDistinct({ status: seazonaOrders.status }).from(seazonaOrders)
|
|
34
|
+
.where(eq(sql`lower(trim(${seazonaOrders.status}))`, to.toLowerCase()));
|
|
35
|
+
if (!known.length) throw new FlowError('invalid', `Seazona has no status named ${to}`);
|
|
36
|
+
const from = orderStatusLabel(order) || null;
|
|
37
|
+
if (from && from.toLowerCase() === to.toLowerCase()) throw new FlowError('conflict', `The order is already ${from} in Seazona`);
|
|
38
|
+
const at = new Date(Number(now));
|
|
39
|
+
const row = {
|
|
40
|
+
orderId: order.id, fromStatus: from, toStatus: known[0].status.trim(), requestedBy: personId,
|
|
41
|
+
requestedAt: at, expiresAt: new Date(at.getTime() + HAND_OFF_MS), state: 'waiting', settledAt: null,
|
|
42
|
+
};
|
|
43
|
+
await db.insert(seazonaStageMoves).values(row).onConflictDoUpdate({ target: seazonaStageMoves.orderId, set: row });
|
|
44
|
+
return handOff(row, { orderUrlTemplate });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Take a waiting move back: the card returns to Seazona's stage.
|
|
48
|
+
export async function cancelStageMove(db, { orderId, now = Date.now() }) {
|
|
49
|
+
const rows = await db.update(seazonaStageMoves).set({ state: 'cancelled', settledAt: new Date(Number(now)) })
|
|
50
|
+
.where(and(eq(seazonaStageMoves.orderId, String(orderId ?? '')), eq(seazonaStageMoves.state, 'waiting'))).returning();
|
|
51
|
+
return { cancelled: rows.length > 0 };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Settle the waiting moves against Flow's copy of the orders: done when the
|
|
55
|
+
// order has the new status, expired when a day has passed. An order that
|
|
56
|
+
// moved to some other status settles as done too: Seazona has the last word.
|
|
57
|
+
export async function settleStageMoves(db, { now = Date.now() } = {}) {
|
|
58
|
+
const at = new Date(Number(now));
|
|
59
|
+
const waiting = await db.select({ move: seazonaStageMoves, order: seazonaOrders }).from(seazonaStageMoves)
|
|
60
|
+
.leftJoin(seazonaOrders, eq(seazonaOrders.id, seazonaStageMoves.orderId))
|
|
61
|
+
.where(eq(seazonaStageMoves.state, 'waiting'));
|
|
62
|
+
const done = [];
|
|
63
|
+
const expired = [];
|
|
64
|
+
for (const { move, order } of waiting) {
|
|
65
|
+
const status = orderStatusLabel(order) || null;
|
|
66
|
+
if (status && status !== move.fromStatus) done.push(move.orderId);
|
|
67
|
+
else if (move.expiresAt <= at) expired.push(move.orderId);
|
|
68
|
+
}
|
|
69
|
+
if (done.length) {
|
|
70
|
+
await db.update(seazonaStageMoves).set({ state: 'done', settledAt: at })
|
|
71
|
+
.where(and(inArray(seazonaStageMoves.orderId, done), eq(seazonaStageMoves.state, 'waiting')));
|
|
72
|
+
}
|
|
73
|
+
if (expired.length) {
|
|
74
|
+
await db.update(seazonaStageMoves).set({ state: 'expired', settledAt: at })
|
|
75
|
+
.where(and(inArray(seazonaStageMoves.orderId, expired), eq(seazonaStageMoves.state, 'waiting')));
|
|
76
|
+
}
|
|
77
|
+
return { done: done.length, expired: expired.length };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The waiting moves, by order id, for the board's cards.
|
|
81
|
+
export async function waitingStageMoves(db) {
|
|
82
|
+
const rows = await db.select().from(seazonaStageMoves).where(eq(seazonaStageMoves.state, 'waiting'));
|
|
83
|
+
return new Map(rows.map((r) => [r.orderId, r]));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The moves that expired in the last week, for the quiet alert.
|
|
87
|
+
export async function expiredStageMoves(db, { now = Date.now() } = {}) {
|
|
88
|
+
return db.select().from(seazonaStageMoves).where(and(
|
|
89
|
+
eq(seazonaStageMoves.state, 'expired'),
|
|
90
|
+
gte(seazonaStageMoves.settledAt, new Date(Number(now) - EXPIRED_ALERT_MS)),
|
|
91
|
+
lt(seazonaStageMoves.settledAt, new Date(Number(now) + 1)),
|
|
92
|
+
));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// What the board shows for a waiting move.
|
|
96
|
+
export function handOff(row, { orderUrlTemplate = null } = {}) {
|
|
97
|
+
return {
|
|
98
|
+
kind: 'hand_off',
|
|
99
|
+
system: 'seazona',
|
|
100
|
+
sourceJobRef: row.orderId,
|
|
101
|
+
caseRef: row.orderId,
|
|
102
|
+
from: row.fromStatus,
|
|
103
|
+
to: row.toStatus,
|
|
104
|
+
state: row.state,
|
|
105
|
+
requestedAt: row.requestedAt.toISOString(),
|
|
106
|
+
expiresAt: row.expiresAt.toISOString(),
|
|
107
|
+
openUrl: orderUrl(orderUrlTemplate, row.orderId),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Each person's own Seazona choices, with their defaults.
|
|
112
|
+
export const PERSON_SETTINGS = Object.freeze([
|
|
113
|
+
{
|
|
114
|
+
key: 'askBeforeStageMoves',
|
|
115
|
+
label: 'Ask before stage moves',
|
|
116
|
+
hint: 'On the Jobs board, show what to do in Seazona before a card moves to a Seazona stage.',
|
|
117
|
+
kind: 'onoff',
|
|
118
|
+
default: true,
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
export async function readPersonSettings(db, personId) {
|
|
123
|
+
const [row] = await db.select().from(seazonaPersonSettings).where(eq(seazonaPersonSettings.personId, String(personId)));
|
|
124
|
+
return PERSON_SETTINGS.map((s) => ({ ...s, value: row ? Boolean(row[s.key]) : s.default }));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function writePersonSetting(db, personId, { key, value }, { now = Date.now() } = {}) {
|
|
128
|
+
const setting = PERSON_SETTINGS.find((s) => s.key === key);
|
|
129
|
+
if (!setting) throw new FlowError('invalid', 'no such setting');
|
|
130
|
+
if (typeof value !== 'boolean') throw new FlowError('invalid', `${setting.label} must be on or off`);
|
|
131
|
+
const at = new Date(Number(now));
|
|
132
|
+
await db.insert(seazonaPersonSettings).values({ personId: String(personId), [key]: value, updatedAt: at })
|
|
133
|
+
.onConflictDoUpdate({ target: seazonaPersonSettings.personId, set: { [key]: value, updatedAt: at } });
|
|
134
|
+
return readPersonSettings(db, personId);
|
|
135
|
+
}
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import * as SentryNode from '@sentry/node';
|
|
2
|
+
import { scrubSpan } from '../../ui/monitoring.js';
|
|
2
3
|
|
|
3
|
-
// The Sentry adapter (docs/SENTRY.md). It sends the errors Flow logs,
|
|
4
|
-
// browser's errors and problem reports,
|
|
4
|
+
// The Sentry adapter (docs/SENTRY.md). It sends the errors Flow logs, the
|
|
5
|
+
// browser's errors and problem reports, and performance traces from both
|
|
6
|
+
// (when SENTRY_TRACES_SAMPLE_RATE is above 0), to the installation's own Sentry
|
|
5
7
|
// project. Flow ships no DSN: each installation enters its own, here or as
|
|
6
8
|
// the host setting SENTRY_DSN. It has no tables.
|
|
7
9
|
|
|
8
10
|
// The browser SDK, loaded from Sentry's CDN only while this adapter is on
|
|
9
|
-
// (server/ui/monitoring.js). Pinned, with its integrity hash.
|
|
11
|
+
// (server/ui/monitoring.js). Pinned, with its integrity hash. With traces on,
|
|
12
|
+
// the bundle that also traces; Sentry ships it only with session replay in
|
|
13
|
+
// it too, which Flow never turns on.
|
|
10
14
|
export const SENTRY_BROWSER = Object.freeze({
|
|
11
15
|
src: 'https://browser.sentry-cdn.com/11.4.0/bundle.feedback.min.js',
|
|
12
16
|
integrity: 'sha384-H9RmZ/VaqOPZrUezgCSqHp4t3LoQMd/5+0Y4oEGUB2bddZzSnwZiOYoWneK4diWt',
|
|
13
17
|
});
|
|
18
|
+
export const SENTRY_BROWSER_TRACING = Object.freeze({
|
|
19
|
+
src: 'https://browser.sentry-cdn.com/11.4.0/bundle.tracing.replay.feedback.min.js',
|
|
20
|
+
integrity: 'sha384-LjwHQKAojcITl6Q7innDSAFjziFnqV9ovZBNXnXnQwub1VXIdBMJnYrQNihtxSa6',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// The share of requests and page loads traced when the setting is empty.
|
|
24
|
+
export const DEFAULT_TRACES_SAMPLE_RATE = 0.2;
|
|
14
25
|
|
|
15
26
|
// A DSN is https://<public key>@<host>/<project id>.
|
|
16
27
|
const DSN_PATTERN = /^https:\/\/[0-9a-f]{16,64}@[a-z0-9.-]+(:\d+)?\/(\d+)$/i;
|
|
@@ -31,6 +42,7 @@ export const SENTRY_SETUP = {
|
|
|
31
42
|
{ name: 'SENTRY_DSN', label: 'DSN', kind: 'url', help: 'From the Sentry project\'s Client Keys. Browsers see it, so it is not a secret.' },
|
|
32
43
|
{ name: 'SENTRY_ENVIRONMENT', label: 'Environment', help: 'How Sentry labels this installation, for example production. Empty: production.' },
|
|
33
44
|
{ name: 'SENTRY_FEEDBACK', label: 'Report a problem button', kind: 'onoff', help: 'On: everyone signed in can send a report, with a screenshot, to this Sentry project.' },
|
|
45
|
+
{ name: 'SENTRY_TRACES_SAMPLE_RATE', label: 'Traces', help: 'The share of clicks, page loads and requests timed, from 0 (off) to 1 (all). Empty: 0.2.' },
|
|
34
46
|
],
|
|
35
47
|
};
|
|
36
48
|
|
|
@@ -40,9 +52,17 @@ export function readSentrySettings(env) {
|
|
|
40
52
|
if (!DSN_PATTERN.test(dsn)) throw new Error('SENTRY_DSN is not a Sentry DSN (https://<key>@<host>/<project id>).');
|
|
41
53
|
const environment = String(env.SENTRY_ENVIRONMENT ?? '').trim() || 'production';
|
|
42
54
|
const feedback = String(env.SENTRY_FEEDBACK ?? 'on').trim() !== 'off';
|
|
43
|
-
|
|
55
|
+
const rate = String(env.SENTRY_TRACES_SAMPLE_RATE ?? '').trim();
|
|
56
|
+
const tracesSampleRate = rate === '' ? DEFAULT_TRACES_SAMPLE_RATE : Number(rate);
|
|
57
|
+
if (!/^\d*\.?\d+$/.test(rate || '0') || !(tracesSampleRate >= 0 && tracesSampleRate <= 1)) {
|
|
58
|
+
throw new Error('SENTRY_TRACES_SAMPLE_RATE must be a number from 0 to 1, such as 0.2.');
|
|
59
|
+
}
|
|
60
|
+
return { dsn, environment, feedback, tracesSampleRate };
|
|
44
61
|
}
|
|
45
62
|
|
|
63
|
+
// No trace for the host's health check: it is not a person waiting.
|
|
64
|
+
const UNTRACED_PATHS = new Set(['/health']);
|
|
65
|
+
|
|
46
66
|
// The release Sentry groups events by: Flow's release tag, else its commit.
|
|
47
67
|
export function sentryRelease(env) {
|
|
48
68
|
const read = (value) => String(value ?? '').trim() || null;
|
|
@@ -51,7 +71,7 @@ export function sentryRelease(env) {
|
|
|
51
71
|
return release ? `flow@${release.replace(/^v/, '')}` : revision ? `flow@${revision.slice(0, 12)}` : null;
|
|
52
72
|
}
|
|
53
73
|
|
|
54
|
-
// `sdk` is for tests: anything with init,
|
|
74
|
+
// `sdk` is for tests: anything with init, captureEvent, captureException
|
|
55
75
|
// and close, as @sentry/node has.
|
|
56
76
|
export function createSentryAdapter({ sdk = SentryNode, env: hostEnv = process.env } = {}) {
|
|
57
77
|
let settings = null;
|
|
@@ -71,10 +91,14 @@ export function createSentryAdapter({ sdk = SentryNode, env: hostEnv = process.e
|
|
|
71
91
|
release: release ?? undefined,
|
|
72
92
|
// Flow sends what it logs; no request bodies, cookies or IP addresses.
|
|
73
93
|
sendDefaultPii: false,
|
|
74
|
-
|
|
75
|
-
|
|
94
|
+
// A request the browser traced keeps the browser's choice, so a
|
|
95
|
+
// click and the server work it caused stay one trace.
|
|
96
|
+
tracesSampler: ({ attributes, inheritOrSampleWith }) => (
|
|
97
|
+
UNTRACED_PATHS.has(attributes?.['url.path']) ? 0 : inheritOrSampleWith(settings.tracesSampleRate)
|
|
98
|
+
),
|
|
99
|
+
beforeSendSpan: scrubSpan,
|
|
76
100
|
});
|
|
77
|
-
log.info?.(`[sentry] on: environment ${settings.environment}; report button ${settings.feedback ? 'on' : 'off'}`);
|
|
101
|
+
log.info?.(`[sentry] on: environment ${settings.environment}; report button ${settings.feedback ? 'on' : 'off'}; traces ${settings.tracesSampleRate > 0 ? settings.tracesSampleRate : 'off'}`);
|
|
78
102
|
},
|
|
79
103
|
async stop() {
|
|
80
104
|
if (settings) await sdk.close(2000);
|
|
@@ -90,13 +114,40 @@ export function createSentryAdapter({ sdk = SentryNode, env: hostEnv = process.e
|
|
|
90
114
|
if (!settings) return;
|
|
91
115
|
const scope = { level: 'error', tags: { source } };
|
|
92
116
|
if (error instanceof Error) sdk.captureException(error, { ...scope, extra: { log: message } });
|
|
93
|
-
|
|
117
|
+
// Not captureMessage: the SDK adds a stack to it, and Sentry then
|
|
118
|
+
// names the issue after its top frame ("Object.captureError"), not
|
|
119
|
+
// the line Flow logged. A plain event keeps the line as the title.
|
|
120
|
+
else sdk.captureEvent({ message, ...scope });
|
|
94
121
|
},
|
|
95
122
|
// What the browser needs to report to the same project. The DSN is
|
|
96
123
|
// meant for browsers.
|
|
97
124
|
browserMonitoring() {
|
|
98
125
|
if (!settings) return null;
|
|
99
|
-
|
|
126
|
+
const { tracesSampleRate } = settings;
|
|
127
|
+
return {
|
|
128
|
+
dsn: settings.dsn,
|
|
129
|
+
environment: settings.environment,
|
|
130
|
+
release,
|
|
131
|
+
feedback: settings.feedback,
|
|
132
|
+
tracesSampleRate,
|
|
133
|
+
script: tracesSampleRate > 0 ? SENTRY_BROWSER_TRACING : SENTRY_BROWSER,
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
// Runs `work` in a span of the current trace (server/core/tracing.js).
|
|
137
|
+
// Work outside a traced request (the pipeline, the workers) starts no
|
|
138
|
+
// trace of its own.
|
|
139
|
+
traceSpan({ name, op, attributes }, work) {
|
|
140
|
+
if (!settings?.tracesSampleRate) return work();
|
|
141
|
+
return sdk.startSpan({ name, op, attributes, onlyIfParent: true }, work);
|
|
142
|
+
},
|
|
143
|
+
// At a request's start: a function that names its trace once the route
|
|
144
|
+
// is known, or null when this request is not traced.
|
|
145
|
+
traceRequest() {
|
|
146
|
+
if (!settings?.tracesSampleRate) return null;
|
|
147
|
+
const span = sdk.getActiveSpan();
|
|
148
|
+
if (!span) return null;
|
|
149
|
+
const root = sdk.getRootSpan(span);
|
|
150
|
+
return (name) => sdk.updateSpanName(root, name);
|
|
100
151
|
},
|
|
101
152
|
},
|
|
102
153
|
};
|
package/server/ui/app-page.js
CHANGED
|
@@ -51,7 +51,7 @@ const BODY = `<div class="fx-app">
|
|
|
51
51
|
<div id="toasts" class="fx-toasts" aria-live="polite"></div>
|
|
52
52
|
</div>`;
|
|
53
53
|
|
|
54
|
-
export const APP_PATHS = ['/sign-in', '/jobs', '/invoices', '/invoices/:id', '/people', '/integrations', '/integrations/:id', '/account', '/appearance', '/invoicing-settings', '/price-list'];
|
|
54
|
+
export const APP_PATHS = ['/sign-in', '/jobs', '/invoices', '/invoices/:id', '/people', '/integrations', '/integrations/:id', '/account', '/appearance', '/invoicing-settings', '/price-list', '/custom-fields'];
|
|
55
55
|
|
|
56
56
|
export function appPage({ defaultFamily }) {
|
|
57
57
|
return renderPage({
|
package/server/ui/app.js
CHANGED
|
@@ -13,6 +13,7 @@ import { renderInvoice, renderInvoiceList } from '/assets/ui/invoicing.js';
|
|
|
13
13
|
import { automationSection } from '/assets/ui/automations.js';
|
|
14
14
|
import { renderInvoicingSettings, sendModeSection } from '/assets/ui/invoicing-settings.js';
|
|
15
15
|
import { renderPriceList } from '/assets/ui/price-list.js';
|
|
16
|
+
import { renderCustomFields } from '/assets/ui/custom-fields.js';
|
|
16
17
|
import { renderJobs } from '/assets/ui/jobs.js';
|
|
17
18
|
import { startMonitoring } from '/assets/ui/monitoring.js';
|
|
18
19
|
import { openSearch } from '/assets/ui/search.js';
|
|
@@ -198,6 +199,7 @@ const VIEWS = {
|
|
|
198
199
|
invoices: { label: 'Invoices', icon: 'invoices', group: 'Work', render: (main, id) => (id ? renderInvoice(main, ui(), id) : renderInvoiceList(main, ui())) },
|
|
199
200
|
'invoicing-settings': { label: 'Invoice rules', icon: 'invoices', group: 'Settings', render: (main) => renderInvoicingSettings(main, ui()) },
|
|
200
201
|
'price-list': { label: 'Price list', icon: 'tag', group: 'Settings', render: (main) => renderPriceList(main, ui()) },
|
|
202
|
+
'custom-fields': { label: 'Custom fields', icon: 'fields', group: 'Settings', render: (main) => renderCustomFields(main, ui()) },
|
|
201
203
|
people: { label: 'People', icon: 'people', group: 'Settings', ownerOnly: true, render: renderPeople },
|
|
202
204
|
integrations: { label: 'Integrations', icon: 'plug', group: 'Settings', ownerOnly: true, render: (main, id) => (id ? renderIntegration(main, id) : renderIntegrations(main)) },
|
|
203
205
|
// Not in the sidebar: "Manage account" in the account menu opens the same
|
|
@@ -212,6 +214,7 @@ const ICON_PATHS = {
|
|
|
212
214
|
invoices: '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h7M9 17h5"/>',
|
|
213
215
|
people: '<circle cx="9" cy="8" r="3"/><path d="M3 20c0-3.5 2.7-6 6-6s6 2.5 6 6"/><path d="M16 5a3 3 0 010 6M21 20c0-3-1.6-5-4-5.7"/>',
|
|
214
216
|
tag: '<path d="M3 12V4h8l10 10-8 8z"/><circle cx="7.5" cy="8.5" r="1.5"/>',
|
|
217
|
+
fields: '<rect x="3" y="4" width="18" height="5" rx="1.5"/><rect x="3" y="13" width="18" height="5" rx="1.5"/><path d="M7 6.5h4M7 15.5h7"/>',
|
|
215
218
|
plug: '<path d="M9 3v5M15 3v5M6 8h12v3a6 6 0 01-12 0zM12 17v4"/>',
|
|
216
219
|
person: '<circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 3.6-7 8-7s8 3 8 7"/>',
|
|
217
220
|
flag: '<path d="M5 21V4M5 4h11l-2 4 2 4H5"/>',
|
|
@@ -309,11 +312,15 @@ function reportMenuItem(openReport) {
|
|
|
309
312
|
};
|
|
310
313
|
}
|
|
311
314
|
|
|
315
|
+
// The page a person lands on after sign-in, and for / or an unknown path.
|
|
316
|
+
// Invoices opens on its Ready tab. A home page can take this over later.
|
|
317
|
+
const START_VIEW = 'invoices';
|
|
318
|
+
|
|
312
319
|
// The view and, for one record, its id: /invoices/<id> is ['invoices', '<id>'].
|
|
313
320
|
function currentView() {
|
|
314
321
|
const [name, id = null] = location.pathname.replace(/^\/+|\/+$/g, '').split('/');
|
|
315
322
|
if (VIEWS[name] && (!VIEWS[name].ownerOnly || me?.person.role === 'owner')) return [name, id];
|
|
316
|
-
return [
|
|
323
|
+
return [START_VIEW, null];
|
|
317
324
|
}
|
|
318
325
|
|
|
319
326
|
async function route() {
|
|
@@ -533,7 +540,7 @@ const STATE_TONE = { ready: 'success', disabled: 'mute', failed: 'danger', resta
|
|
|
533
540
|
const CATALOGUE = {
|
|
534
541
|
xero: { maker: 'Xero', category: 'accounting', blurb: 'Send invoices to Xero as drafts and bring payments back.', logo: 'xero.svg' },
|
|
535
542
|
seazona: { maker: 'Seazona', category: 'lab', blurb: 'Bring lab cases and orders into Flow as jobs.', logo: 'seazona.svg' },
|
|
536
|
-
sentry: { maker: 'Sentry', category: 'monitoring', blurb: 'Send errors
|
|
543
|
+
sentry: { maker: 'Sentry', category: 'monitoring', blurb: 'Send errors, problem reports and speed traces to your own Sentry project.', logo: 'sentry.svg' },
|
|
537
544
|
};
|
|
538
545
|
const CATEGORIES = [['all', 'All'], ['accounting', 'Accounting'], ['lab', 'Lab software'], ['monitoring', 'Monitoring']];
|
|
539
546
|
const CATEGORY_LABEL = Object.fromEntries(CATEGORIES);
|
|
@@ -774,6 +781,7 @@ async function renderIntegration(main, id) {
|
|
|
774
781
|
current.state === 'failed' && current.error ? notice(current.error, 'danger', 'It could not start.') : null,
|
|
775
782
|
current.id === 'xero' && current.state === 'ready' ? h('section', { class: 'fx-int-section' }, xeroConnection(body.organisations, canChange)) : null,
|
|
776
783
|
current.id === 'seazona' ? h('section', { class: 'fx-int-section fx-card', style: { padding: '8px 20px 16px' } }, automationSection(ui(), 'seazona', 'Ready to invoice')) : null,
|
|
784
|
+
on && current.state === 'ready' ? personSettingsSection(current) : null,
|
|
777
785
|
current.id === 'xero' ? h('section', { class: 'fx-int-section fx-card', style: { padding: '8px 20px 16px' } }, sendModeSection(ui())) : null,
|
|
778
786
|
guide ? h('section', { class: 'fx-int-section' },
|
|
779
787
|
h('h2', { class: 'fx-int-section__title' }, 'Set up'),
|
|
@@ -798,6 +806,36 @@ async function renderIntegration(main, id) {
|
|
|
798
806
|
draw(found);
|
|
799
807
|
}
|
|
800
808
|
|
|
809
|
+
// "Your settings": this person's own choices in one integration
|
|
810
|
+
// (GET /api/work/my-settings), such as Seazona's "Ask before stage moves".
|
|
811
|
+
// Each person sees and changes only their own.
|
|
812
|
+
function personSettingsSection(integration) {
|
|
813
|
+
const section = h('section', { class: 'fx-int-section' },
|
|
814
|
+
h('h2', { class: 'fx-int-section__title' }, 'Your settings'), h('div', { class: 'fx-skeleton' }));
|
|
815
|
+
flow(`/api/work/my-settings?integration=${encodeURIComponent(integration.id)}`).then(({ integrations }) => {
|
|
816
|
+
const settings = integrations[0]?.settings ?? [];
|
|
817
|
+
if (!settings.length) { section.remove(); return; }
|
|
818
|
+
const rows = settings.map((setting) => {
|
|
819
|
+
const input = h('select', { class: 'fx-select' },
|
|
820
|
+
[{ value: 'off', label: 'Off' }, { value: 'on', label: 'On' }].map((c) => h('option', { value: c.value, selected: (setting.value ? 'on' : 'off') === c.value }, c.label)));
|
|
821
|
+
input.addEventListener('change', async () => {
|
|
822
|
+
input.disabled = true;
|
|
823
|
+
try {
|
|
824
|
+
await flow('/api/work/my-settings', { method: 'PUT', body: JSON.stringify({ integration: integration.id, key: setting.key, value: input.value === 'on' }) });
|
|
825
|
+
toast('Saved for you.', 'success');
|
|
826
|
+
} catch (error) {
|
|
827
|
+
input.value = setting.value ? 'on' : 'off';
|
|
828
|
+
toast(error.message, 'danger');
|
|
829
|
+
}
|
|
830
|
+
input.disabled = false;
|
|
831
|
+
});
|
|
832
|
+
return settingRow({ label: setting.label, hint: setting.hint, control: input });
|
|
833
|
+
});
|
|
834
|
+
section.replaceChildren(section.firstChild, h('div', { class: 'fx-settings' }, rows));
|
|
835
|
+
}).catch(() => section.remove());
|
|
836
|
+
return section;
|
|
837
|
+
}
|
|
838
|
+
|
|
801
839
|
// One setting, laid out the same on every settings screen: a short name, one
|
|
802
840
|
// line of smaller text under it, and the control on the right. Longer help
|
|
803
841
|
// lives behind a link, not here. A wide control (a grid of choices) sits on
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Settings, Custom fields (/custom-fields; server/core/custom-fields.js,
|
|
2
|
+
// docs/CUSTOM_FIELDS.md). The fields a lab makes for its jobs, like ClickUp's
|
|
3
|
+
// custom fields: each row is one field, with its type and, for a dropdown,
|
|
4
|
+
// its options in lane order. Create field and Edit open a dialog. The work
|
|
5
|
+
// systems' own fields (Seazona's stage) show below, read only: Flow reads
|
|
6
|
+
// them and never changes them here. Everyone can read the page; an owner or
|
|
7
|
+
// admin changes it. The caller passes in app.js's shared pieces as `ui`.
|
|
8
|
+
|
|
9
|
+
const DOCS = 'https://github.com/arcforgelabs/flow/blob/main/docs/CUSTOM_FIELDS.md';
|
|
10
|
+
const TYPE_LABELS = {
|
|
11
|
+
dropdown: 'Dropdown', person: 'Person', checkbox: 'Checkbox', date: 'Date', number: 'Number', text: 'Text',
|
|
12
|
+
};
|
|
13
|
+
const TYPE_HINTS = {
|
|
14
|
+
dropdown: 'One option from a list. Makes board lanes.',
|
|
15
|
+
person: 'One person in Flow. Makes board lanes.',
|
|
16
|
+
checkbox: 'Yes or no. Makes board lanes.',
|
|
17
|
+
date: 'A day, for example a promised date.',
|
|
18
|
+
number: 'A number, for example units.',
|
|
19
|
+
text: 'A short note.',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export async function renderCustomFields(main, ui) {
|
|
23
|
+
const { h, flow, toast, notice, dialog, pageHeader, me } = ui;
|
|
24
|
+
const disabled = !['owner', 'admin'].includes(me?.person.role);
|
|
25
|
+
const host = h('div', { class: 'fx-card', style: { padding: '8px 20px 16px' } }, h('div', { class: 'fx-skeleton' }));
|
|
26
|
+
const addButton = h('button', { class: 'fx-btn fx-btn--primary', type: 'button', disabled }, 'Create field');
|
|
27
|
+
main.append(pageHeader('Custom fields', { subtitle: 'Fields for your jobs. They stay in Flow and never change Seazona or Xero.', actions: [addButton] }), host);
|
|
28
|
+
|
|
29
|
+
let data = null;
|
|
30
|
+
|
|
31
|
+
async function send(path, method, payload, done = 'Saved.') {
|
|
32
|
+
try {
|
|
33
|
+
const body = await flow(path, { method, ...(payload ? { body: JSON.stringify(payload) } : {}) });
|
|
34
|
+
if (done) toast(done, 'success');
|
|
35
|
+
return body;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
toast(error.message, 'danger');
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const row = (name, hint, control) => h('div', { class: 'fx-set__row' },
|
|
43
|
+
h('div', { class: 'fx-set__text' }, h('span', { class: 'fx-set__name' }, name), hint),
|
|
44
|
+
h('div', { class: 'fx-set__control fx-rule__controls' }, control));
|
|
45
|
+
const optionChip = (o) => h('span', { class: 'fx-cf__opt', 'data-color': o.color ?? 'gray' }, o.name);
|
|
46
|
+
const typeChip = (type) => h('span', { class: 'fx-chip fx-chip--static' }, TYPE_LABELS[type] ?? type);
|
|
47
|
+
|
|
48
|
+
// The option list editor for a dropdown: one line per option (name,
|
|
49
|
+
// colour, move up, remove), in lane order.
|
|
50
|
+
function optionsEditor(start) {
|
|
51
|
+
let options = start.filter((o) => !o.archived).map((o) => ({ ...o }));
|
|
52
|
+
const list = h('div', { class: 'fx-fields fx-cf__options' });
|
|
53
|
+
const add = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm', type: 'button' }, 'Add option');
|
|
54
|
+
function draw() {
|
|
55
|
+
list.replaceChildren(...options.map((o, i) => {
|
|
56
|
+
const name = h('input', { class: 'fx-input', maxlength: '40', value: o.name, 'aria-label': `Option ${i + 1}`, placeholder: 'Option name' });
|
|
57
|
+
name.addEventListener('input', () => { o.name = name.value; });
|
|
58
|
+
const color = h('select', { class: 'fx-select fx-cf__color', 'aria-label': `Colour of option ${i + 1}`, 'data-color': o.color },
|
|
59
|
+
data.colors.map((c) => h('option', { value: c }, c[0].toUpperCase() + c.slice(1))));
|
|
60
|
+
color.value = o.color ?? 'gray';
|
|
61
|
+
color.addEventListener('change', () => { o.color = color.value; color.dataset.color = color.value; });
|
|
62
|
+
const up = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm', type: 'button', 'aria-label': `Move option ${i + 1} up`, disabled: i === 0 }, '↑');
|
|
63
|
+
up.addEventListener('click', () => { [options[i - 1], options[i]] = [options[i], options[i - 1]]; draw(); });
|
|
64
|
+
const remove = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm fx-rule__delete', type: 'button', 'aria-label': `Remove option ${i + 1}` }, 'Remove');
|
|
65
|
+
remove.addEventListener('click', () => { options.splice(i, 1); draw(); });
|
|
66
|
+
return h('div', { class: 'fx-cf__line' }, name, color, up, remove);
|
|
67
|
+
}));
|
|
68
|
+
if (!options.length) list.append(h('span', { class: 'fx-dim' }, 'No options yet.'));
|
|
69
|
+
}
|
|
70
|
+
add.addEventListener('click', () => {
|
|
71
|
+
options.push({ name: '', color: data.colors[options.length % data.colors.length] });
|
|
72
|
+
draw();
|
|
73
|
+
list.querySelector('.fx-cf__line:last-child input')?.focus();
|
|
74
|
+
});
|
|
75
|
+
draw();
|
|
76
|
+
return {
|
|
77
|
+
element: h('div', { class: 'fx-fields' }, list, add),
|
|
78
|
+
value: () => options.filter((o) => o.name.trim()).map(({ id, name, color }) => ({ ...(id ? { id } : {}), name, color })),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The dialog for a new field (field null) or an existing one. The type is
|
|
83
|
+
// fixed once the field exists.
|
|
84
|
+
async function edit(field, draft = field) {
|
|
85
|
+
const label = (text, control, hint) => h('div', { class: 'fx-field' }, h('span', { class: 'fx-label' }, text), control, hint ?? null);
|
|
86
|
+
const name = h('input', { class: 'fx-input', required: true, maxlength: '60', value: draft?.name ?? '', 'aria-label': 'Field name', placeholder: 'For example Priority' });
|
|
87
|
+
const type = h('select', { class: 'fx-select', 'aria-label': 'Type', disabled: Boolean(field) },
|
|
88
|
+
data.types.map((t) => h('option', { value: t }, TYPE_LABELS[t] ?? t)));
|
|
89
|
+
type.value = draft?.type ?? 'dropdown';
|
|
90
|
+
const typeHint = h('span', { class: 'fx-dim' }, TYPE_HINTS[type.value]);
|
|
91
|
+
const editor = optionsEditor(draft?.options ?? [
|
|
92
|
+
{ name: 'To do', color: 'gray' }, { name: 'Doing', color: 'blue' }, { name: 'Done', color: 'green' },
|
|
93
|
+
]);
|
|
94
|
+
const optionsField = label('Options', editor.element, h('span', { class: 'fx-dim' }, 'Board lanes follow this order. A removed option is kept for old jobs.'));
|
|
95
|
+
const showOptions = () => { optionsField.hidden = type.value !== 'dropdown'; typeHint.textContent = TYPE_HINTS[type.value]; };
|
|
96
|
+
type.addEventListener('change', showOptions);
|
|
97
|
+
showOptions();
|
|
98
|
+
|
|
99
|
+
let action = null;
|
|
100
|
+
const parts = [label('Name', name), label('Type', type, typeHint), optionsField];
|
|
101
|
+
if (field) {
|
|
102
|
+
const archive = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm fx-rule__delete', type: 'button' }, 'Archive field');
|
|
103
|
+
archive.addEventListener('click', () => { action = 'archive'; archive.closest('dialog').close(); });
|
|
104
|
+
parts.push(archive);
|
|
105
|
+
}
|
|
106
|
+
const ok = await dialog({ title: field ? `Edit ${field.name}` : 'Create field', body: h('div', { class: 'fx-fields fx-rule__dialog' }, ...parts), confirm: field ? 'Save' : 'Create field' });
|
|
107
|
+
if (action === 'archive') {
|
|
108
|
+
if (await send(`/api/custom-fields/${field.id}/archive`, 'POST', { archived: true }, 'Archived. Its values are kept.')) return load();
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
if (!ok) return null;
|
|
112
|
+
const payload = { name: name.value };
|
|
113
|
+
if (!field) payload.type = type.value;
|
|
114
|
+
if (type.value === 'dropdown') payload.options = editor.value();
|
|
115
|
+
const body = field
|
|
116
|
+
? await send(`/api/custom-fields/${field.id}`, 'PUT', payload)
|
|
117
|
+
: await send('/api/custom-fields', 'POST', payload, 'Field created.');
|
|
118
|
+
if (!body) return edit(field, { ...draft, ...payload, type: type.value });
|
|
119
|
+
return load();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function move(index, by) {
|
|
123
|
+
const ids = data.fields.map((f) => f.id);
|
|
124
|
+
[ids[index], ids[index + by]] = [ids[index + by], ids[index]];
|
|
125
|
+
if (await send('/api/custom-fields/order', 'PUT', { ids }, null)) await load();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function fieldRow(field, index) {
|
|
129
|
+
const hint = h('div', { class: 'fx-price__hint' }, typeChip(field.type),
|
|
130
|
+
...(field.type === 'dropdown' ? field.options.filter((o) => !o.archived).map(optionChip) : [h('span', { class: 'fx-set__hint' }, TYPE_HINTS[field.type])]));
|
|
131
|
+
const controls = [];
|
|
132
|
+
if (index !== null) {
|
|
133
|
+
const up = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm', type: 'button', disabled: disabled || index === 0, 'aria-label': `Move ${field.name} up` }, '↑');
|
|
134
|
+
up.addEventListener('click', () => move(index, -1));
|
|
135
|
+
const down = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm', type: 'button', disabled: disabled || index === data.fields.length - 1, 'aria-label': `Move ${field.name} down` }, '↓');
|
|
136
|
+
down.addEventListener('click', () => move(index, 1));
|
|
137
|
+
const editButton = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm', type: 'button', disabled }, 'Edit');
|
|
138
|
+
editButton.addEventListener('click', () => edit(field));
|
|
139
|
+
controls.push(up, down, editButton);
|
|
140
|
+
} else {
|
|
141
|
+
const back = h('button', { class: 'fx-btn fx-btn--ghost fx-btn--sm', type: 'button', disabled }, 'Bring back');
|
|
142
|
+
back.addEventListener('click', async () => {
|
|
143
|
+
if (await send(`/api/custom-fields/${field.id}/archive`, 'POST', { archived: false }, 'Brought back.')) await load();
|
|
144
|
+
});
|
|
145
|
+
controls.push(back);
|
|
146
|
+
}
|
|
147
|
+
return row(field.name, hint, h('div', { class: 'fx-row' }, ...controls));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function systemRow(field) {
|
|
151
|
+
const options = field.options.slice(0, 12).map((o) => h('span', { class: 'fx-cf__opt', 'data-color': o.final ? 'green' : 'gray' }, o.name));
|
|
152
|
+
if (field.options.length > 12) options.push(h('span', { class: 'fx-set__hint' }, `${field.options.length - 12} more`));
|
|
153
|
+
return row(`${field.sourceLabel} ${field.name.toLowerCase()}`, h('div', { class: 'fx-price__hint' }, typeChip(field.type), ...options),
|
|
154
|
+
h('span', { class: 'fx-status', 'data-tone': 'mute' }, `Read only · from ${field.sourceLabel}`));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function draw() {
|
|
158
|
+
const archived = data.archived.filter((f) => f.archived);
|
|
159
|
+
const sections = [
|
|
160
|
+
disabled ? notice('Only an owner or admin can change these. Everyone can set a job\'s values.', 'info') : null,
|
|
161
|
+
h('section', { class: 'fx-set' }, h('h2', { class: 'fx-set__title' }, `Your fields · ${data.fields.length}`),
|
|
162
|
+
...(data.fields.length ? data.fields.map(fieldRow)
|
|
163
|
+
: [h('p', { class: 'fx-dim' }, 'No fields yet. Create one, for example Priority or Technician, to group the Jobs board by it.')])),
|
|
164
|
+
];
|
|
165
|
+
if (data.systemFields.length) {
|
|
166
|
+
sections.push(h('section', { class: 'fx-set' }, h('h2', { class: 'fx-set__title' }, 'From integrations'),
|
|
167
|
+
...data.systemFields.map(systemRow),
|
|
168
|
+
h('p', { class: 'fx-dim', style: { margin: '8px 0 0' } }, 'Flow reads these. Change them in their own system.')));
|
|
169
|
+
}
|
|
170
|
+
if (archived.length) {
|
|
171
|
+
sections.push(h('section', { class: 'fx-set' }, h('h2', { class: 'fx-set__title' }, `Archived · ${archived.length}`), ...archived.map((f) => fieldRow(f, null))));
|
|
172
|
+
}
|
|
173
|
+
sections.push(h('p', { class: 'fx-dim', style: { margin: '8px 0 0' } }, h('a', { href: DOCS, target: '_blank', rel: 'noopener' }, 'How custom fields work')));
|
|
174
|
+
host.replaceChildren(...sections.filter(Boolean));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function load() {
|
|
178
|
+
try {
|
|
179
|
+
const [live, all] = await Promise.all([flow('/api/custom-fields'), flow('/api/custom-fields?archived=1')]);
|
|
180
|
+
data = { ...live, archived: all.fields };
|
|
181
|
+
} catch (error) {
|
|
182
|
+
host.replaceChildren(notice(error.message, 'danger'));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
draw();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
addButton.addEventListener('click', () => edit(null));
|
|
189
|
+
await load();
|
|
190
|
+
}
|