vogievetsky commented on a change in pull request #7954: Web-console: Add 
action column to segments view
URL: https://github.com/apache/incubator-druid/pull/7954#discussion_r296983089
 
 

 ##########
 File path: web-console/src/views/segments-view/segments-view.tsx
 ##########
 @@ -357,128 +378,191 @@ export class SegmentsView extends 
React.PureComponent<SegmentsViewProps, Segment
                 </a>
               );
             },
-            show: tableColumnSelectionHandler.showColumn('End'),
+            show: hiddenColumns.exists('End'),
           },
           {
             Header: 'Version',
             accessor: 'version',
             defaultSortDesc: true,
             width: 120,
-            show: tableColumnSelectionHandler.showColumn('Version'),
+            show: hiddenColumns.exists('Version'),
           },
           {
             Header: 'Partition',
             accessor: 'partition_num',
             width: 60,
             filterable: false,
-            show: tableColumnSelectionHandler.showColumn('Partition'),
+            show: hiddenColumns.exists('Partition'),
           },
           {
             Header: 'Size',
             accessor: 'size',
             filterable: false,
             defaultSortDesc: true,
             Cell: row => formatBytes(row.value),
-            show: tableColumnSelectionHandler.showColumn('Size'),
+            show: hiddenColumns.exists('Size'),
           },
           {
             Header: 'Num rows',
             accessor: 'num_rows',
             filterable: false,
             defaultSortDesc: true,
             Cell: row => formatNumber(row.value),
-            show: !noSqlMode && tableColumnSelectionHandler.showColumn('Num 
rows'),
+            show: !noSqlMode && hiddenColumns.exists('Num rows'),
           },
           {
             Header: 'Replicas',
             accessor: 'num_replicas',
             width: 60,
             filterable: false,
             defaultSortDesc: true,
-            show: !noSqlMode && 
tableColumnSelectionHandler.showColumn('Replicas'),
+            show: !noSqlMode && hiddenColumns.exists('Replicas'),
           },
           {
             Header: 'Is published',
             id: 'is_published',
             accessor: row => String(Boolean(row.is_published)),
             Filter: makeBooleanFilter(),
-            show: !noSqlMode && tableColumnSelectionHandler.showColumn('Is 
published'),
+            show: !noSqlMode && hiddenColumns.exists('Is published'),
           },
           {
             Header: 'Is realtime',
             id: 'is_realtime',
             accessor: row => String(Boolean(row.is_realtime)),
             Filter: makeBooleanFilter(),
-            show: !noSqlMode && tableColumnSelectionHandler.showColumn('Is 
realtime'),
+            show: !noSqlMode && hiddenColumns.exists('Is realtime'),
           },
           {
             Header: 'Is available',
             id: 'is_available',
             accessor: row => String(Boolean(row.is_available)),
             Filter: makeBooleanFilter(),
-            show: !noSqlMode && tableColumnSelectionHandler.showColumn('Is 
available'),
+            show: !noSqlMode && hiddenColumns.exists('Is available'),
           },
           {
             Header: 'Is overshadowed',
             id: 'is_overshadowed',
             accessor: row => String(Boolean(row.is_overshadowed)),
             Filter: makeBooleanFilter(),
-            show: !noSqlMode && tableColumnSelectionHandler.showColumn('Is 
overshadowed'),
+            show: !noSqlMode && hiddenColumns.exists('Is overshadowed'),
+          },
+          {
+            Header: ActionCell.COLUMN_LABEL,
+            id: ActionCell.COLUMN_ID,
+            accessor: 'segment_id',
+            width: ActionCell.COLUMN_WIDTH,
+            filterable: false,
+            Cell: row => {
+              if (row.aggregated) return '';
+              const id = row.value;
+              const datasource = row.row.datasource;
+              const dimensions = parseList(row.original.payload.dimensions);
+              const metrics = parseList(row.original.payload.metrics);
+              return (
+                <ActionCell
+                  onDetail={() => {
+                    this.setState({
+                      segmentTableActionDialogId: id,
+                      datasourceTableActionDialogId: datasource,
+                      actions: this.getSegmentActions(id, datasource),
+                    });
+                  }}
+                  actions={this.getSegmentActions(id, datasource)}
+                />
+              );
+            },
+            Aggregated: row => '',
+            show: hiddenColumns.exists(ActionCell.COLUMN_LABEL),
           },
         ]}
         defaultPageSize={50}
-        SubComponent={rowInfo => {
-          const { original } = rowInfo;
-          const { payload } = rowInfo.original;
-          const dimensions = parseList(payload.dimensions);
-          const metrics = parseList(payload.metrics);
-          return (
-            <div className="segment-detail">
-              <H5>Segment ID</H5>
-              <p>{original.segment_id}</p>
-              <H5>{`Dimensions (${dimensions.length})`}</H5>
-              <p>{dimensions.join(', ') || 'No dimension'}</p>
-              <H5>{`Metrics (${metrics.length})`}</H5>
-              <p>{metrics.join(', ') || 'No metrics'}</p>
-            </div>
-          );
-        }}
       />
     );
   }
 
+  renderTerminateSegmentAction() {
+    const { terminateSegmentId, terminatetDatasourceId } = this.state;
+
+    return (
+      <AsyncActionDialog
+        action={
+          terminateSegmentId
+            ? async () => {
+                const resp = await axios.delete(
+                  
`/druid/coordinator/v1/datasources/${terminatetDatasourceId}/segments/${terminateSegmentId}`,
+                  {},
+                );
+                return resp.data;
+              }
+            : null
+        }
+        confirmButtonText="Drop Segment"
+        successText="Segment drop request acknowledged, next time the 
coordinator runs segment will be dropped"
+        failText="Could not drop segment"
+        intent={Intent.DANGER}
+        onClose={success => {
+          this.setState({ terminateSegmentId: null });
+          if (success) {
+            this.segmentsJsonQueryManager.rerunLastQuery();
+            this.segmentsSqlQueryManager.rerunLastQuery();
+          }
+        }}
+      >
+        <p>{`Are you sure you want to drop segment 
'${terminateSegmentId}'?`}</p>
+        <p>This action is not reversible.</p>
+      </AsyncActionDialog>
+    );
+  }
+
   render() {
+    const {
+      segmentTableActionDialogId,
+      datasourceTableActionDialogId,
+      actions,
+      hiddenColumns,
+    } = this.state;
     const { goToQuery, noSqlMode } = this.props;
-    const { tableColumnSelectionHandler } = this;
 
     return (
-      <div className="segments-view app-view">
-        <ViewControlBar label="Segments">
-          <Button
-            icon={IconNames.REFRESH}
-            text="Refresh"
-            onClick={() =>
-              noSqlMode
-                ? this.segmentsJsonQueryManager.rerunLastQuery()
-                : this.segmentsSqlQueryManager.rerunLastQuery()
-            }
-          />
-          {!noSqlMode && (
+      <>
+        <div className="segments-view app-view">
+          <ViewControlBar label="Segments">
             <Button
-              icon={IconNames.APPLICATION}
-              text="Go to SQL"
-              hidden={noSqlMode}
-              onClick={() => 
goToQuery(this.segmentsSqlQueryManager.getLastQuery().query)}
+              icon={IconNames.REFRESH}
+              text="Refresh"
+              onClick={() =>
+                noSqlMode
+                  ? this.segmentsJsonQueryManager.rerunLastQuery()
+                  : this.segmentsSqlQueryManager.rerunLastQuery()
+              }
+            />
+            {!noSqlMode && (
+              <Button
+                icon={IconNames.APPLICATION}
+                text="Go to SQL"
+                hidden={noSqlMode}
+                onClick={() => 
goToQuery(this.segmentsSqlQueryManager.getLastQuery().query)}
+              />
+            )}
+            <TableColumnSelector
+              columns={noSqlMode ? tableColumnsNoSql : tableColumns}
+              onChange={column => this.setState({ hiddenColumns: 
hiddenColumns.toggle(column) })}
+              tableColumnsHidden={hiddenColumns.storedArray}
             />
-          )}
-          <TableColumnSelector
-            columns={noSqlMode ? tableColumnsNoSql : tableColumns}
-            onChange={column => 
tableColumnSelectionHandler.changeTableColumnSelector(column)}
-            tableColumnsHidden={tableColumnSelectionHandler.hiddenColumns}
+          </ViewControlBar>
+          {this.renderSegmentsTable()}
+        </div>
+        ;{this.renderTerminateSegmentAction()}
 
 Review comment:
   `;`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to