buildListing()

in source/idea/idea-cluster-manager/webapp/src/pages/virtual-desktops/virtual-desktop-sessions.tsx [639:910]


    buildListing() {
        return (
            <IdeaListView
                ref={this.listing}
                title="Sessions"
                showPreferences={true}
                preferencesKey={PREFERENCES_KEY}
                description="Virtual Desktop sessions for all users. End-users see these sessions as Virtual Desktops."
                selectionType="multi"
                primaryAction={{
                    id: "create-session",
                    text: "Create Session",
                    onClick: () => {
                        this.showCreateSessionForm();
                    },
                }}
                secondaryActionsDisabled={!this.isSelected()}
                secondaryActions={[
                    {
                        id: "resume-session",
                        text: "Resume Session(s)",
                        disabled: !this.isSelected() || !this.isAdmin(),
                        onClick: () => {
                            this.setState(
                                {
                                    forceStop: true,
                                },
                                () => {
                                    this.getResumeSessionsConfirmModal().show();
                                }
                            );
                        },
                    },
                    {
                        id: "stop-session",
                        text: "Stop/Hibernate Session(s)",
                        disabled: !this.isSelected() || !this.isAdmin(),
                        onClick: () => {
                            this.setState(
                                {
                                    forceStop: true,
                                },
                                () => {
                                    this.getStopSessionsConfirmModal().show();
                                }
                            );
                        },
                    },
                    {
                        id: "force-stop-session",
                        text: "Force Stop/Hibernate Session(s)",
                        disabled: !this.isSelected() || !this.isAdmin(),
                        onClick: () => {
                            this.setState(
                                {
                                    forceStop: true,
                                },
                                () => {
                                    this.getStopSessionsConfirmModal().show();
                                }
                            );
                        },
                    },
                    {
                        id: "terminate-session",
                        text: "Terminate Session(s)",
                        disabled: !this.isSelected(),
                        onClick: () => {
                            this.setState(
                                {
                                    forceTerminate: false,
                                },
                                () => {
                                    this.getTerminateSessionsConfirmModal().show();
                                }
                            );
                        },
                    },
                    {
                        id: "force-terminate-session",
                        text: "Force Terminate Session(s)",
                        disabled: !this.isSelected(),
                        onClick: () => {
                            this.setState(
                                {
                                    forceTerminate: true,
                                },
                                () => {
                                    this.getTerminateSessionsConfirmModal().show();
                                }
                            );
                        },
                    },
                    {
                        id: "get-session-health",
                        text: "Session(s) Health",
                        disabled: !this.isSelected() || !this.isAdmin(),
                        onClick: () => {
                            let sessions: VirtualDesktopSession[] = [];
                            this.getSelectedSessions().forEach((session) => {
                                sessions.push({
                                    idea_session_id: session.idea_session_id,
                                    dcv_session_id: session.dcv_session_id,
                                });
                            });

                            this.getVirtualDCVClient()
                                .describeSessions({
                                    sessions: sessions,
                                })
                                .then((response) => {
                                    let health = response.response;
                                    delete health?.request_id;
                                    delete health?.next_token;
                                    this.setState(
                                        {
                                            sessionHealth: health?.sessions,
                                        },
                                        () => {
                                            this.getSessionHealthModal().show();
                                        }
                                    );
                                });
                        },
                    },
                    {
                        id: "create-software-stack",
                        text: "Create Software Stack From Session",
                        disabled: !this.canCreateSoftwareStack() || !this.isAdmin(),
                        disabledReason: "Select exactly 1 session to enable this Action",
                        onClick: () => {
                            // we know that there is exactly 1 session
                            this.getSelectedSessions().forEach((session) => {
                                this.showCreateSoftwareStackForm(session);
                            });
                        },
                    },
                ]}
                showPaginator={true}
                onRefresh={() => {
                    this.setState(
                        {
                            sessionSelected: false,
                        },
                        () => {
                            this.getListing().fetchRecords();
                        }
                    );
                }}
                showDateRange={true}
                dateRange={{
                    type: "relative",
                    amount: 1,
                    unit: "month",
                }}
                dateRangeFilterKeyOptions={[
                    { value: "created_on", label: "Created" },
                    { value: "updated_on", label: "Updated" },
                ]}
                showFilters={true}
                filterType="select"
                selectFilters={[
                    {
                        name: "$all",
                    },
                    {
                        name: "state",
                        choices: [
                            {
                                title: "All States",
                                value: "",
                            },
                            {
                                title: "Ready",
                                value: "READY",
                            },
                            {
                                title: "Provisioning",
                                value: "PROVISIONING",
                            },
                            {
                                title: "Stopped",
                                value: "STOPPED",
                            },
                            {
                                title: "Stopped Idle",
                                value: "STOPPED_IDLE",
                            },
                            {
                                title: "Stopping",
                                value: "STOPPING",
                            },
                            {
                                title: "Initializing",
                                value: "INITIALIZING",
                            },
                            {
                                title: "Creating",
                                value: "CREATING",
                            },
                            {
                                title: "Resuming",
                                value: "RESUMING",
                            },
                            {
                                title: "Deleting",
                                value: "DELETING",
                            },
                            {
                                title: "Error",
                                value: "ERROR",
                            },
                        ],
                    },
                    {
                        name: "base_os",
                        choices: [
                            {
                                title: "All Operating Systems",
                                value: "",
                            },
                            {
                                title: "Amazon Linux 2",
                                value: "amazonlinux2",
                            },
                            {
                                title: "Windows",
                                value: "windows",
                            },
                            {
                                title: "RHEL 8",
                                value: "rhel8"
                            },
                            {
                                title: "RHEL 9",
                                value: "rhel9"
                            }
                        ],
                    },
                ]}
                onFilter={(filters) => {
                    return filters;
                }}
                onSelectionChange={(event) => {
                    this.setState({
                        sessionSelected: event.detail.selectedItems.length > 0,
                    });
                }}
                onFetchRecords={() => {
                    return (this.isAdmin() ? this.getVirtualDesktopAdminClient() : this.getVirtualDesktopClient())
                        .listSessions({
                            filters: this.getListing().getFilters(),
                            paginator: { page_size: 100 },
                            date_range: this.getListing().getFormatedDateRange(),
                        })
                        .catch((error) => {
                            this.props.onFlashbarChange({
                                items: [
                                    {
                                        content: error.message,
                                        type: "error",
                                        dismissible: true,
                                    },
                                ],
                            });
                            throw error;
                        });
                }}
                columnDefinitions={VIRTUAL_DESKTOP_SESSIONS_TABLE_COLUMN_DEFINITIONS}
            />
        );
    }