mozilla-frontend-infra / react-lazylog

INACTIVE
https://mozilla-frontend-infra.github.io/react-lazylog/
Mozilla Public License 2.0
306 stars 101 forks source link

Clearing text #104

Closed georgejdli closed 2 months ago

georgejdli commented 3 years ago

I would like to be able to clear the current text from the display similar to you can clear the text from a terminal window by entering the "clear" command.

I played around with extended the LazyLog component in my project and added a "clearText" method that calls this.setState

class LazyLogClear extends LazyLog {
  clearText() {
   this.setState({
      count: 0,
      lines: null,
      isSearching: false,
      searchKeywords: '',
      resultLines: [],
      filteredLines: null,
      resultLineUniqueIndexes: [],
      isFilteringLinesWithMatches: false,
      scrollToIndex: 0,
    });
  }
}

To use this new method I would bind a ref (with useRef) to the LazyLogClear and call it elsewhere in my app. The only issue I've seen so far is that if I have a query in the SearchBar that query doesn't reset and when I clear the text from the display it ends up giving an inaccurate count of matched items (phantom resultLines from previously cleared text).

Are there any other state properties I'm missing or do I need to extend the SearchBar component as well so I can pass a prop to clear the search query?

Is there any interest in adding this feature directly to react-lazylog?

DanielLeefu commented 3 years ago

very good

melloware commented 1 year ago

@georgejdli I would be interested in a PR in my fork for this feature. I can help get the SearchBar cleared as well.

GitHub: https://github.com/melloware/react-logviewer

Demo Site: https://melloware.github.io/react-logviewer/