<commit_before>import { createSlice, PayloadAction, CaseReducer } from '@reduxjs/toolkit';

import Execution from './../models/Execution';
import { updateComment, updateStepPatch, updateAllStepPatch } from 'lib/rest/Rest';
import { StoreDispatch, RootStore } from 'rootReducer';
import Feature, { SimpleFeature } from 'models/Feature';
import fetchFeature from 'lib/services/FetchFeature';
import fetchExecutionHistory from 'lib/services/FetchExecutionHistory';
import { LoggedInUser, User } from 'models/User';
import { calculateManualStatus, calculateFeatureStatus } from 'lib/StatusCalculator';
import Status from 'models/Status';
import Tag from 'models/Tag';
import fetchSimpleFeaturesByTags from 'lib/services/FetchSimpleFeaturesByTags';
import fetchSimpleFeatures from 'lib/services/FetchSimpleFeatures';

interface SelectedFeature {
  selected: Feature | null;
  executionHistory: Execution[] | null;
}

interface FeatureIndexes {
  byTag: Tag[] | null;
  byId: SimpleFeature[] | null;
}

type FeatureState = FeatureIndexes & SelectedFeature;

interface CommentUpdateDetails {
  scenarioId: string;
  label: string;
  content: string;
  user: LoggedInUser;
}

interface StepStatusChange {
  stepId: number;
  status: Status;
  scenarioId: string;
  build: string;
  user: LoggedInUser;
}

interface ScenarioStatusChange {
  status: Status;
  scenarioId: string;
  build: string;
  user: LoggedInUser;
}

type SaveIndexesAction = PayloadAction<FeatureIndexes>;
type SaveFeatureAndHistoryAction = PayloadAction<SelectedFeature>;
type CommentUpdateAction = PayloadAction<CommentUpdateDetails>;
type LastUpdatedUpdateAction = PayloadAction<User>;
type StepStatusChangeAction = PayloadAction<StepStatusChange>;
type ScenarioStatusChangeAction = PayloadAction<ScenarioStatusChange>;

const featureIndexReducer: CaseReducer<FeatureState, SaveIndexesAction> = (state, action) => {
  return { ...state, ...action.payload };
};

const saveFeatureAndHistoryReducer: CaseReducer<FeatureState, SaveFeatureAndHistoryAction> = (state, action) => {
  return { ...state, ...action.payload };
};

const updateMetadata = (featureState: FeatureState, user: LoggedInUser, build?: string): void => {
  const { selected, executionHistory } = featureState;
  if (selected && executionHistory) {
    selected.lastEditedOn = new Date().getTime();
    selected.lastEditedBy = user.display;
    const history = build && executionHistory.find(ex => ex.build === build);
    if (history) {
      history.calculatedStatus = selected.calculatedStatus;<commit_msg>remove unused code<commit_after>import { createSlice, PayloadAction, CaseReducer } from '@reduxjs/toolkit';

import Execution from './../models/Execution';
import { updateComment, updateStepPatch, updateAllStepPatch } from 'lib/rest/Rest';
import { StoreDispatch, RootStore } from 'rootReducer';
import Feature, { SimpleFeature } from 'models/Feature';
import fetchFeature from 'lib/services/FetchFeature';
import fetchExecutionHistory from 'lib/services/FetchExecutionHistory';
import { LoggedInUser, User } from 'models/User';
import { calculateManualStatus, calculateFeatureStatus } from 'lib/StatusCalculator';
import Status from 'models/Status';
import Tag from 'models/Tag';
import fetchSimpleFeaturesByTags from 'lib/services/FetchSimpleFeaturesByTags';
import fetchSimpleFeatures from 'lib/services/FetchSimpleFeatures';

interface SelectedFeature {
  selected: Feature | null;
  executionHistory: Execution[] | null;
}

interface FeatureIndexes {
  byTag: Tag[] | null;
  byId: SimpleFeature[] | null;
}

type FeatureState = FeatureIndexes & SelectedFeature;

interface CommentUpdateDetails {
  scenarioId: string;
  label: string;
  content: string;
  user: LoggedInUser;
}

interface StepStatusChange {
  stepId: number;
  status: Status;
  scenarioId: string;
  build: string;
  user: LoggedInUser;
}

interface ScenarioStatusChange {
  status: Status;
  scenarioId: string;
  build: string;
  user: LoggedInUser;
}

type SaveIndexesAction = PayloadAction<FeatureIndexes>;
type SaveFeatureAndHistoryAction = PayloadAction<SelectedFeature>;
type CommentUpdateAction = PayloadAction<CommentUpdateDetails>;
type StepStatusChangeAction = PayloadAction<StepStatusChange>;
type ScenarioStatusChangeAction = PayloadAction<ScenarioStatusChange>;

const featureIndexReducer: CaseReducer<FeatureState, SaveIndexesAction> = (state, action) => {
  return { ...state, ...action.payload };
};

const saveFeatureAndHistoryReducer: CaseReducer<FeatureState, SaveFeatureAndHistoryAction> = (state, action) => {
  return { ...state, ...action.payload };
};

const updateMetadata = (featureState: FeatureState, user: LoggedInUser, build?: string): void => {
  const { selected, executionHistory } = featureState;
  if (selected && executionHistory) {
    selected.lastEditedOn = new Date().getTime();
    selected.lastEditedBy = user.display;
    const history = build && executionHistory.find(ex => ex.build === build);
    if (history) {
      history.calculatedStatus = selected.calculatedStatus;
{'fraction_non_alphanumeric': 0.10614192009540847, 'fraction_numerical': 0.0, 'mean_word_length': 6.01813110181311, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1867560', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1384, 'n_words': 356}