"...lm-evaluation-harness.git" did not exist on "5e59320b709fd08ee24fd3fd098ea17cb5a9ad8a"
ConfigDetail.js 5.55 KB
Newer Older
chenzk's avatar
v1.0  
chenzk committed
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React, { useState, useEffect } from 'react';
import Link from '@docusaurus/Link';

function CodeValue({ value }) {
  if (!value) return null;

  if (value.includes('\n') || value.length > 50) {
    return (
      <pre>
        <code>{value}</code>
      </pre>
    );
  }

  return <code>{value}</code>;
}

function NestedTypeTable({ nestedTypes }) {
  if (!nestedTypes || nestedTypes.length === 0) return null;

  return (
    <table className="nested-type-table">
      <thead>
        <tr>
          <th>Type</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
        {nestedTypes.map((type, idx) => (
          <tr key={idx}>
            <td>
              {type.type === 'link' ? (
                <Link to={type.url}>{type.text}</Link>
              ) : (
                type.name || type.type
              )}
            </td>
            <td>{type.description || type.content}</td>
          </tr>
        ))}
      </tbody>
    </table>
  );
}

export function ConfigDetail({ config }) {
  const styles = {
    descriptionSection: {
      marginBottom: '2rem',
    },
    documentationLink: {
      color: 'var(--ifm-color-primary)',
      textDecoration: 'none',
    },
    typeCell: {
      position: 'relative',
    },
    expandButton: {
      background: 'none',
      border: 'none',
      cursor: 'pointer',
      padding: '0 4px',
      color: 'var(--ifm-color-primary)',
      display: 'inline-flex',
      alignItems: 'center',
      marginLeft: '5px'
    },
    nestedTableContainer: {
      marginTop: '8px',
      marginBottom: '4px',
      backgroundColor: 'var(--ifm-table-stripe-background)',
      borderRadius: '4px',
      padding: '8px',
      border: '1px solid var(--ifm-table-border-color)'
    }
  };

  const { name, description, documentationUrl, parameters } = config;

  // Initialize expandedParams state
  const [expandedParams, setExpandedParams] = useState({});

  // Use useEffect to set initial expand state when component mounts
  useEffect(() => {
    const initialExpanded = {};
    parameters.forEach(param => {
      // Auto-expand if nested types count is less than 5
      if (param.nestedTypes && param.nestedTypes.length > 0 && param.nestedTypes.length < 5) {
        initialExpanded[param.name] = true;
      }
    });
    setExpandedParams(initialExpanded);
  }, [parameters]);

  const toggleExpand = (paramName) => {
    setExpandedParams(prev => ({
      ...prev,
      [paramName]: !prev[paramName]
    }));
  };

  return (
    <div>
      {description && (
        <div style={styles.descriptionSection}>
          <p>{description}</p>
          {documentationUrl && (
            <p>
              Details can be found in: <br />
              <Link
                to={documentationUrl}
                style={styles.documentationLink}
                target="_blank"
                rel="noopener noreferrer"
              >
                {documentationUrl}
              </Link>
            </p>
          )}
        </div>
      )}

      <h2>Parameters</h2>
      <table>
        <thead>
          <tr>
            <th>Name</th>
            <th>Type</th>
            <th>Required</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
          {parameters.map((param) => {
            const hasNestedTypes = param.nestedTypes && param.nestedTypes.length > 0;
            const isExpanded = expandedParams[param.name];

            return (
              <tr key={param.name}>
                <td><code>{param.name}</code></td>
                <td style={styles.typeCell}>
                  {param.type}
                  {hasNestedTypes && (
                    <button
                      style={styles.expandButton}
                      onClick={() => toggleExpand(param.name)}
                      aria-label={isExpanded ? "Collapse" : "Expand"}
                      title={isExpanded ? "Collapse" : "Expand"}
                    >
                      {isExpanded ? '' : ''}
                    </button>
                  )}
                  {hasNestedTypes && isExpanded && (
                    <div style={styles.nestedTableContainer}>
                      <NestedTypeTable nestedTypes={param.nestedTypes} />
                    </div>
                  )}
                </td>
                <td>{param.required ? '' : ''}</td>
                <td>
                  <div>{param.description}</div>
                  {param.validValues && (
                    <div>
                      Valid values:
                      {param.validValues.map((value, idx) => (
                        <React.Fragment key={idx}>
                          {idx > 0 && ', '}
                          <CodeValue value={value} />
                        </React.Fragment>
                      ))}
                    </div>
                  )}
                  {param.defaultValue && (
                    <div>
                      Defaults<CodeValue value={param.defaultValue} />
                    </div>
                  )}
                </td>
              </tr>
            );
          })}
        </tbody>
      </table>

      <style jsx>{`
        .nested-type-table {
          width: 100%;
          border-collapse: collapse;
          font-size: 0.9em;
        }
        
        .nested-type-table th,
        .nested-type-table td {
          padding: 6px 8px;
          border: 1px solid var(--ifm-table-border-color);
          text-align: left;
        }
        
        .nested-type-table th {
          background-color: var(--ifm-color-emphasis-200);
        }
      `}</style>
    </div>
  );
}