Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger for one of the warnings seems to be misconfigured #26

Closed
mazurp03 opened this issue Nov 24, 2023 · 6 comments
Closed

Trigger for one of the warnings seems to be misconfigured #26

mazurp03 opened this issue Nov 24, 2023 · 6 comments

Comments

@mazurp03
Copy link

mazurp03 commented Nov 24, 2023

Hi,
One of the warnings in the latest Shift Selector version seems to be too sensitive.
Here is the code fragment that I'm talking about:

useEffect(() => {
    if (shiftValues.length && shiftOptions?.options && !closedAlerts.includes(1)) {
      const shiftGroupUUIDs: { [key: string]: number } = shiftValues.reduce((res: any, { text }: { text: string }) => {
        const [, shiftGroupUUID] = text.split('|');
        return {
          ...res,
          [shiftGroupUUID]: res[shiftGroupUUID] ? ++res[shiftGroupUUID] : 1,
        };
      }, {});
      const shiftOptionsCount = Object.values(shiftGroupUUIDs).reduce((acc: number, d: number): number => acc + d, 0);

      if (shiftOptionsCount !== shiftOptions.options.length) {
        if (shiftOptions.options.length > 1) {
          return setAlertHandler({
            id: 1,
            type: 'brandWarning',
            text:
              'Warning! You are missing shifts because some shiftnames are not unique. Please make sure all shifts have unique names!',
          });
        } else {
          return setAlertHandler({
            id: 1,
            type: 'brandWarning',
            text: 'Warning! No shifts available. Please check your shift options variable.',
          });
        }
      }

      if (alerts.find(({ id }) => id === 1)) {
        resetAlert(1);
      }
    }
  }, [closedAlerts, alerts, shiftOptions, shiftValues, resetAlert, setAlertHandler]);

Let's focus on the first "if" condition. In case of more than one shift group configured in the database, this warning triggers all the time. For example, I have more than one instance of Grafana with completely different shiftGroupUUID's. For each shiftGroupUUID I have 3 shifts configured with the name e.g. "morning", "afternoon", "night". Of course, there should be something that will secure us from duplicating shift names in the same shiftGroupUUID (that's important), but for me there is a big discrepancy between the description of this warning and the condition that must be met.

There should be some function/effect that will check whether shift names are unique in the same shiftGroupUUID. For now, this "if" condition checks if there is more than one shiftGroupUUID (if I understand this code fragment correctly) and then if it meets the condition in which there is more than one - warning is triggered with a description, which for me doesn't indicate the checked condition.

@isaozler
Copy link
Owner

Hi @mazurp03, I tested it with the following data. Are you getting this issue with the latest 0.1.4 release? I'm asking because I am not getting any warnings about duplicate shifts in different shift groups.

image
{
    "static": {
        "shifts": [
            {
                "group": "Group 1 eg. Summer",
                "group_uuid": "uuid_1",
                "uuid": "shift_uuid_11",
                "label": "Morning Custom",
                "startTime": "06:01:00",
                "endTime": "14:00:00",
                "order": 1
            },
            {
                "group": "Group 1 eg. Summer",
                "group_uuid": "uuid_1",
                "uuid": "shift_uuid_12",
                "label": "Afternoon Custom",
                "startTime": "14:01:00",
                "endTime": "19:37:00",
                "order": 2
            },
            {
                "group": "Group 1 eg. Summer",
                "group_uuid": "uuid_1",
                "uuid": "shift_uuid_13",
                "label": "Night Custom",
                "startTime": "19:38:00",
                "endTime": "06:00:00",
                "order": 3
            },
            {
                "group": "Group 2 eg. Winter",
                "group_uuid": "uuid_2",
                "uuid": "shift_uuid_21",
                "label": "Morning Custom",
                "startTime": "06:01:00",
                "endTime": "14:00:00",
                "order": 1
            },
            {
                "group": "Group 2 eg. Winter",
                "group_uuid": "uuid_2",
                "uuid": "shift_uuid_22",
                "label": "Afternoon Custom",
                "startTime": "14:01:00",
                "endTime": "19:37:00",
                "order": 2
            },
            {
                "group": "Group 2 eg. Winter",
                "group_uuid": "uuid_2",
                "uuid": "shift_uuid_23",
                "label": "Night Custom",
                "startTime": "19:38:00",
                "endTime": "06:00:00",
                "order": 3
            }
        ]
    }
}

@fatbasstard
Copy link

Hi @isaozler ,

To jump on this, got the same warning. Using the Filter setup. When a line is selected the actual data returns a unique dataset. But without it there is indeed multiple values with the same name.

The validation appears to not take the filter into account correctly?

@isaozler
Copy link
Owner

isaozler commented Mar 5, 2024

Hi @isaozler ,

To jump on this, got the same warning. Using the Filter setup. When a line is selected the actual data returns a unique dataset. But without it there is indeed multiple values with the same name.

The validation appears to not take the filter into account correctly?

I see, will check this 👍

@fatbasstard
Copy link

@isaozler Found something already?

@isaozler
Copy link
Owner

@mazurp03 Could you check this branch to see if this fixes your issue?

https://github.com/isaozler/grafana-shift-selector/tree/fix/v10

@isaozler
Copy link
Owner

With the release of 0.1.6, you can retrieve all shifts without being filtered by Grafana.

Firstly, you should concatenate the shift labels with the shift group.
https://github.com/isaozler/grafana-shift-selector/assets/1378630/5c4204a3-ef6c-40d5-b5a3-73eba997d5b5

Secondly, the trim feature should be enabled in the data mapper props panel.
https://github.com/isaozler/grafana-shift-selector/assets/1378630/ebfeeeee-91a5-4245-97a5-107abc865aa3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants