Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions packages/core/src/openbim/BCFTopics/src/Topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,25 @@ export class Topic implements BCFTopic {
// Based on the BCF API documentation, the files associated with a topic are the models that should be loaded when displaying the topic's viewpoints.
// files: any

// Strict mode drops values that are not in the configuration, and it used
// to do so in complete silence: the topic was created, the value was gone,
// and nothing anywhere said why. Rejections must be audible.
private static warnRejected(field: string, value: unknown) {
console.warn(
`BCFTopics: "${String(value)}" is not one of the configured ${field}, and strict mode is on. The value was ignored; add it to the BCFTopics config or disable strict mode.`,
);
}

private _type = Topic.default.type;

set type(value: string) {
const manager = this._components.get(BCFTopics);
const { strict, types } = manager.config;
const valid = strict ? types.has(value) : true;
if (!valid) return;
if (!valid) {
Topic.warnRejected("types", value);
return;
}
this._type = value;
}

Expand All @@ -72,7 +84,10 @@ export class Topic implements BCFTopic {
const manager = this._components.get(BCFTopics);
const { strict, statuses } = manager.config;
const valid = strict ? statuses.has(value) : true;
if (!valid) return;
if (!valid) {
Topic.warnRejected("statuses", value);
return;
}
this._status = value;
}

Expand All @@ -87,7 +102,10 @@ export class Topic implements BCFTopic {
if (value) {
const { strict, priorities } = manager.config;
const valid = strict ? priorities.has(value) : true;
if (!valid) return;
if (!valid) {
Topic.warnRejected("priorities", value);
return;
}
this._priority = value;
} else {
this._priority = value;
Expand All @@ -105,7 +123,10 @@ export class Topic implements BCFTopic {
if (value) {
const { strict, stages } = manager.config;
const valid = strict ? stages.has(value) : true;
if (!valid) return;
if (!valid) {
Topic.warnRejected("stages", value);
return;
}
this._stage = value;
} else {
this._stage = value;
Expand All @@ -123,7 +144,10 @@ export class Topic implements BCFTopic {
if (value) {
const { strict, users } = manager.config;
const valid = strict ? users.has(value) : true;
if (!valid) return;
if (!valid) {
Topic.warnRejected("users", value);
return;
}
this._assignedTo = value;
} else {
this._assignedTo = value;
Expand All @@ -143,7 +167,10 @@ export class Topic implements BCFTopic {
const _value = new Set<string>();
for (const label of value) {
const valid = strict ? labels.has(label) : true;
if (!valid) continue;
if (!valid) {
Topic.warnRejected("labels", label);
continue;
}
_value.add(label);
}
this._labels = _value;
Expand Down
Loading