Fix localize key types to remove user groups exception (#13259)

This commit is contained in:
Steve Repsher 2022-07-27 05:37:52 -04:00 committed by GitHub
parent c73677f15d
commit 086c33d8b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -15,7 +15,6 @@ type LocalizeKeyExceptions =
| `state.${string}` | `state.${string}`
| `state_attributes.${string}` | `state_attributes.${string}`
| `state_badge.${string}` | `state_badge.${string}`
| `groups.${string}`
| `ui.${string}` | `ui.${string}`
| `${keyof TranslationDict["supervisor"]}.${string}` | `${keyof TranslationDict["supervisor"]}.${string}`
| `component.${string}`; | `component.${string}`;

View File

@ -4,7 +4,7 @@ import {
mdiHomeCircleOutline, mdiHomeCircleOutline,
mdiCancel, mdiCancel,
} from "@mdi/js"; } from "@mdi/js";
import { HomeAssistant } from "../types"; import { HomeAssistant, TranslationDict } from "../types";
import { Credential } from "./auth"; import { Credential } from "./auth";
export const SYSTEM_GROUP_ID_ADMIN = "system-admin"; export const SYSTEM_GROUP_ID_ADMIN = "system-admin";
@ -21,7 +21,7 @@ export interface User {
is_active: boolean; is_active: boolean;
local_only: boolean; local_only: boolean;
system_generated: boolean; system_generated: boolean;
group_ids: string[]; group_ids: (keyof TranslationDict["groups"])[];
credentials: Credential[]; credentials: Credential[];
} }
@ -95,7 +95,12 @@ export const computeUserBadges = (
includeSystem: boolean includeSystem: boolean
) => { ) => {
const labels: [string, string][] = []; const labels: [string, string][] = [];
const translate = (key) => hass.localize(`ui.panel.config.users.${key}`); const translate = (
key: Extract<
keyof TranslationDict["ui"]["panel"]["config"]["users"],
`is_${string}`
>
) => hass.localize(`ui.panel.config.users.${key}`);
if (user.is_owner) { if (user.is_owner) {
labels.push([OWNER_ICON, translate("is_owner")]); labels.push([OWNER_ICON, translate("is_owner")]);

View File

@ -30,13 +30,13 @@ import { showUserDetailDialog } from "./show-dialog-user-detail";
export class HaConfigUsers extends LitElement { export class HaConfigUsers extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public _users: User[] = []; @property({ attribute: false }) public _users: User[] = [];
@property() public isWide!: boolean; @property({ type: Boolean }) public isWide!: boolean;
@property() public narrow!: boolean; @property({ type: Boolean }) public narrow!: boolean;
@property() public route!: Route; @property({ attribute: false }) public route!: Route;
private _columns = memoizeOne( private _columns = memoizeOne(
(narrow: boolean, localize: LocalizeFunc): DataTableColumnContainer => { (narrow: boolean, localize: LocalizeFunc): DataTableColumnContainer => {
@ -76,7 +76,8 @@ export class HaConfigUsers extends LitElement {
width: "20%", width: "20%",
direction: "asc", direction: "asc",
hidden: narrow, hidden: narrow,
template: (groupIds) => html` ${localize(`groups.${groupIds[0]}`)} `, template: (groupIds: User["group_ids"]) =>
html` ${localize(`groups.${groupIds[0]}`)} `,
}, },
is_active: { is_active: {
title: this.hass.localize( title: this.hass.localize(
@ -238,3 +239,9 @@ export class HaConfigUsers extends LitElement {
}); });
} }
} }
declare global {
interface HTMLElementTagNameMap {
"ha-config-users": HaConfigUsers;
}
}