mattermost-mobile-upstream/app/utils/classification.ts
Pablo Vélez 54731fa6ac
Mm 70299 channel labels display phase 1 (#10113)
* MM-70299 - display channel attributes in header, info and banner

* cover and expand channel attributes feature with UI and E2E tests

* Implement channel attributes lock and update related tests and API methods

* Enhance error logging and improve type definitions for channel attributes

* Handle error from setAccessControlGroupId in fetchAccessControlAttributeFields

* Refactor fetchAccessControlAttributeFields to include system ID handling and improve batch record persistence

* Address code review feedback: extract feature-flag constants, move DB-only helpers to query/local layers, refactor attribute chip styles, fix colour spelling, and add test coverage for value pruning and subtitle component

* Fix error handling in removeStoredFields function and delete obsolete end-to-end test file

* Add tests for removeStoredFields function and enhance property queries

* Fix removeStoredFields to recover group ID from classification anchor and clean all owned fields

* Fix batchRecords silently swallowing write errors in fetchAccessControlAttributeFields

* Remove unused visibility check for ChannelAttributeLabels in e2e tests

* Fix classification fetch cache and channel-attributes E2E lock contention

Do not stamp the classification banner cache when both access-control flags
are off, so turning a flag back on after a reload refetches fields.

Share the classification lock with the channel-attributes Detox suite and
stop unsetting ClassificationMarkings. Skip flag-on tests when the server
cannot enable ChannelAttributes.

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* Scope access_control field prune to owned object types

handlePropertyFields(groupId) deletes every field in the group. The fetch
only returns system and channel fields, so same-group user/session rows
were removed on each refresh. Prune only system and channel fields, matching
removeStoredFields.

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* fail channel attributes tests when feature enablement fails instead of silently reporting them as passed

* Compose all channel attribute values in banners with template resolution, mixed field support, and matching web colors

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: mattermost-code <matty-code@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2026-09-17 21:37:43 +02:00

65 lines
2.3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {
CLASSIFICATIONS_FIELD_NAME,
CLASSIFICATIONS_SYSTEM_OBJECT_TYPE,
DISPLAY_BANNER_TOP,
} from '@constants/classification';
import type {PropertyFieldModel, PropertyValueModel} from '@database/models/server';
export type ClassificationBannerState = {
visible: boolean;
levelName: string;
color: string;
};
// Minimal structural shapes that both the WatermelonDB models and the query
// observers satisfy. Selection (group/field/value/delete_at) is handled by the
// scoped queries in @queries/servers/properties; these helpers only map the
// selected records to a banner view model.
type ClassificationField = Pick<PropertyFieldModel, 'id' | 'name' | 'objectType' | 'attrs'>;
type ClassificationValue = Pick<PropertyValueModel, 'fieldId' | 'value'>;
const hiddenState: ClassificationBannerState = {visible: false, levelName: '', color: ''};
export function deriveClassificationBannerState(
fields: ClassificationField[],
systemValues: ClassificationValue[],
): ClassificationBannerState {
const systemField = fields.find(
(f) => f.objectType === CLASSIFICATIONS_SYSTEM_OBJECT_TYPE &&
f.name === CLASSIFICATIONS_FIELD_NAME,
);
if (!systemField) {
return hiddenState;
}
const actions = (systemField.attrs?.actions as string[] | undefined) ?? [];
if (!actions.includes(DISPLAY_BANNER_TOP)) {
return hiddenState;
}
const systemValue = systemValues.find((v) => v.fieldId === systemField.id);
const optionId = (systemValue?.value as string | undefined) ?? '';
if (!optionId) {
return hiddenState;
}
const options = (systemField.attrs?.options as PropertyFieldOption[] | undefined) ?? [];
const levelOption = options.find((o) => o.id === optionId);
return {
visible: Boolean(levelOption?.name),
levelName: levelOption?.name ?? '',
color: levelOption?.color ?? '',
};
}
// The per-channel banner is no longer classification's: any attribute designated
// for banner display produces one. See deriveChannelAttributeBanner in
// @utils/channel_attributes, which selects by attrs.actions and keeps a
// name-based fallback for classification fields that predate any configuration.