Replace the agent's remote scope by Remote, open to someone in: chips written as one remote_from gate
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c99e91f5b9
commit
1c7bc72198
3 files changed
+78
-69
No files matched your search
+70
-64
@@ -24,7 +24,7 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const { api, count } = window;
|
||||
const { api, count, remoteHelpers: rh } = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2, taste: 0.2 };
|
||||
@@ -38,7 +38,7 @@
|
||||
const EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR",
|
||||
"HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE",
|
||||
"IS", "LI", "NO", "GB", "CH", "EU"];
|
||||
const FIELDS = ["place", "country", "remote", "seniority", "function", "salary_min",
|
||||
const FIELDS = ["place", "country", "remote", "remote_from", "seniority", "function", "salary_min",
|
||||
"currency", "permit", "languages", "company"];
|
||||
const MODES = [["require", "must"], ["any", "one of"], ["prefer", "prefer"]];
|
||||
const HYBRID_WEIGHT = 0.05;
|
||||
@@ -107,11 +107,33 @@
|
||||
}
|
||||
|
||||
// The countries Where offers, by name: Europe's, without EU, which is not
|
||||
// a country but "open anywhere in Europe" and is said by Remote.
|
||||
// a country but "open anywhere in Europe" and is picked in the remote line.
|
||||
const COUNTRIES = EUROPE.filter((c) => c !== "EU")
|
||||
.map((c) => [c, countryName(c)])
|
||||
.sort((a, b) => a[1].localeCompare(b[1]));
|
||||
|
||||
/** @type {Map<string, string>} the words of the `remote_from` values, by
|
||||
* value, as `/api/places/labels` says them; a card and a chip fall back to
|
||||
* `rh.fallbackLabel` until they are in */
|
||||
const placeNames = new Map();
|
||||
const placeLabel = (value) => placeNames.get(value) || rh.fallbackLabel(value, countryName);
|
||||
|
||||
// The labels of the `remote_from` tokens in `gates` that are not known yet.
|
||||
// A failure is toasted by `api()` and leaves the fallbacks.
|
||||
async function nameRemote(gates) {
|
||||
const missing = [...new Set(gates.filter((g) => g.field === "remote_from")
|
||||
.flatMap((g) => g.values.map(String)))]
|
||||
.filter((v) => v !== rh.ANYWHERE && !placeNames.has(v));
|
||||
if (!missing.length) return;
|
||||
const p = new URLSearchParams();
|
||||
missing.forEach((t) => p.append("tokens", t));
|
||||
try {
|
||||
for (const { token, label } of await api(`/api/places/labels?${p}`)) placeNames.set(token, label);
|
||||
} catch (err) {
|
||||
// the fallbacks stand
|
||||
}
|
||||
}
|
||||
|
||||
// "a, b or c": the values of one line.
|
||||
function orList(items) {
|
||||
return items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`;
|
||||
@@ -196,6 +218,7 @@
|
||||
}
|
||||
if (gate.field === "place") return `in ${orList(towns(values))}`;
|
||||
if (gate.field === "remote") return orList(values);
|
||||
if (gate.field === "remote_from") return rh.remoteSentence(values, placeLabel);
|
||||
if (gate.field === "company") return `at ${orList(values)}`;
|
||||
if (gate.field === "salary_min") return `paying at least ${values[0]}`;
|
||||
return `with ${gate.field.replace("_", " ")} ${values.join(", ")}`;
|
||||
@@ -203,14 +226,14 @@
|
||||
|
||||
// The Where block in words, one sentence of the lines a role may match,
|
||||
// with the one-of rows among them since they are the same group: "Keeps
|
||||
// roles anywhere in Denmark, in Malmö, Lund or Helsingborg, or remote within
|
||||
// Europe, and leaves out the rest." The lines add up, which the first
|
||||
// roles anywhere in Denmark, in Malmö, Lund or Helsingborg, or remote from
|
||||
// Denmark, Sweden or Germany, and leaves out the rest." The lines add up, which the first
|
||||
// wording ("Roles in ...") left the owner to guess.
|
||||
function whereSentence(where, others) {
|
||||
const parts = [];
|
||||
if (where.countries) parts.push(`anywhere ${phrase(where.countries)}`);
|
||||
if (where.places) parts.push(phrase(where.places));
|
||||
if (where.remote) parts.push(where.europe ? "remote within Europe" : "remote");
|
||||
if (where.remote && where.remote.values.length) parts.push(rh.remoteSentence(where.remote.values, placeLabel));
|
||||
parts.push(...others.map(phrase));
|
||||
if (!parts.length) return "";
|
||||
const list = parts.length < 2 ? parts[0] : `${parts.slice(0, -1).join(", ")}, or ${parts[parts.length - 1]}`;
|
||||
@@ -218,11 +241,11 @@
|
||||
}
|
||||
|
||||
// The gates in words: where a role may be, then what it must meet, then
|
||||
// what lifts it. "Keeps roles anywhere in Denmark, or remote within Europe,
|
||||
// what lifts it. "Keeps roles anywhere in Denmark, or remote from anywhere,
|
||||
// and leaves out the rest. Only roles with seniority senior. Prefers
|
||||
// hybrid."
|
||||
function rulesLine(gates) {
|
||||
const { where, rest } = distribute(gates);
|
||||
const { where, rest } = rh.distribute(gates);
|
||||
const of = (mode) => rest.filter((g) => g.mode === mode);
|
||||
const must = of("require").map(phrase);
|
||||
const prefer = of("prefer").map((g) => phrase(g).replace(/^with /, ""));
|
||||
@@ -379,6 +402,38 @@
|
||||
return { node: chips.node, values: () => [...chips.list] };
|
||||
}
|
||||
|
||||
// "Remote, open to someone in": the values of a `remote_from` gate as chips,
|
||||
// picked from the place suggestions that a remote hire can live in:
|
||||
// countries, regions and Anywhere. `values()` are the gate's values
|
||||
// (`country:DK`, `anywhere`), the chips say them in words.
|
||||
function remoteInput(values, onChange) {
|
||||
const root = el("div");
|
||||
root.id = "a-remote-from";
|
||||
const chips = window.chipInput(root, {
|
||||
suggest: async (q) => {
|
||||
const rows = await api(`/api/suggest/places?${new URLSearchParams({ q })}`);
|
||||
const picks = [];
|
||||
for (const s of rows) {
|
||||
const value = rh.fromSuggestion(s);
|
||||
if (value === null) continue;
|
||||
picks.push(value === rh.ANYWHERE
|
||||
? { value, label: "Anywhere" }
|
||||
: { value, label: s.label, hint: s.kind });
|
||||
}
|
||||
const has = picks.some((p) => p.value === rh.ANYWHERE);
|
||||
if (!has && rh.offersAnywhere(q)) picks.unshift({ value: rh.ANYWHERE, label: "Anywhere" });
|
||||
return picks;
|
||||
},
|
||||
onChange: (items) => {
|
||||
items.forEach((i) => placeNames.set(i.value, i.label));
|
||||
onChange();
|
||||
},
|
||||
placeholder: "Add a country, a region or Anywhere", label: "Remote, open to someone in",
|
||||
});
|
||||
chips.set(values.map((v) => ({ value: v, label: placeLabel(v) })));
|
||||
return { node: root, values: () => chips.values().map((i) => i.value) };
|
||||
}
|
||||
|
||||
// Words as chips of free text, added on Enter or a comma, and one chip for
|
||||
// the spellings that fold alike. What is typed but not added yet counts, so
|
||||
// Save does not drop it. Towns and fetch terms both.
|
||||
@@ -490,46 +545,6 @@
|
||||
return { node: row, read };
|
||||
}
|
||||
|
||||
// Share out an agent's gates between the Where block and Other rules. Each
|
||||
// Where line takes the first gate it can say whole; the rest are rows. A
|
||||
// must or one-of gate with a weight other than the default stays a row,
|
||||
// since Where would drop it. Remote within Europe is a must on country
|
||||
// that is Europe and the countries line exactly, and only with Remote
|
||||
// ticked; any other must on country is a row, and Remote reads anywhere.
|
||||
function distribute(gates) {
|
||||
const where = { countries: null, places: null, remote: null, europe: null, hybrid: null };
|
||||
const rest = [];
|
||||
const musts = [];
|
||||
const plain = (g) => g.weight === undefined || g.weight === 1;
|
||||
const only = (g, value) => g.values.length === 1 && g.values[0] === value;
|
||||
for (const g of gates) {
|
||||
let slot = null;
|
||||
if (g.field === "country" && g.mode === "require" && plain(g)) {
|
||||
musts.push(g);
|
||||
continue;
|
||||
}
|
||||
if (g.field === "country" && g.mode === "any" && plain(g)) slot = "countries";
|
||||
else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote")) slot = "remote";
|
||||
else if (g.field === "place" && g.mode === "any" && plain(g)) slot = "places";
|
||||
else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid")) slot = "hybrid";
|
||||
if (slot && !where[slot]) where[slot] = g;
|
||||
else rest.push(g);
|
||||
}
|
||||
const within = new Set(europeWith(where.countries ? where.countries.values : []));
|
||||
for (const g of musts) {
|
||||
const same = g.values.length === within.size && g.values.every((v) => within.has(v));
|
||||
if (where.remote && !where.europe && same) where.europe = g;
|
||||
else rest.push(g);
|
||||
}
|
||||
return { where, rest };
|
||||
}
|
||||
|
||||
// What Remote within Europe sends: Europe, and the countries line too,
|
||||
// since the must holds for every role, not only the remote ones.
|
||||
function europeWith(countries) {
|
||||
return [...EUROPE, ...countries.filter((c) => !EUROPE.includes(c))];
|
||||
}
|
||||
|
||||
function form(row) {
|
||||
const div = el("article", "agent-card editing");
|
||||
const f = $("#agent-form-template").content.querySelector("form").cloneNode(true);
|
||||
@@ -558,22 +573,15 @@
|
||||
changed(f);
|
||||
});
|
||||
|
||||
const { where, rest } = distribute(row ? row.gates : []);
|
||||
const { where, rest } = rh.distribute(row ? row.gates : []);
|
||||
const countries = countryInput(where.countries ? where.countries.values : []);
|
||||
const places = wordInput(where.places ? where.places.values : [], "Add a town");
|
||||
const terms = wordInput(row ? row.fetch_terms || [] : [], "machine learning, data science");
|
||||
$("#a-terms", f).replaceWith(terms.node);
|
||||
$("#a-countries", f).replaceWith(countries.node);
|
||||
$("#a-towns", f).replaceWith(places.node);
|
||||
const remote = $("#a-remote", f);
|
||||
const scope = $("#a-remote-scope", f);
|
||||
remote.checked = Boolean(where.remote);
|
||||
// Anywhere when a must on country is a row, so ticking Remote does not
|
||||
// stack a second one on it; else Europe, the usual answer.
|
||||
const mustRow = rest.some((g) => g.field === "country" && g.mode === "require");
|
||||
scope.value = where.europe || !(where.remote || mustRow) ? "europe" : "anywhere";
|
||||
const offerScope = () => { scope.disabled = !remote.checked; };
|
||||
offerScope();
|
||||
const remoteFrom = remoteInput(where.remote ? where.remote.values : [], () => changed(f));
|
||||
$("#a-remote-from", f).replaceWith(remoteFrom.node);
|
||||
// The hybrid weight shows only when it is not the default; either way it
|
||||
// is sent back as it came.
|
||||
const hybridWeight = where.hybrid && where.hybrid.weight !== undefined ? where.hybrid.weight : HYBRID_WEIGHT;
|
||||
@@ -601,16 +609,14 @@
|
||||
});
|
||||
|
||||
// The gates the Where block says, in the order the starter agents have
|
||||
// them: the must on country, the lines, then hybrid.
|
||||
// them: the lines, then hybrid.
|
||||
function whereGates() {
|
||||
const out = [];
|
||||
const within = countries.values();
|
||||
const towns = places.values();
|
||||
if (remote.checked && scope.value === "europe") {
|
||||
out.push({ field: "country", values: europeWith(within), mode: "require" });
|
||||
}
|
||||
const from = remoteFrom.values();
|
||||
if (within.length) out.push({ field: "country", values: within, mode: "any" });
|
||||
if (remote.checked) out.push({ field: "remote", values: ["remote"], mode: "any" });
|
||||
if (from.length) out.push({ field: "remote_from", values: from, mode: "any" });
|
||||
if (towns.length) out.push({ field: "place", values: towns, mode: "any" });
|
||||
if ($("#a-hybrid", f).checked) {
|
||||
out.push({ field: "remote", values: ["hybrid"], mode: "prefer", weight: Number($("#a-hybrid-weight", f).value) });
|
||||
@@ -621,7 +627,6 @@
|
||||
// under Where says them all, as the card will, rows included.
|
||||
const gates = () => whereGates().concat(rules.map((r) => r.read()));
|
||||
const view = () => {
|
||||
offerScope();
|
||||
$("#a-gates", f).value = JSON.stringify(gates(), null, 2);
|
||||
$("#a-where-sum", f).textContent = rulesLine(gates()) || "Keeps roles anywhere.";
|
||||
};
|
||||
@@ -795,6 +800,7 @@
|
||||
|
||||
async function load() {
|
||||
agents = await api("/api/agents");
|
||||
await nameRemote(agents.flatMap((a) => a.gates || []));
|
||||
// A card is only worded by it, so a failure leaves the cards as they were.
|
||||
try {
|
||||
stageOn = Object.fromEntries((await api("/api/stages")).map((s) => [s.name, s.on]));
|
||||
|
||||
@@ -1249,6 +1249,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
.where-line { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .9rem; }
|
||||
.where-line > span, .where-line > label { flex: none; min-width: 9rem; }
|
||||
.where-line .chips { flex: 1 1 12rem; }
|
||||
.where-line .chip-input { flex: 1 1 12rem; min-width: 0; margin: 0; }
|
||||
/* Hybrid ranks rather than filters, so it stands apart from the lines, and
|
||||
the sentence under it says the whole block. */
|
||||
.agent-form .where-rank { margin-top: .4rem; }
|
||||
|
||||
@@ -39,12 +39,10 @@
|
||||
</div>
|
||||
<span class="hint">Towns are for places outside the countries above: with Denmark above, Malmö here adds Malmö to all of Denmark. A town inside a country above changes nothing, since the whole country is in already.</span>
|
||||
<div class="where-line">
|
||||
<label class="inline"><input type="checkbox" id="a-remote"> or remote</label>
|
||||
<select id="a-remote-scope" aria-label="Remote from where">
|
||||
<option value="europe">within Europe</option>
|
||||
<option value="anywhere">anywhere</option>
|
||||
</select>
|
||||
<span>Remote, open to someone in:</span>
|
||||
<div id="a-remote-from"></div>
|
||||
</div>
|
||||
<span class="hint">A remote role is kept when it can be worked from one of these; Anywhere is for roles open worldwide. A remote role whose area is not stated yet ranks until extract reads the posting.</span>
|
||||
<label class="inline where-rank"><input type="checkbox" id="a-hybrid"> Prefer hybrid<span id="a-hybrid-weight-line">, adding <input type="number" id="a-hybrid-weight" min="0" step="0.05" value="0.05" aria-label="Weight of hybrid"></span></label>
|
||||
<span class="hint">This one ranks rather than filters: a hybrid role gains a little.</span>
|
||||
<p id="a-where-sum" class="where-sum" role="status"></p>
|
||||
@@ -96,5 +94,9 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
{# chips.css only adds to app.css; base.html has no head block for it. #}
|
||||
<link rel="stylesheet" href="{{ asset('chips.css') }}">
|
||||
<script src="{{ asset('chips.js') }}"></script>
|
||||
<script src="{{ asset('remote.js') }}"></script>
|
||||
<script src="{{ asset('agents.js') }}"></script>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user