All files / components/service-calls service-calls.tsx

86.2% Statements 25/29
81.15% Branches 56/69
71.42% Functions 5/7
86.2% Lines 25/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 1471x   1x 1x   1x             5x   5x   5x       5x   1x 1x   4x         4x   4x 4x             9x 9x             9x 5x                           4x   4x 4x 4x 4x   4x                                                                                 8x                                                                      
import { Component, h, Prop, Host, State, Watch } from "@stencil/core";
import { ServiceCallsResponse } from "./service-calls-response";
import api from "../../utils/api";
import { ServiceCaseCreateModal } from "../service-case-create/service-case-create-modal";
 
@Component({
    tag: "ux-w-service-calls",
    styleUrl: "service-calls.scss",
    shadow: false
})
export class ServiceCalls {
    /** URL where this widget can request the data */
    @Prop() url: string = "";
    /** This holds the response from the API with all Information required to show the widget */
    @State() data: ServiceCallsResponse = null;
    /** data is loading */
    @State() loading: boolean = false;
 
    @Watch("url")
    componentWillLoad() {
        if (this.url === "") {
            // eslint-disable-next-line no-console
            console.warn("url needs to be supplied for WidgetServiceCalls");
            return;
        }
        window.setTimeout(() => {
            Iif (this.data === null) {
                this.loading = true;
            }
        });
        api<ServiceCallsResponse>(this.url)
            .then((data: ServiceCallsResponse) => {
                this.data = data;
                this.loading = false;
            })
            // eslint-disable-next-line no-console
            .catch((error) => console.error(error));
    }
 
    render() {
        const baseClass = "ux-w-service-calls";
        Iif (this.loading) {
            return (
                <Host class={baseClass}>
                    <ux-w-wrapper isLoading />
                </Host>
            );
        }
        if (this.data === null) {
            return null;
        }
        const {
            link,
            linkTitle,
            title,
            noCallsText,
            createCall,
            createCallLink,
            messages,
            noData,
            noDataText,
            isCaseOverviewAllowed,
            serviceCaseMicroFrontend
        } = this.data;
 
        const hasCalls = this.data?.calls?.length > 0;
        const calls = hasCalls ? [...this.data.calls] : null;
        const createCaseModalName = "new-service-case";
        const showEmptyState = !hasCalls && !noData && isCaseOverviewAllowed;
 
        return (
            <Host class={baseClass}>
                <ux-w-wrapper url={link} linkTitle={linkTitle} headline={title}>
                    <div slot="content">
                        {!isCaseOverviewAllowed && (
                            <ux-w-empty icon="cross" class="ux-color-error">
                                <div
                                    innerHTML={messages?.disabledOverviewText}
                                ></div>
                            </ux-w-empty>
                        )}
                        {showEmptyState && (
                            <ux-w-empty
                                link={
                                    !serviceCaseMicroFrontend && createCallLink
                                }
                                linkText={
                                    (!serviceCaseMicroFrontend && createCall) ||
                                    ""
                                }
                                icon="hand-list-arrow"
                            >
                                <div innerHTML={noCallsText}></div>
                                {!!serviceCaseMicroFrontend && (
                                    <ux-button
                                        slot="link"
                                        data-trigger-modal={`open,${createCaseModalName}`}
                                        class="ux-w-empty__link"
                                    >
                                        {createCall}
                                    </ux-button>
                                )}
                            </ux-w-empty>
                        )}
                        {!hasCalls && noData && isCaseOverviewAllowed && (
                            <ux-w-empty icon="crane">
                                <div innerHTML={noDataText}></div>
                            </ux-w-empty>
                        )}
                        {isCaseOverviewAllowed &&
                            calls?.map((call) => {
                                return (
                                    <div class={`${baseClass}__item`}>
                                        <ux-w-service-calls-item
                                            headline={call.title}
                                            statusType={call.status?.type}
                                            statusText={call.status?.text}
                                            machineName={call.machineName}
                                            machineNumber={call.machineNumber}
                                            lastChange={call.lastChange}
                                            lastChangeLabel={
                                                messages?.lastChange
                                            }
                                            callIdLabel={messages?.callId}
                                            callId={call.callId}
                                            link={call.link}
                                            linkTitle={messages?.details}
                                            timeFormat={messages?.timeFormat}
                                        ></ux-w-service-calls-item>
                                    </div>
                                );
                            })}
                    </div>
                </ux-w-wrapper>
                {showEmptyState && serviceCaseMicroFrontend && (
                    <ServiceCaseCreateModal
                        modalName={createCaseModalName}
                        env={serviceCaseMicroFrontend.env}
                        legacyApi={serviceCaseMicroFrontend.legacyApi}
                        locale={serviceCaseMicroFrontend.locale}
                    />
                )}
            </Host>
        );
    }
}